-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extra logging for subscription failures (#40)
- Loading branch information
Showing
14 changed files
with
162 additions
and
17 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
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
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
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
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
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,26 @@ | ||
import type { Logger } from '@message-queue-toolkit/core' | ||
|
||
export class FakeLogger implements Logger { | ||
public readonly loggedMessages: unknown[] = [] | ||
public readonly loggedWarnings: unknown[] = [] | ||
public readonly loggedErrors: unknown[] = [] | ||
|
||
debug(obj: unknown) { | ||
this.loggedMessages.push(obj) | ||
} | ||
error(obj: unknown) { | ||
this.loggedErrors.push(obj) | ||
} | ||
fatal(obj: unknown) { | ||
this.loggedErrors.push(obj) | ||
} | ||
info(obj: unknown) { | ||
this.loggedMessages.push(obj) | ||
} | ||
trace(obj: unknown) { | ||
this.loggedMessages.push(obj) | ||
} | ||
warn(obj: unknown) { | ||
this.loggedWarnings.push(obj) | ||
} | ||
} |
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,86 @@ | ||
import type { SNSClient } from '@aws-sdk/client-sns' | ||
import type { SQSClient } from '@aws-sdk/client-sqs' | ||
import { deleteQueue } from '@message-queue-toolkit/sqs' | ||
import type { AwilixContainer } from 'awilix' | ||
import { afterEach, describe, expect } from 'vitest' | ||
|
||
import { subscribeToTopic } from '../../lib/utils/snsSubscriber' | ||
import { deleteTopic } from '../../lib/utils/snsUtils' | ||
import { FakeLogger } from '../fakes/FakeLogger' | ||
|
||
import type { Dependencies } from './testContext' | ||
import { registerDependencies } from './testContext' | ||
|
||
const TOPIC_NAME = 'topic' | ||
const QUEUE_NAME = 'queue' | ||
|
||
describe('snsSubscriber', () => { | ||
let diContainer: AwilixContainer<Dependencies> | ||
let snsClient: SNSClient | ||
let sqsClient: SQSClient | ||
beforeEach(async () => { | ||
diContainer = await registerDependencies({}, false) | ||
snsClient = diContainer.cradle.snsClient | ||
sqsClient = diContainer.cradle.sqsClient | ||
}) | ||
|
||
afterEach(async () => { | ||
const { awilixManager } = diContainer.cradle | ||
await awilixManager.executeDispose() | ||
await diContainer.dispose() | ||
|
||
await deleteTopic(snsClient, TOPIC_NAME) | ||
await deleteQueue(sqsClient, QUEUE_NAME) | ||
}) | ||
|
||
describe('subscribeToTopic', () => { | ||
it('logs queue in subscription error', async () => { | ||
const logger = new FakeLogger() | ||
await subscribeToTopic( | ||
sqsClient, | ||
snsClient, | ||
{ | ||
QueueName: QUEUE_NAME, | ||
}, | ||
{ | ||
Name: TOPIC_NAME, | ||
}, | ||
{ | ||
Attributes: { | ||
FilterPolicy: `{"type":["remove"]}`, | ||
FilterPolicyScope: 'MessageAttributes', | ||
}, | ||
}, | ||
) | ||
|
||
await expect( | ||
subscribeToTopic( | ||
sqsClient, | ||
snsClient, | ||
{ | ||
QueueName: QUEUE_NAME, | ||
}, | ||
{ | ||
Name: TOPIC_NAME, | ||
}, | ||
{ | ||
Attributes: { | ||
FilterPolicy: `{"type":["add"]}`, | ||
FilterPolicyScope: 'MessageBody', | ||
}, | ||
}, | ||
{ | ||
logger, | ||
}, | ||
), | ||
).rejects.toThrow( | ||
/Invalid parameter: Attributes Reason: Subscription already exists with different attributes/, | ||
) | ||
|
||
expect(logger.loggedErrors).toHaveLength(1) | ||
expect(logger.loggedErrors[0]).toBe( | ||
'Error while creating subscription for queue "queue", topic "topic": Invalid parameter: Attributes Reason: Subscription already exists with different attributes', | ||
) | ||
}) | ||
}) | ||
}) |
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