Skip to content

Commit bdd346b

Browse files
authored
Adding dlq update tags tests (#223)
1 parent 4f4a2a8 commit bdd346b

File tree

2 files changed

+122
-16
lines changed

2 files changed

+122
-16
lines changed

packages/sns/test/consumers/SnsSqsPermissionConsumer.deadLetterQueue.spec.ts

Lines changed: 88 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { SNSClient } from '@aws-sdk/client-sns'
2-
import type { SQSClient } from '@aws-sdk/client-sqs'
2+
import { ListQueueTagsCommand, type SQSClient } from '@aws-sdk/client-sqs'
33
import { waitAndRetry } from '@lokalise/node-core'
44
import {
55
type SQSMessage,
@@ -54,75 +54,149 @@ describe('SnsSqsPermissionConsumer - dead letter queue', () => {
5454
})
5555

5656
describe('init', () => {
57+
const topicName = 'sometopic'
58+
const queueName = 'myQueue'
59+
const deadLetterQueueName = 'deadLetterQueue'
60+
61+
beforeEach(async () => {
62+
await deleteQueue(sqsClient, queueName)
63+
await deleteQueue(sqsClient, deadLetterQueueName)
64+
await deleteTopic(snsClient, topicName)
65+
})
66+
5767
it('creates a new dead letter queue', async () => {
5868
const newConsumer = new SnsSqsPermissionConsumer(diContainer.cradle, {
5969
creationConfig: {
60-
topic: { Name: 'sometopic' },
61-
queue: { QueueName: 'existingQueue' },
70+
topic: { Name: topicName },
71+
queue: { QueueName: queueName },
6272
updateAttributesIfExists: true,
6373
},
6474
deadLetterQueue: {
6575
redrivePolicy: { maxReceiveCount: 3 },
6676
creationConfig: {
67-
queue: { QueueName: 'deadLetterQueue' },
77+
queue: { QueueName: deadLetterQueueName },
6878
},
6979
},
7080
})
7181

7282
await newConsumer.init()
7383
expect(newConsumer.subscriptionProps.queueUrl).toBe(
74-
'http://sqs.eu-west-1.localstack:4566/000000000000/existingQueue',
84+
`http://sqs.eu-west-1.localstack:4566/000000000000/${queueName}`,
7585
)
7686
expect(newConsumer.subscriptionProps.deadLetterQueueUrl).toBe(
77-
'http://sqs.eu-west-1.localstack:4566/000000000000/deadLetterQueue',
87+
`http://sqs.eu-west-1.localstack:4566/000000000000/${deadLetterQueueName}`,
7888
)
7989

8090
const attributes = await getQueueAttributes(sqsClient, newConsumer.subscriptionProps.queueUrl)
8191

8292
expect(attributes.result?.attributes).toMatchObject({
8393
RedrivePolicy: JSON.stringify({
84-
deadLetterTargetArn: `arn:aws:sqs:eu-west-1:000000000000:deadLetterQueue`,
94+
deadLetterTargetArn: `arn:aws:sqs:eu-west-1:000000000000:${deadLetterQueueName}`,
8595
maxReceiveCount: 3,
8696
}),
8797
})
8898
})
8999

90100
it('using existing dead letter queue', async () => {
91101
await assertQueue(sqsClient, {
92-
QueueName: 'deadLetterQueue',
102+
QueueName: deadLetterQueueName,
93103
})
94104

95105
const newConsumer = new SnsSqsPermissionConsumer(diContainer.cradle, {
96106
creationConfig: {
97-
topic: { Name: 'sometopic' },
98-
queue: { QueueName: 'existingQueue' },
107+
topic: { Name: topicName },
108+
queue: { QueueName: queueName },
99109
updateAttributesIfExists: true,
100110
},
101111
deadLetterQueue: {
102112
redrivePolicy: { maxReceiveCount: 3 },
103113
locatorConfig: {
104-
queueUrl: 'http://sqs.eu-west-1.localstack:4566/000000000000/deadLetterQueue',
114+
queueUrl: `http://sqs.eu-west-1.localstack:4566/000000000000/${deadLetterQueueName}`,
105115
},
106116
},
107117
})
108118

109119
await newConsumer.init()
110120
expect(newConsumer.subscriptionProps.queueUrl).toBe(
111-
'http://sqs.eu-west-1.localstack:4566/000000000000/existingQueue',
121+
`http://sqs.eu-west-1.localstack:4566/000000000000/${queueName}`,
112122
)
113123
expect(newConsumer.subscriptionProps.deadLetterQueueUrl).toBe(
114-
'http://sqs.eu-west-1.localstack:4566/000000000000/deadLetterQueue',
124+
`http://sqs.eu-west-1.localstack:4566/000000000000/${deadLetterQueueName}`,
115125
)
116126

117127
const attributes = await getQueueAttributes(sqsClient, newConsumer.subscriptionProps.queueUrl)
118128

119129
expect(attributes.result?.attributes).toMatchObject({
120130
RedrivePolicy: JSON.stringify({
121-
deadLetterTargetArn: `arn:aws:sqs:eu-west-1:000000000000:deadLetterQueue`,
131+
deadLetterTargetArn: `arn:aws:sqs:eu-west-1:000000000000:${deadLetterQueueName}`,
122132
maxReceiveCount: 3,
123133
}),
124134
})
125135
})
136+
137+
it('should update attributes and tags', async () => {
138+
await assertQueue(sqsClient, {
139+
QueueName: deadLetterQueueName,
140+
Attributes: { KmsMasterKeyId: 'old' },
141+
tags: { tag: 'old' },
142+
})
143+
144+
const newConsumer = new SnsSqsPermissionConsumer(diContainer.cradle, {
145+
creationConfig: {
146+
topic: { Name: topicName },
147+
queue: { QueueName: queueName },
148+
updateAttributesIfExists: true,
149+
},
150+
deadLetterQueue: {
151+
redrivePolicy: { maxReceiveCount: 3 },
152+
creationConfig: {
153+
forceTagUpdate: true,
154+
updateAttributesIfExists: true,
155+
queue: {
156+
QueueName: deadLetterQueueName,
157+
Attributes: { KmsMasterKeyId: 'new' },
158+
tags: { tag: 'new' },
159+
},
160+
},
161+
},
162+
})
163+
164+
await newConsumer.init()
165+
expect(newConsumer.subscriptionProps.queueUrl).toBe(
166+
`http://sqs.eu-west-1.localstack:4566/000000000000/${queueName}`,
167+
)
168+
expect(newConsumer.subscriptionProps.deadLetterQueueUrl).toBe(
169+
`http://sqs.eu-west-1.localstack:4566/000000000000/${deadLetterQueueName}`,
170+
)
171+
172+
const mainQueueAttributes = await getQueueAttributes(
173+
sqsClient,
174+
newConsumer.subscriptionProps.queueUrl,
175+
)
176+
expect(mainQueueAttributes.result?.attributes).toMatchObject({
177+
RedrivePolicy: JSON.stringify({
178+
deadLetterTargetArn: `arn:aws:sqs:eu-west-1:000000000000:${deadLetterQueueName}`,
179+
maxReceiveCount: 3,
180+
}),
181+
})
182+
183+
const dlqAttributes = await getQueueAttributes(
184+
sqsClient,
185+
newConsumer.subscriptionProps.deadLetterQueueUrl!,
186+
)
187+
expect(dlqAttributes.result?.attributes).toMatchObject({
188+
KmsMasterKeyId: 'new',
189+
})
190+
191+
const tags = await sqsClient.send(
192+
new ListQueueTagsCommand({ QueueUrl: newConsumer.subscriptionProps.deadLetterQueueUrl }),
193+
)
194+
expect(tags.Tags).toMatchInlineSnapshot(`
195+
{
196+
"tag": "new",
197+
}
198+
`)
199+
})
126200
})
127201

128202
describe('messages are sent to DLQ', () => {

packages/sqs/test/consumers/SqsPermisssionConsumer.deadLetterQueue.spec.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SQSClient } from '@aws-sdk/client-sqs'
1+
import { ListQueueTagsCommand, type SQSClient } from '@aws-sdk/client-sqs'
22
import { SendMessageCommand } from '@aws-sdk/client-sqs'
33
import { waitAndRetry } from '@lokalise/node-core'
44
import type { AwilixContainer } from 'awilix'
@@ -118,6 +118,7 @@ describe('SqsPermissionConsumer - deadLetterQueue', () => {
118118
const result = await assertQueue(sqsClient, {
119119
QueueName: customDeadLetterQueueName,
120120
Attributes: { KmsMasterKeyId: 'my first value' },
121+
tags: { tag: 'old', hello: 'world' },
121122
})
122123
dlqUrl = result.queueUrl
123124
})
@@ -154,7 +155,7 @@ describe('SqsPermissionConsumer - deadLetterQueue', () => {
154155
expect(consumer.dlqUrl).toBe(dlqUrl)
155156
})
156157

157-
it('updates existing dlq when one with different attributes exist', async () => {
158+
it('updates existing dlq attributes', async () => {
158159
consumer = new SqsPermissionConsumer(diContainer.cradle, {
159160
creationConfig: { queue: { QueueName: customQueueName }, updateAttributesIfExists: true },
160161
deadLetterQueue: {
@@ -180,6 +181,37 @@ describe('SqsPermissionConsumer - deadLetterQueue', () => {
180181
expect(attributes.result?.attributes!.KmsMasterKeyId).toBe('new value')
181182
})
182183

184+
it('updates existing dlq tags', async () => {
185+
consumer = new SqsPermissionConsumer(diContainer.cradle, {
186+
creationConfig: { queue: { QueueName: customQueueName }, updateAttributesIfExists: true },
187+
deadLetterQueue: {
188+
redrivePolicy: { maxReceiveCount: 5 },
189+
creationConfig: {
190+
forceTagUpdate: true,
191+
queue: {
192+
QueueName: customDeadLetterQueueName,
193+
tags: { tag: 'new', good: 'bye' },
194+
},
195+
},
196+
},
197+
})
198+
199+
await consumer.init()
200+
expect(consumer.queueProps.url).toBe(
201+
`http://sqs.eu-west-1.localstack:4566/000000000000/${customQueueName}`,
202+
)
203+
expect(consumer.dlqUrl).toBe(dlqUrl)
204+
205+
const tags = await sqsClient.send(new ListQueueTagsCommand({ QueueUrl: consumer.dlqUrl }))
206+
expect(tags.Tags).toMatchInlineSnapshot(`
207+
{
208+
"good": "bye",
209+
"hello": "world",
210+
"tag": "new",
211+
}
212+
`)
213+
})
214+
183215
it('connect existing dlq to existing queue', async () => {
184216
const { queueUrl } = await assertQueue(sqsClient, { QueueName: customQueueName })
185217

0 commit comments

Comments
 (0)