-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws-codepipeline): Make the Stage insertion API in CodePipeline …
…more flexible. This commit allows clients of CodePipeline to create new Stages placed at an arbitrary index in the Pipeline, or before/after a given Stage (instead of only appending new Stages at the end).
- Loading branch information
Showing
4 changed files
with
287 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,169 @@ | ||
import { expect, haveResource } from '@aws-cdk/assert'; | ||
import cdk = require('@aws-cdk/cdk'); | ||
import { Test } from 'nodeunit'; | ||
import codepipeline = require('../lib'); | ||
|
||
// tslint:disable:object-literal-key-quotes | ||
|
||
export = { | ||
'Pipeline Stages': { | ||
'can be inserted at index 0'(test: Test) { | ||
const stack = new cdk.Stack(); | ||
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); | ||
|
||
new codepipeline.Stage(stack, 'SecondStage', { pipeline }); | ||
new codepipeline.Stage(stack, 'FirstStage', { | ||
pipeline, | ||
placement: { | ||
atIndex: 0, | ||
}, | ||
}); | ||
|
||
expect(stack, true).to(haveResource('AWS::CodePipeline::Pipeline', { | ||
"Stages": [ | ||
{ "Name": "FirstStage" }, | ||
{ "Name": "SecondStage" }, | ||
], | ||
})); | ||
|
||
test.done(); | ||
}, | ||
|
||
'can be inserted before another Stage'(test: Test) { | ||
const stack = new cdk.Stack(); | ||
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); | ||
|
||
const secondStage = new codepipeline.Stage(stack, 'SecondStage', { pipeline }); | ||
new codepipeline.Stage(stack, 'FirstStage', { | ||
pipeline, | ||
placement: { | ||
rightBefore: secondStage, | ||
}, | ||
}); | ||
|
||
expect(stack, true).to(haveResource('AWS::CodePipeline::Pipeline', { | ||
"Stages": [ | ||
{ "Name": "FirstStage" }, | ||
{ "Name": "SecondStage" }, | ||
], | ||
})); | ||
|
||
test.done(); | ||
}, | ||
|
||
'can be inserted after another Stage'(test: Test) { | ||
const stack = new cdk.Stack(); | ||
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); | ||
|
||
const firstStage = new codepipeline.Stage(stack, 'FirstStage', { pipeline }); | ||
new codepipeline.Stage(stack, 'ThirdStage', { pipeline }); | ||
new codepipeline.Stage(stack, 'SecondStage', { | ||
pipeline, | ||
placement: { | ||
justAfter: firstStage, | ||
}, | ||
}); | ||
|
||
expect(stack, true).to(haveResource('AWS::CodePipeline::Pipeline', { | ||
"Stages": [ | ||
{ "Name": "FirstStage" }, | ||
{ "Name": "SecondStage" }, | ||
{ "Name": "ThirdStage" }, | ||
], | ||
})); | ||
|
||
test.done(); | ||
}, | ||
|
||
'attempting to insert a Stage at a negative index results in an error'(test: Test) { | ||
const stack = new cdk.Stack(); | ||
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); | ||
|
||
test.throws(() => { | ||
new codepipeline.Stage(stack, 'Stage', { | ||
pipeline, | ||
placement: { | ||
atIndex: -1, | ||
}, | ||
}); | ||
}, /atIndex/); | ||
|
||
test.done(); | ||
}, | ||
|
||
'attempting to insert a Stage at an index larger than the current number of Stages results in an error'(test: Test) { | ||
const stack = new cdk.Stack(); | ||
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); | ||
|
||
test.throws(() => { | ||
new codepipeline.Stage(stack, 'Stage', { | ||
pipeline, | ||
placement: { | ||
atIndex: 1, | ||
}, | ||
}); | ||
}, /atIndex/); | ||
|
||
test.done(); | ||
}, | ||
|
||
"attempting to insert a Stage before a Stage that doesn't exist results in an error"(test: Test) { | ||
const stack = new cdk.Stack(); | ||
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); | ||
const stage = new codepipeline.Stage(stack, 'Stage', { pipeline }); | ||
|
||
const anotherPipeline = new codepipeline.Pipeline(stack, 'AnotherPipeline'); | ||
test.throws(() => { | ||
new codepipeline.Stage(stack, 'AnotherStage', { | ||
pipeline: anotherPipeline, | ||
placement: { | ||
rightBefore: stage, | ||
}, | ||
}); | ||
}, /before/i); | ||
|
||
test.done(); | ||
}, | ||
|
||
"attempting to insert a Stage after a Stage that doesn't exist results in an error"(test: Test) { | ||
const stack = new cdk.Stack(); | ||
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); | ||
const stage = new codepipeline.Stage(stack, 'Stage', { pipeline }); | ||
|
||
const anotherPipeline = new codepipeline.Pipeline(stack, 'AnotherPipeline'); | ||
test.throws(() => { | ||
new codepipeline.Stage(stack, 'AnotherStage', { | ||
pipeline: anotherPipeline, | ||
placement: { | ||
justAfter: stage, | ||
}, | ||
}); | ||
}, /after/i); | ||
|
||
test.done(); | ||
}, | ||
|
||
"providing more than one placement value results in an error"(test: Test) { | ||
const stack = new cdk.Stack(); | ||
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); | ||
const stage = new codepipeline.Stage(stack, 'FirstStage', { pipeline }); | ||
|
||
test.throws(() => { | ||
new codepipeline.Stage(stack, 'SecondStage', { | ||
pipeline, | ||
placement: { | ||
rightBefore: stage, | ||
justAfter: stage, | ||
}, | ||
}); | ||
// incredibly, an arrow function below causes nodeunit to crap out with: | ||
// "TypeError: Function has non-object prototype 'undefined' in instanceof check" | ||
// tslint:disable-next-line:only-arrow-functions | ||
}, function(e: any) { | ||
return /rightBefore/.test(e) && /justAfter/.test(e); | ||
}); | ||
|
||
test.done(); | ||
}, | ||
}, | ||
}; |