@@ -82,6 +82,31 @@ passingExample('sugar for matching stack to a template', () => {
82
82
}
83
83
} ) ;
84
84
} ) ;
85
+ passingExample ( 'expect <synthStack> to match (no replaces) <template> with parameters' , ( ) => {
86
+ const parameterType = 'Test::Parameter' ;
87
+ const synthStack = synthesizedStack ( stack => {
88
+ new TestParameter ( stack , 'TestParameter' , { type : parameterType } ) ;
89
+ } ) ;
90
+ const expected = { } ;
91
+ expect ( synthStack ) . to ( matchTemplate ( expected , MatchStyle . NO_REPLACES ) ) ;
92
+ } ) ;
93
+ passingExample ( 'expect <synthStack> to be a superset of <template> with parameters' , ( ) => {
94
+ const parameterType = 'Test::Parameter' ;
95
+ const synthStack = synthesizedStack ( stack => {
96
+ // Added
97
+ new TestResource ( stack , 'NewResource' , { type : 'AWS::S3::Bucket' } ) ;
98
+ // Expected
99
+ new TestParameter ( stack , 'TestParameterA' , { type : parameterType } ) ;
100
+ new TestParameter ( stack , 'TestParameterB' , { type : parameterType , default : { Foo : 'Bar' } } ) ;
101
+ } ) ;
102
+ const expected = {
103
+ Parameters : {
104
+ TestParameterA : { Type : 'Test::Parameter' } ,
105
+ TestParameterB : { Type : 'Test::Parameter' , Default : { Foo : 'Bar' } }
106
+ }
107
+ } ;
108
+ expect ( synthStack ) . to ( matchTemplate ( expected , MatchStyle . SUPERSET ) ) ;
109
+ } ) ;
85
110
86
111
failingExample ( 'expect <synthStack> at <some path> *not* to have <some type>' , ( ) => {
87
112
const resourceType = 'Test::Resource' ;
@@ -146,6 +171,36 @@ failingExample('expect <synthStack> to be a superset of <template>', () => {
146
171
} ;
147
172
expect ( synthStack ) . to ( matchTemplate ( expected , MatchStyle . SUPERSET ) ) ;
148
173
} ) ;
174
+ failingExample ( 'expect <synthStack> to match (no replaces) <template> with parameters' , ( ) => {
175
+ const parameterType = 'Test::Parameter' ;
176
+ const synthStack = synthesizedStack ( stack => {
177
+ new TestParameter ( stack , 'TestParameter' , { type : parameterType } ) ;
178
+ } ) ;
179
+ const expected = {
180
+ Parameters : {
181
+ TestParameter : { Type : 'AWS::S3::Bucket' }
182
+ }
183
+ } ;
184
+ expect ( synthStack ) . to ( matchTemplate ( expected , MatchStyle . NO_REPLACES ) ) ;
185
+ } ) ;
186
+ failingExample ( 'expect <synthStack> to be a superset of <template> with parameters' , ( ) => {
187
+ const parameterType = 'Test::Parameter' ;
188
+ const synthStack = synthesizedStack ( stack => {
189
+ // Added
190
+ new TestParameter ( stack , 'NewParameter' , { type : 'AWS::S3::Bucket' } ) ;
191
+ // Expected
192
+ new TestParameter ( stack , 'TestParameterA' , { type : parameterType } ) ;
193
+ // Expected, but has different properties - will break
194
+ new TestParameter ( stack , 'TestParameterB' , { type : parameterType , default : { Foo : 'Bar' } } ) ;
195
+ } ) ;
196
+ const expected = {
197
+ Parameters : {
198
+ TestParameterA : { Type : 'Test::Parameter' } ,
199
+ TestParameterB : { Type : 'Test::Parameter' , Default : { Foo : 'Baz' } }
200
+ }
201
+ } ;
202
+ expect ( synthStack ) . to ( matchTemplate ( expected , MatchStyle . SUPERSET ) ) ;
203
+ } ) ;
149
204
150
205
// countResources
151
206
@@ -222,3 +277,13 @@ class TestResource extends cdk.CfnResource {
222
277
super ( scope , id , props ) ;
223
278
}
224
279
}
280
+
281
+ interface TestParameterProps extends cdk . CfnParameterProps {
282
+ type : string ;
283
+ }
284
+
285
+ class TestParameter extends cdk . CfnParameter {
286
+ constructor ( scope : cdk . Construct , id : string , props : TestParameterProps ) {
287
+ super ( scope , id , props ) ;
288
+ }
289
+ }
0 commit comments