-
-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #666 from tulios/reproduce-665
Remove invalid topics from targetTopics on INVALID_TOPIC_EXCEPTION
- Loading branch information
Showing
2 changed files
with
64 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const { secureRandom, newLogger, createCluster, createTopic } = require('testHelpers') | ||
const createProducer = require('../index') | ||
|
||
describe('Producer > Producing to invalid topics', () => { | ||
let producer, topicName | ||
|
||
beforeEach(async () => { | ||
topicName = `test-topic-${secureRandom()}` | ||
|
||
producer = createProducer({ | ||
cluster: createCluster(), | ||
logger: newLogger(), | ||
}) | ||
await producer.connect() | ||
await createTopic({ topic: topicName }) | ||
}) | ||
|
||
afterEach(async () => { | ||
producer && (await producer.disconnect()) | ||
}) | ||
|
||
it('it rejects when producing to an invalid topic name, but is able to subsequently produce to a valid topic', async () => { | ||
producer = createProducer({ | ||
cluster: createCluster(), | ||
logger: newLogger(), | ||
}) | ||
await producer.connect() | ||
|
||
const message = { key: `key-${secureRandom()}`, value: `value-${secureRandom()}` } | ||
const invalidTopicName = `${topicName}-abc)(*&^%` | ||
await expect(producer.send({ topic: invalidTopicName, messages: [message] })).rejects.toThrow( | ||
'The request attempted to perform an operation on an invalid topic' | ||
) | ||
|
||
await producer.send({ topic: topicName, messages: [message] }) | ||
}) | ||
}) |