Skip to content

Commit

Permalink
test: add event source unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalenic committed Feb 9, 2024
1 parent f33526d commit 83c9225
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions test/workload/stateful/eventSourceConstruct.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import * as cdk from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
import { EventSource } from '../../../lib/workload/stateful/event_source/component';

let stack: cdk.Stack;

function assert_common(template: Template) {
template.resourceCountIs('AWS::SQS::Queue', 2);

template.hasResourceProperties('AWS::CloudWatch::Alarm', {
ComparisonOperator: 'GreaterThanThreshold',
EvaluationPeriods: 1,
Threshold: 0,
});

template.hasResourceProperties('AWS::Events::Rule', {
EventPattern: {
source: ['aws.s3'],
detail: {
bucket: {
name: ['bucket'],
},
},
},
});
}

beforeEach(() => {
stack = new cdk.Stack();
});

test('Test EventSource created props', () => {
new EventSource(stack, 'TestDatabaseConstruct', {
buckets: ['bucket'],
});
const template = Template.fromStack(stack);

assert_common(template);
});

test('Test EventSource created props with event types', () => {
new EventSource(stack, 'TestDatabaseConstruct', {
buckets: ['bucket'],
eventTypes: ['Object Created'],
});
const template = Template.fromStack(stack);

assert_common(template);
template.hasResourceProperties('AWS::Events::Rule', {
EventPattern: {
'detail-type': ['Object Created'],
},
});
});

test('Test EventSource created props with prefix', () => {
new EventSource(stack, 'TestDatabaseConstruct', {
buckets: ['bucket'],
prefix: 'prefix',
});
const template = Template.fromStack(stack);

assert_common(template);
template.hasResourceProperties('AWS::Events::Rule', {
EventPattern: {
detail: {
object: {
key: [
{
prefix: 'prefix',
},
],
},
},
},
});
});

0 comments on commit 83c9225

Please sign in to comment.