Skip to content

Commit

Permalink
chore: add support for filtering keys
Browse files Browse the repository at this point in the history
  • Loading branch information
utsabc committed Mar 7, 2024
1 parent 54a6cad commit 80d4623
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions test/integrations/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const overrideDestination = (destination: Destination, overrideConfigValu
});
};

export const produceTestData = (testData: TestCaseData[]) => {
export const produceTestData = (testData: TestCaseData[], filterKeys = []) => {
const result: any = [];
testData.forEach((tcData) => {
let events;
Expand All @@ -120,7 +120,12 @@ export const produceTestData = (testData: TestCaseData[]) => {
}

events.forEach((event) => {
result.push(event.message);
const { message } = event;
// remove unwanted keys
filterKeys.forEach((key) => {
delete message[key];
});
result.push(message);
});
});

Expand Down
8 changes: 7 additions & 1 deletion test/scripts/testDataGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ command
.option('-id, --id <string>', 'Enter unique "Id" of the test case you want to run')
.option('-dp, --dataPlane <string>', 'Enter Data Plane URL')
.option('-wk, --writeKey <string>', 'Enter Write Key')
.option(
'-fk, --filterKeys <string>',
'Enter Keys to filter from the test data(originalTimestamp, timestamp, messageId etc)',
)
.parse();

const opts = command.opts();
Expand All @@ -26,6 +30,8 @@ if (opts.destination === undefined) {
throw new Error('Destination is not provided');
}

const filterKeys = opts.filterKeys ? opts.filterKeys.split(',') : [];

const rootDir = __dirname;
const resolvedpath = path.resolve(rootDir, '../integrations');
const destinationTestDataPaths = getTestDataFilePaths(resolvedpath, opts);
Expand All @@ -44,7 +50,7 @@ destinationTestDataPaths.forEach((testDataPath) => {
});
}
console.log('Writing test data to ../../temp/test_data.json');
produceTestData(testData);
produceTestData(testData, filterKeys);

if (opts.dataPlane && opts.writeKey) {
// read file ../../temp/test_data.json
Expand Down

0 comments on commit 80d4623

Please sign in to comment.