-
Notifications
You must be signed in to change notification settings - Fork 20
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
Konstantin Zarudaev
committed
Jan 11, 2024
1 parent
f09627d
commit e08e4c3
Showing
2 changed files
with
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,89 @@ | ||
import * as cdk from 'aws-cdk-lib' | ||
import { Template } from 'aws-cdk-lib/assertions' | ||
import { Match, Template } from 'aws-cdk-lib/assertions' | ||
import { CodePipelineStack } from '../lib/pipeline-stack' | ||
|
||
const app = new cdk.App() | ||
const stack = new CodePipelineStack(app, 'CodePipeline') | ||
const template = Template.fromStack(stack) | ||
describe('Unit tests for the pipeline stack', () => { | ||
const app = new cdk.App() | ||
const stack = new CodePipelineStack(app, 'CodePipeline') | ||
const template = Template.fromStack(stack) | ||
|
||
// Execute tests for CodePipeline template | ||
test('Pipeline restarts on update', () => { | ||
// Assessment | ||
template.hasResourceProperties('AWS::CodePipeline::Pipeline', { | ||
RestartExecutionOnUpdate: true | ||
// Execute tests for CodePipeline template | ||
test('Pipeline restarts on update', () => { | ||
template.hasResourceProperties('AWS::CodePipeline::Pipeline', { | ||
RestartExecutionOnUpdate: true | ||
}) | ||
}) | ||
}) | ||
|
||
test('There are 8 CodeBuild objects in use', () => { | ||
// Assessment | ||
template.resourceCountIs('AWS::CodeBuild::Project', 8) | ||
}) | ||
test('Key rotation is enabled', () => { | ||
template.hasResourceProperties('AWS::KMS::Key', { | ||
EnableKeyRotation: true | ||
}) | ||
}) | ||
|
||
test('Pipeline source settings', () => { | ||
template.hasResourceProperties('AWS::CodePipeline::Pipeline', { | ||
Stages: Match.arrayWith([ | ||
{ | ||
Actions: [{ | ||
ActionTypeId: { | ||
Category: 'Source', | ||
Owner: 'AWS', | ||
Provider: 'CodeCommit', | ||
Version: '1' | ||
}, | ||
Configuration: { | ||
BranchName: 'main', | ||
PollForSourceChanges: false, | ||
RepositoryName: Match.anyValue() | ||
}, | ||
Name: Match.anyValue(), | ||
OutputArtifacts: Match.anyValue(), | ||
RoleArn: Match.anyValue(), | ||
RunOrder: 1 | ||
}], | ||
Name: 'Source' | ||
}] | ||
) | ||
}) | ||
}) | ||
|
||
test('Pipeline build settings', () => { | ||
template.hasResourceProperties('AWS::CodePipeline::Pipeline', { | ||
Stages: Match.arrayWith([ | ||
{ | ||
Actions: [{ | ||
ActionTypeId: { | ||
Category: 'Build', | ||
Owner: 'AWS', | ||
Provider: 'CodeBuild', | ||
Version: '1' | ||
}, | ||
Configuration: Match.anyValue(), | ||
InputArtifacts: Match.anyValue(), | ||
Name: 'Synth', | ||
OutputArtifacts: [{ Name: 'Synth_Output' }], | ||
RoleArn: Match.anyValue(), | ||
RunOrder: 1 | ||
}], | ||
Name: 'Build' | ||
}] | ||
) | ||
}) | ||
}) | ||
|
||
// Summary checks | ||
test('Expected number of the CodeBuild objects', () => { | ||
const expectedValue = 8 | ||
template.resourceCountIs('AWS::CodeBuild::Project', expectedValue) | ||
}) | ||
|
||
test('CodePipeline has repository name in output', () => { | ||
// Assessment | ||
template.hasOutput('RepositoryName', '') | ||
test('Expected number of the S3 buckets', () => { | ||
const expectedValue = 1 | ||
template.resourceCountIs('AWS::S3::Bucket', expectedValue) | ||
}) | ||
|
||
test('Expected number of IAM roles', () => { | ||
const expectedValue = 12 | ||
template.resourceCountIs('AWS::IAM::Role', expectedValue) | ||
}) | ||
}) |