-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 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
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', | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); |