Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scheduler-targets): SqsSendMessage Target #27774

Merged
merged 24 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
269b0bd
wip
go-to-k Oct 31, 2023
e397c2c
test: change unit tests
go-to-k Oct 31, 2023
41fbf8b
feat: add bindBaseTargetConfig
go-to-k Oct 31, 2023
48dca93
docs: props comments
go-to-k Oct 31, 2023
32452a6
test: change an unit test
go-to-k Oct 31, 2023
ec9a162
test: wip
go-to-k Oct 31, 2023
e1b18f3
test: add integ tests
go-to-k Oct 31, 2023
d1ab879
add validations and the unit tests
go-to-k Oct 31, 2023
38c443f
docs: WIP in README
go-to-k Oct 31, 2023
173f2ed
chore: change validations and unit tests
go-to-k Nov 1, 2023
13489af
docs: wip in README
go-to-k Nov 1, 2023
4fc9c97
docs: change README and jsdocs
go-to-k Nov 1, 2023
5b2ed77
docs: fix for rosetta in README
go-to-k Nov 1, 2023
97acac6
docs: add default for messageGroupId
go-to-k Nov 1, 2023
736e359
Merge branch 'main' into feat/scheduler-targets-sqs
go-to-k Nov 4, 2023
3bf56da
covered for the review
go-to-k Nov 4, 2023
c585d6c
add a new line in README
go-to-k Nov 4, 2023
276298a
Merge branch 'main' of https://github.com/go-to-k/aws-cdk into feat/s…
go-to-k Nov 12, 2023
3060470
improve unit tests by using fromQueueArn in the same stack
go-to-k Nov 12, 2023
bc9bddc
Merge branch 'main' into feat/scheduler-targets-sqs
vinayak-kukreja Nov 20, 2023
84e77f6
Merge branch 'main' into feat/scheduler-targets-sqs
sumupitchayan Nov 20, 2023
c5bb455
Merge branch 'main' into feat/scheduler-targets-sqs
sumupitchayan Nov 21, 2023
6ad3e0c
Merge branch 'main' into feat/scheduler-targets-sqs
mergify[bot] Nov 21, 2023
84951af
Merge branch 'main' into feat/scheduler-targets-sqs
mergify[bot] Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: change validations and unit tests
  • Loading branch information
go-to-k committed Nov 1, 2023
commit 173f2ed1592a2857ceb0754eb74be61af5141d71
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ export class SqsSendMessage extends ScheduleTargetBase implements IScheduleTarge
throw new Error(`messageGroupId length must be between 1 and 128, got ${props.messageGroupId.length}`);
}
if (!queue.fifo) {
throw new Error('queue must be FIFO queue if messageGroupId is specified');
throw new Error('target must be a FIFO queue if messageGroupId is specified');
}
if (!(queue.node.defaultChild as sqs.CfnQueue).contentBasedDeduplication) {
throw new Error('contentBasedDeduplication must be true if messageGroupId is specified');
throw new Error('contentBasedDeduplication must be true if the target is a FIFO queue');
}
} else if (queue.fifo) {
throw new Error('messageGroupId must be specified if the target is a FIFO queue');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ describe('schedule target', () => {
beforeEach(() => {
app = new App();
stack = new Stack(app, 'Stack', { env: { region: 'us-east-1', account: '123456789012' } });
queue = new sqs.Queue(stack, 'MyQueue', {
fifo: true,
contentBasedDeduplication: true,
});
queue = new sqs.Queue(stack, 'MyQueue');
});

test('creates IAM role and IAM policy for sqs target in the same account', () => {
Expand Down Expand Up @@ -477,7 +474,11 @@ describe('schedule target', () => {
});

test('add message group id for target config', () => {
const queueTarget = new SqsSendMessage(queue, {
const fifoQueue = new sqs.Queue(stack, 'FifoQueue', {
fifo: true,
contentBasedDeduplication: true,
});
const queueTarget = new SqsSendMessage(fifoQueue, {
messageGroupId: 'messageGroupId',
});

Expand All @@ -490,7 +491,7 @@ describe('schedule target', () => {
Properties: {
Target: {
Arn: {
'Fn::GetAtt': ['MyQueueE6CA6235', 'Arn'],
'Fn::GetAtt': ['FifoQueueE5FF7273', 'Arn'],
},
RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] },
RetryPolicy: {},
Expand All @@ -503,15 +504,23 @@ describe('schedule target', () => {
});

test('throws when messageGroupId length is less than 1', () => {
const fifoQueue = new sqs.Queue(stack, 'FifoQueue', {
fifo: true,
contentBasedDeduplication: true,
});
expect(() =>
new SqsSendMessage(queue, {
new SqsSendMessage(fifoQueue, {
messageGroupId: '',
})).toThrow(/messageGroupId length must be between 1 and 128, got 0/);
});

test('throws when messageGroupId length is greater than 128', () => {
const fifoQueue = new sqs.Queue(stack, 'FifoQueue', {
fifo: true,
contentBasedDeduplication: true,
});
expect(() =>
new SqsSendMessage(queue, {
new SqsSendMessage(fifoQueue, {
messageGroupId: 'a'.repeat(129),
})).toThrow(/messageGroupId length must be between 1 and 128, got 129/);
});
Expand All @@ -523,17 +532,26 @@ describe('schedule target', () => {
expect(() =>
new SqsSendMessage(wrongQueue, {
messageGroupId: 'id',
})).toThrow(/queue must be FIFO queue if messageGroupId is specified/);
})).toThrow(/target must be a FIFO queue if messageGroupId is specified/);
});

test('throws when contentBasedDeduplication is not true if messageGroupId is specified', () => {
test('throws when contentBasedDeduplication is not true if queue is FIFO queue', () => {
const wrongQueue = new sqs.Queue(stack, 'WrongQueue', {
fifo: true,
contentBasedDeduplication: false,
});
expect(() =>
new SqsSendMessage(wrongQueue, {
messageGroupId: 'id',
})).toThrow(/contentBasedDeduplication must be true if messageGroupId is specified/);
})).toThrow(/contentBasedDeduplication must be true if the target is a FIFO queue/);
});

test('throws when queue is FIFO queue if messageGroupId is not specified', () => {
const wrongQueue = new sqs.Queue(stack, 'WrongQueue', {
fifo: true,
contentBasedDeduplication: true,
});
expect(() =>
new SqsSendMessage(wrongQueue, {})).toThrow(/messageGroupId must be specified if the target is a FIFO queue/);
});
});
Loading