1
+ /* eslint-disable import/no-extraneous-dependencies */
2
+ import '@aws-cdk/assert-internal/jest' ;
3
+ import * as cdkp from '../../../lib' ;
4
+ import { PipelineQueries } from '../../../lib/helpers-internal/pipeline-queries' ;
5
+ import { AppWithOutput , TestApp } from '../../testhelpers/test-app' ;
6
+
7
+ let app : TestApp ;
8
+
9
+ beforeEach ( ( ) => {
10
+ app = new TestApp ( ) ;
11
+ } ) ;
12
+
13
+ afterEach ( ( ) => {
14
+ app . cleanup ( ) ;
15
+ } ) ;
16
+
17
+ describe ( 'pipeline-queries' , ( ) => {
18
+
19
+ describe ( 'stackOutputsReferenced' , ( ) => {
20
+ let blueprint : Blueprint ;
21
+ let stageDeployment : cdkp . StageDeployment ;
22
+ let step : cdkp . ShellStep ;
23
+ let queries : PipelineQueries ;
24
+ let stackDeployment : cdkp . StackDeployment ;
25
+ let outputName : string | undefined ;
26
+ beforeEach ( ( ) => {
27
+ blueprint = new Blueprint ( app , 'Bp' , {
28
+ synth : new cdkp . ShellStep ( 'Synth' , {
29
+ input : cdkp . CodePipelineSource . gitHub ( 'test/test' , 'main' ) ,
30
+ commands : [ 'build' ] ,
31
+ } ) ,
32
+ } ) ;
33
+ const stage = new AppWithOutput ( app , 'CrossAccount' ) ;
34
+ outputName = 'MyOutput' ;
35
+ stageDeployment = blueprint . addStage ( stage ) ;
36
+ stackDeployment = stageDeployment . stacks [ 0 ] ;
37
+ expect ( stackDeployment ) . not . toBeUndefined ( ) ;
38
+ step = new cdkp . ShellStep ( 'test' , {
39
+ input : cdkp . CodePipelineSource . gitHub ( 'test/test' , 'main' ) ,
40
+ commands : [ 'build' ] ,
41
+ envFromCfnOutputs : {
42
+ INPUT : stage . theOutput ,
43
+ } ,
44
+ } ) ;
45
+ queries = new PipelineQueries ( blueprint ) ;
46
+ } ) ;
47
+
48
+ const cases = [
49
+ {
50
+ description : 'output referenced in stage pre step' ,
51
+ additionalSetup : ( ) => stageDeployment . addPre ( step ) ,
52
+ expectedResultGetter : ( ) => [ outputName ] ,
53
+ } ,
54
+ {
55
+ description : 'output referenced in stage post step' ,
56
+ additionalSetup : ( ) => stageDeployment . addPost ( step ) ,
57
+ expectedResultGetter : ( ) => [ outputName ] ,
58
+ } ,
59
+ {
60
+ description : 'output referenced in stack pre step' ,
61
+ additionalSetup : ( ) => stackDeployment . addStackSteps ( [ step ] , [ ] , [ ] ) ,
62
+ expectedResultGetter : ( ) => [ outputName ] ,
63
+ } ,
64
+ {
65
+ description : 'output referenced in stack changeSet step' ,
66
+ additionalSetup : ( ) => stackDeployment . addStackSteps ( [ ] , [ step ] , [ ] ) ,
67
+ expectedResultGetter : ( ) => [ outputName ] ,
68
+ } ,
69
+ {
70
+ description : 'output referenced in stack post step' ,
71
+ additionalSetup : ( ) => stackDeployment . addStackSteps ( [ ] , [ ] , [ step ] ) ,
72
+ expectedResultGetter : ( ) => [ outputName ] ,
73
+ } ,
74
+ {
75
+ description : 'output not referenced' ,
76
+ additionalSetup : ( ) => { } ,
77
+ expectedResultGetter : ( ) => [ ] ,
78
+ } ,
79
+
80
+ ] ;
81
+
82
+ cases . forEach ( testCase => {
83
+ test ( testCase . description , ( ) => {
84
+ //WHEN
85
+ testCase . additionalSetup ( ) ;
86
+
87
+ //THEN
88
+ expect ( queries . stackOutputsReferenced ( stackDeployment ) ) . toEqual ( testCase . expectedResultGetter ( ) ) ;
89
+ } ) ;
90
+ } ) ;
91
+
92
+ } ) ;
93
+ } ) ;
94
+
95
+
96
+ class Blueprint extends cdkp . PipelineBase {
97
+ protected doBuildPipeline ( ) : void {
98
+ }
99
+ }
0 commit comments