/
pipeline-queries.test.ts
98 lines (86 loc) · 2.88 KB
/
pipeline-queries.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* eslint-disable import/no-extraneous-dependencies */
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 {
}
}