Skip to content

Commit

Permalink
Update pipeline and test examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Zarudaev committed Jan 11, 2024
1 parent f09627d commit e08e4c3
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 17 deletions.
2 changes: 2 additions & 0 deletions lib/pipeline-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class CodePipelineStack extends Stack {
})

const pipeline = new CodePipeline(this, 'Pipeline', {
crossAccountKeys: true,
enableKeyRotation: true,
synth: new ShellStep('Synth', {
input: CodePipelineSource.codeCommit(repo, 'main'),
installCommands: [
Expand Down
98 changes: 81 additions & 17 deletions test/pipeline-stack.test.ts
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)
})
})

0 comments on commit e08e4c3

Please sign in to comment.