-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
280 additions
and
8 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,153 @@ | ||
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 pipeline = pipelineForTesting(); | ||
|
||
const secondStage = new codepipeline.Stage(pipeline, 'SecondStage', { pipeline }); | ||
const firstStage = new codepipeline.Stage(pipeline, 'FirstStage', { | ||
pipeline, | ||
placed: { | ||
atIndex: 0, | ||
} | ||
}); | ||
|
||
test.equal(pipeline.stages[0].name, firstStage.name); | ||
test.equal(pipeline.stages[1].name, secondStage.name); | ||
|
||
test.done(); | ||
}, | ||
|
||
'can be inserted before another Stage'(test: Test) { | ||
const pipeline = pipelineForTesting(); | ||
|
||
const secondStage = new codepipeline.Stage(pipeline, 'SecondStage', { pipeline }); | ||
const firstStage = new codepipeline.Stage(pipeline, 'FirstStage', { | ||
pipeline, | ||
placed: { | ||
rightBefore: secondStage, | ||
} | ||
}); | ||
|
||
test.equal(pipeline.stages[0].name, firstStage.name); | ||
test.equal(pipeline.stages[1].name, secondStage.name); | ||
|
||
test.done(); | ||
}, | ||
|
||
'can be inserted after another Stage'(test: Test) { | ||
const pipeline = pipelineForTesting(); | ||
|
||
const firstStage = new codepipeline.Stage(pipeline, 'FirstStage', { pipeline }); | ||
const thirdStage = new codepipeline.Stage(pipeline, 'ThirdStage', { pipeline }); | ||
const secondStage = new codepipeline.Stage(pipeline, 'SecondStage', { | ||
pipeline, | ||
placed: { | ||
justAfter: firstStage, | ||
} | ||
}); | ||
|
||
test.equal(pipeline.stages[0].name, firstStage.name); | ||
test.equal(pipeline.stages[1].name, secondStage.name); | ||
test.equal(pipeline.stages[2].name, thirdStage.name); | ||
|
||
test.done(); | ||
}, | ||
|
||
'attempting to insert a Stage at a negative index results in an error'(test: Test) { | ||
const pipeline = pipelineForTesting(); | ||
|
||
test.throws(() => { | ||
new codepipeline.Stage(pipeline, 'Stage', { | ||
pipeline, | ||
placed: { | ||
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 pipeline = pipelineForTesting(); | ||
|
||
test.throws(() => { | ||
new codepipeline.Stage(pipeline, 'Stage', { | ||
pipeline, | ||
placed: { | ||
atIndex: 1, | ||
} | ||
}); | ||
}, /atIndex/); | ||
|
||
test.done(); | ||
}, | ||
|
||
"attempting to insert a Stage before a Stage that doesn't exist results in an error"(test: Test) { | ||
const pipeline = pipelineForTesting(); | ||
const stage = new codepipeline.Stage(pipeline, 'Stage', { pipeline }); | ||
|
||
const anotherPipeline = pipelineForTesting(); | ||
test.throws(() => { | ||
new codepipeline.Stage(anotherPipeline, 'Stage', { | ||
pipeline: anotherPipeline, | ||
placed: { | ||
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 pipeline = pipelineForTesting(); | ||
const stage = new codepipeline.Stage(pipeline, 'Stage', { pipeline }); | ||
|
||
const anotherPipeline = pipelineForTesting(); | ||
test.throws(() => { | ||
new codepipeline.Stage(anotherPipeline, 'Stage', { | ||
pipeline: anotherPipeline, | ||
placed: { | ||
justAfter: stage, | ||
} | ||
}); | ||
}, /after/i); | ||
|
||
test.done(); | ||
}, | ||
|
||
"providing more than one placement value results in an error"(test: Test) { | ||
const pipeline = pipelineForTesting(); | ||
const stage = new codepipeline.Stage(pipeline, 'FirstStage', { pipeline }); | ||
|
||
test.throws(() => { | ||
new codepipeline.Stage(pipeline, 'SecondStage', { | ||
pipeline, | ||
placed: { | ||
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(); | ||
}, | ||
}, | ||
}; | ||
|
||
function pipelineForTesting(): codepipeline.Pipeline { | ||
const stack = new cdk.Stack(); | ||
return new codepipeline.Pipeline(stack, 'Pipeline'); | ||
} |