Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pipelines): stack outputs used in stackSteps not recognized (#17311)
fixes #17272 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
2 changed files
with
102 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
99 changes: 99 additions & 0 deletions
99
packages/@aws-cdk/pipelines/test/blueprint/helpers-internal/pipeline-queries.test.ts
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,99 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import '@aws-cdk/assert-internal/jest'; | ||
import * as cdkp from '../../../lib'; | ||
import { PipelineQueries } from '../../../lib/helpers-internal/pipeline-queries'; | ||
import { AppWithOutput, TestApp } from '../../testhelpers/test-app'; | ||
|
||
let app: TestApp; | ||
|
||
beforeEach(() => { | ||
app = new TestApp(); | ||
}); | ||
|
||
afterEach(() => { | ||
app.cleanup(); | ||
}); | ||
|
||
describe('pipeline-queries', () => { | ||
|
||
describe('stackOutputsReferenced', () => { | ||
let blueprint: Blueprint; | ||
let stageDeployment: cdkp.StageDeployment; | ||
let step: cdkp.ShellStep; | ||
let queries: PipelineQueries; | ||
let stackDeployment: cdkp.StackDeployment; | ||
let outputName: string | undefined; | ||
beforeEach(() => { | ||
blueprint = new Blueprint(app, 'Bp', { | ||
synth: new cdkp.ShellStep('Synth', { | ||
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'), | ||
commands: ['build'], | ||
}), | ||
}); | ||
const stage = new AppWithOutput(app, 'CrossAccount'); | ||
outputName = 'MyOutput'; | ||
stageDeployment = blueprint.addStage(stage); | ||
stackDeployment = stageDeployment.stacks[0]; | ||
expect(stackDeployment).not.toBeUndefined(); | ||
step = new cdkp.ShellStep('test', { | ||
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'), | ||
commands: ['build'], | ||
envFromCfnOutputs: { | ||
INPUT: stage.theOutput, | ||
}, | ||
}); | ||
queries = new PipelineQueries(blueprint); | ||
}); | ||
|
||
const cases = [ | ||
{ | ||
description: 'output referenced in stage pre step', | ||
additionalSetup: () => stageDeployment.addPre(step), | ||
expectedResultGetter: () => [outputName], | ||
}, | ||
{ | ||
description: 'output referenced in stage post step', | ||
additionalSetup: () => stageDeployment.addPost(step), | ||
expectedResultGetter: () => [outputName], | ||
}, | ||
{ | ||
description: 'output referenced in stack pre step', | ||
additionalSetup: () => stackDeployment.addStackSteps([step], [], []), | ||
expectedResultGetter: () => [outputName], | ||
}, | ||
{ | ||
description: 'output referenced in stack changeSet step', | ||
additionalSetup: () => stackDeployment.addStackSteps([], [step], []), | ||
expectedResultGetter: () => [outputName], | ||
}, | ||
{ | ||
description: 'output referenced in stack post step', | ||
additionalSetup: () => stackDeployment.addStackSteps([], [], [step]), | ||
expectedResultGetter: () => [outputName], | ||
}, | ||
{ | ||
description: 'output not referenced', | ||
additionalSetup: () => { }, | ||
expectedResultGetter: () => [], | ||
}, | ||
|
||
]; | ||
|
||
cases.forEach(testCase => { | ||
test(testCase.description, () => { | ||
//WHEN | ||
testCase.additionalSetup(); | ||
|
||
//THEN | ||
expect(queries.stackOutputsReferenced(stackDeployment)).toEqual(testCase.expectedResultGetter()); | ||
}); | ||
}); | ||
|
||
}); | ||
}); | ||
|
||
|
||
class Blueprint extends cdkp.PipelineBase { | ||
protected doBuildPipeline(): void { | ||
} | ||
} |