Skip to content

Commit

Permalink
Refactor: Add dry run messages back in
Browse files Browse the repository at this point in the history
  • Loading branch information
sjwiesman committed Mar 13, 2023
1 parent 3379a45 commit f8a8776
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/dataGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ export default async function dataGenerator({
record.recordSizePayload = payload;
}

if (global.dryRun) {
alert({
type: `success`,
name: `Dry run: Skipping record production...`,
msg: `\n Topic: ${topic} \n Record key: ${key} \n Payload: ${JSON.stringify(record)}`
});
}

await producer?.send(key, record, topic);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/kafka/producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class KafkaProducer {
});

if (global.debug) {
console.log(`Connecting to Kafka producer...`);
console.log(`Connecting to Kafka brokers...`);
}
await producer.connect();
return new KafkaProducer(producer, format);
Expand Down
3 changes: 0 additions & 3 deletions tests/datagen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@ describe('Schema Parsing Tests', () => {
const schema = './tests/schema.avsc';
const output = datagen(`-s ${schema} -n 2`);
expect(output).toContain('Parsing Avro schema...');
expect(output).toContain('Dry run: Skipping topic creation...');
expect(output).toContain('Dry run: Skipping record production...');
expect(output).toContain('Stopping the data generator');
});
test('should parse sql schema', () => {
const schema = './tests/products.sql';
const output = datagen(`-s ${schema} -n 2`);
expect(output).toContain('Parsing schema...');
expect(output).toContain('Dry run: Skipping topic creation...');
expect(output).toContain('Dry run: Skipping record production...');
expect(output).toContain('Stopping the data generator');
});
test('should parse json schema', () => {
const schema = './tests/schema.json';
const output = datagen(`-s ${schema} -n 2`);
expect(output).toContain('Parsing JSON schema...');
expect(output).toContain('Dry run: Skipping topic creation...');
expect(output).toContain('Dry run: Skipping record production...');
expect(output).toContain('Stopping the data generator');
});
Expand Down

0 comments on commit f8a8776

Please sign in to comment.