1
1
import cxapi = require( '@aws-cdk/cx-api' ) ;
2
- import { Test } from 'nodeunit' ;
2
+ import { Test , testCase } from 'nodeunit' ;
3
3
import { SDK } from '../../lib' ;
4
4
import { AppStacks , DefaultSelection } from '../../lib/api/cxapp/stacks' ;
5
5
import { Configuration } from '../../lib/settings' ;
6
6
import { testAssembly } from '../util' ;
7
7
8
- const FIXED_RESULT = testAssembly ( {
9
- stackName : 'withouterrors' ,
10
- template : { resource : 'noerrorresource' } ,
11
- } ,
12
- {
13
- stackName : 'witherrors' ,
14
- template : { resource : 'errorresource' } ,
15
- metadata : {
16
- '/resource' : [
17
- {
18
- type : cxapi . ERROR_METADATA_KEY ,
19
- data : 'this is an error'
20
- }
21
- ]
22
- } ,
23
- } ) ;
24
-
25
- export = {
8
+ export = testCase ( {
26
9
async 'do not throw when selecting stack without errors' ( test : Test ) {
27
10
// GIVEN
28
11
const stacks = testStacks ( ) ;
@@ -95,14 +78,75 @@ export = {
95
78
// THEN
96
79
test . ok ( thrown && thrown . includes ( 'Since this app includes more than a single stack, specify which stacks to use (wildcards are supported)' ) ) ;
97
80
test . done ( ) ;
98
- }
81
+ } ,
82
+
83
+ 'AWS::CDK::Metadata' : {
84
+ async 'is generated for relocatable stacks' ( test : Test ) {
85
+ const stacks = testStacks ( { env : `aws://${ cxapi . UNKNOWN_ACCOUNT } /${ cxapi . UNKNOWN_REGION } ` , versionReporting : true } ) ;
86
+
87
+ const result = await stacks . synthesizeStack ( 'withouterrors' ) ;
88
+ const metadata = result . template . Resources && result . template . Resources . CDKMetadata ;
89
+ test . deepEqual ( metadata , {
90
+ Type : 'AWS::CDK::Metadata' ,
91
+ Properties : {
92
+ Modules : `${ require ( '../../package.json' ) . name } =${ require ( '../../package.json' ) . version } `
93
+ }
94
+ } ) ;
95
+
96
+ test . done ( ) ;
97
+ } ,
98
+
99
+ async 'is generated for stacks in supported regions' ( test : Test ) {
100
+ const stacks = testStacks ( { env : 'aws://012345678912/us-east-1' , versionReporting : true } ) ;
101
+
102
+ const result = await stacks . synthesizeStack ( 'withouterrors' ) ;
103
+ const metadata = result . template . Resources && result . template . Resources . CDKMetadata ;
104
+ test . deepEqual ( metadata , {
105
+ Type : 'AWS::CDK::Metadata' ,
106
+ Properties : {
107
+ Modules : `${ require ( '../../package.json' ) . name } =${ require ( '../../package.json' ) . version } `
108
+ }
109
+ } ) ;
110
+
111
+ test . done ( ) ;
112
+ } ,
113
+
114
+ async 'is not generated for stacks in unsupported regions' ( test : Test ) {
115
+ const stacks = testStacks ( { env : 'aws://012345678912/bermuda-triangle-1337' , versionReporting : true } ) ;
116
+
117
+ const result = await stacks . synthesizeStack ( 'withouterrors' ) ;
118
+ const metadata = result . template . Resources && result . template . Resources . CDKMetadata ;
119
+ test . equal ( metadata , undefined ) ;
120
+
121
+ test . done ( ) ;
122
+ }
123
+ } ,
124
+ } ) ;
99
125
100
- } ;
126
+ function testStacks ( { env, versionReporting = true } : { env ?: string , versionReporting ?: boolean } = { } ) {
127
+ const configuration = new Configuration ( ) ;
128
+ configuration . settings . set ( [ 'versionReporting' ] , versionReporting ) ;
101
129
102
- function testStacks ( ) {
103
130
return new AppStacks ( {
104
- configuration : new Configuration ( ) ,
131
+ configuration,
105
132
aws : new SDK ( ) ,
106
- synthesizer : async ( ) => FIXED_RESULT ,
133
+ synthesizer : async ( ) => testAssembly ( {
134
+ stackName : 'withouterrors' ,
135
+ env,
136
+ template : { resource : 'noerrorresource' } ,
137
+ } ,
138
+ {
139
+ stackName : 'witherrors' ,
140
+ env,
141
+ template : { resource : 'errorresource' } ,
142
+ metadata : {
143
+ '/resource' : [
144
+ {
145
+ type : cxapi . ERROR_METADATA_KEY ,
146
+ data : 'this is an error'
147
+ }
148
+ ]
149
+ } ,
150
+ } ) ,
107
151
} ) ;
108
- }
152
+ }
0 commit comments