1
- import '@aws-cdk/assert-internal/jest' ;
2
- import { isSuperObject } from '@aws-cdk/assert-internal' ;
1
+ import { Match , Matcher , Template } from '@aws-cdk/assertions' ;
3
2
import * as cfn from '@aws-cdk/aws-cloudformation' ;
4
3
import * as codebuild from '@aws-cdk/aws-codebuild' ;
5
4
import * as codepipeline from '@aws-cdk/aws-codepipeline' ;
@@ -135,56 +134,43 @@ describeDeprecated('pipeline deploy stack action', () => {
135
134
capabilities : [ cfn . CloudFormationCapabilities . ANONYMOUS_IAM , cfn . CloudFormationCapabilities . AUTO_EXPAND ] ,
136
135
adminPermissions : false ,
137
136
} ) ) ;
138
- expect ( pipelineStack ) . toHaveResource ( 'AWS::CodePipeline::Pipeline' , hasPipelineAction ( {
139
- Configuration : {
140
- StackName : 'TestStack' ,
141
- ActionMode : 'CHANGE_SET_REPLACE' ,
142
- Capabilities : 'CAPABILITY_NAMED_IAM' ,
143
- } ,
137
+
138
+ Template . fromStack ( pipelineStack ) . hasResourceProperties ( 'AWS::CodePipeline::Pipeline' , hasPipelineActionConfiguration ( {
139
+ StackName : 'TestStack' ,
140
+ ActionMode : 'CHANGE_SET_REPLACE' ,
141
+ Capabilities : 'CAPABILITY_NAMED_IAM' ,
144
142
} ) ) ;
145
- expect ( pipelineStack ) . toHaveResource ( 'AWS::CodePipeline::Pipeline' , hasPipelineAction ( {
146
- Configuration : {
147
- StackName : 'AnonymousIAM' ,
148
- ActionMode : 'CHANGE_SET_REPLACE' ,
149
- Capabilities : 'CAPABILITY_IAM' ,
150
- } ,
143
+ Template . fromStack ( pipelineStack ) . hasResourceProperties ( 'AWS::CodePipeline::Pipeline' , hasPipelineActionConfiguration ( {
144
+ StackName : 'AnonymousIAM' ,
145
+ ActionMode : 'CHANGE_SET_REPLACE' ,
146
+ Capabilities : 'CAPABILITY_IAM' ,
151
147
} ) ) ;
152
- expect ( pipelineStack ) . not . toHaveResource ( 'AWS::CodePipeline::Pipeline' , hasPipelineAction ( {
153
- Configuration : {
154
- StackName : 'NoCapStack' ,
155
- ActionMode : 'CHANGE_SET_REPLACE' ,
156
- Capabilities : 'CAPABILITY_NAMED_IAM' ,
157
- } ,
148
+ Template . fromStack ( pipelineStack ) . hasResourceProperties ( 'AWS::CodePipeline::Pipeline' , Match . not ( hasPipelineActionConfiguration ( {
149
+ StackName : 'NoCapStack' ,
150
+ ActionMode : 'CHANGE_SET_REPLACE' ,
151
+ Capabilities : 'CAPABILITY_NAMED_IAM' ,
152
+ } ) ) ) ;
153
+ Template . fromStack ( pipelineStack ) . hasResourceProperties ( 'AWS::CodePipeline::Pipeline' , Match . not ( hasPipelineActionConfiguration ( {
154
+ StackName : 'NoCapStack' ,
155
+ ActionMode : 'CHANGE_SET_REPLACE' ,
156
+ Capabilities : 'CAPABILITY_IAM' ,
157
+ } ) ) ) ;
158
+ Template . fromStack ( pipelineStack ) . hasResourceProperties ( 'AWS::CodePipeline::Pipeline' , hasPipelineActionConfiguration ( {
159
+ StackName : 'NoCapStack' ,
160
+ ActionMode : 'CHANGE_SET_REPLACE' ,
158
161
} ) ) ;
159
- expect ( pipelineStack ) . not . toHaveResource ( 'AWS::CodePipeline::Pipeline' , hasPipelineAction ( {
160
- Configuration : {
161
- StackName : 'NoCapStack' ,
162
- ActionMode : 'CHANGE_SET_REPLACE' ,
163
- Capabilities : 'CAPABILITY_IAM' ,
164
- } ,
162
+ Template . fromStack ( pipelineStack ) . hasResourceProperties ( 'AWS::CodePipeline::Pipeline' , hasPipelineActionConfiguration ( {
163
+ StackName : 'AutoExpand' ,
164
+ ActionMode : 'CHANGE_SET_REPLACE' ,
165
+ Capabilities : 'CAPABILITY_AUTO_EXPAND' ,
165
166
} ) ) ;
166
- expect ( pipelineStack ) . toHaveResource ( 'AWS::CodePipeline::Pipeline' , hasPipelineAction ( {
167
- Configuration : {
168
- StackName : 'NoCapStack' ,
169
- ActionMode : 'CHANGE_SET_REPLACE' ,
170
- } ,
167
+ Template . fromStack ( pipelineStack ) . hasResourceProperties ( 'AWS::CodePipeline::Pipeline' , hasPipelineActionConfiguration ( {
168
+ StackName : 'AnonymousIAMAndAutoExpand' ,
169
+ ActionMode : 'CHANGE_SET_REPLACE' ,
170
+ Capabilities : 'CAPABILITY_IAM,CAPABILITY_AUTO_EXPAND' ,
171
171
} ) ) ;
172
- expect ( pipelineStack ) . toHaveResource ( 'AWS::CodePipeline::Pipeline' , hasPipelineAction ( {
173
- Configuration : {
174
- StackName : 'AutoExpand' ,
175
- ActionMode : 'CHANGE_SET_REPLACE' ,
176
- Capabilities : 'CAPABILITY_AUTO_EXPAND' ,
177
- } ,
178
- } ) ) ;
179
- expect ( pipelineStack ) . toHaveResource ( 'AWS::CodePipeline::Pipeline' , hasPipelineAction ( {
180
- Configuration : {
181
- StackName : 'AnonymousIAMAndAutoExpand' ,
182
- ActionMode : 'CHANGE_SET_REPLACE' ,
183
- Capabilities : 'CAPABILITY_IAM,CAPABILITY_AUTO_EXPAND' ,
184
- } ,
185
- } ) ) ;
186
-
187
172
} ) ;
173
+
188
174
test ( 'users can use admin permissions' , ( ) => {
189
175
const pipelineStack = getTestStack ( ) ;
190
176
const selfUpdatingStack = createSelfUpdatingStack ( pipelineStack ) ;
@@ -196,7 +182,7 @@ describeDeprecated('pipeline deploy stack action', () => {
196
182
input : selfUpdatingStack . synthesizedApp ,
197
183
adminPermissions : true ,
198
184
} ) ) ;
199
- expect ( pipelineStack ) . toHaveResource ( 'AWS::IAM::Policy' , {
185
+ Template . fromStack ( pipelineStack ) . hasResourceProperties ( 'AWS::IAM::Policy' , {
200
186
PolicyDocument : {
201
187
Version : '2012-10-17' ,
202
188
Statement : [
@@ -251,15 +237,13 @@ describeDeprecated('pipeline deploy stack action', () => {
251
237
] ,
252
238
} ,
253
239
} ) ;
254
- expect ( pipelineStack ) . toHaveResource ( 'AWS::CodePipeline::Pipeline' , hasPipelineAction ( {
255
- Configuration : {
256
- StackName : 'TestStack' ,
257
- ActionMode : 'CHANGE_SET_REPLACE' ,
258
- Capabilities : 'CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND' ,
259
- } ,
240
+ Template . fromStack ( pipelineStack ) . hasResourceProperties ( 'AWS::CodePipeline::Pipeline' , hasPipelineActionConfiguration ( {
241
+ StackName : 'TestStack' ,
242
+ ActionMode : 'CHANGE_SET_REPLACE' ,
243
+ Capabilities : 'CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND' ,
260
244
} ) ) ;
261
-
262
245
} ) ;
246
+
263
247
test ( 'users can supply a role for deploy action' , ( ) => {
264
248
const pipelineStack = getTestStack ( ) ;
265
249
const selfUpdatingStack = createSelfUpdatingStack ( pipelineStack ) ;
@@ -313,7 +297,7 @@ describeDeprecated('pipeline deploy stack action', () => {
313
297
} ) ) ;
314
298
315
299
// THEN //
316
- expect ( pipelineStack ) . toHaveResource ( 'AWS::IAM::Policy' , {
300
+ Template . fromStack ( pipelineStack ) . hasResourceProperties ( 'AWS::IAM::Policy' , {
317
301
PolicyDocument : {
318
302
Version : '2012-10-17' ,
319
303
Statement : [
@@ -391,7 +375,7 @@ describeDeprecated('pipeline deploy stack action', () => {
391
375
const app = new cdk . App ( ) ;
392
376
393
377
const deployedStack = new cdk . Stack ( app , 'DeployedStack' ) ;
394
- for ( let i = 0 ; i < assetCount ; i ++ ) {
378
+ for ( let i = 0 ; i < assetCount ; i ++ ) {
395
379
deployedStack . node . addMetadata ( cxschema . ArtifactMetadataEntryType . ASSET , { } ) ;
396
380
}
397
381
@@ -406,7 +390,6 @@ describeDeprecated('pipeline deploy stack action', () => {
406
390
} ,
407
391
) ,
408
392
) ;
409
-
410
393
} ) ;
411
394
412
395
test ( 'allows overriding the ChangeSet and Execute action names' , ( ) => {
@@ -425,25 +408,21 @@ describeDeprecated('pipeline deploy stack action', () => {
425
408
] ,
426
409
} ) ;
427
410
428
- expect ( stack ) . toHaveResourceLike ( 'AWS::CodePipeline::Pipeline' , {
429
- Stages : [
430
- { } ,
431
- { } ,
432
- {
411
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::CodePipeline::Pipeline' , {
412
+ Stages : Match . arrayWith ( [
413
+ Match . objectLike ( {
433
414
Name : 'Deploy' ,
434
- Actions : [
435
- {
415
+ Actions : Match . arrayWith ( [
416
+ Match . objectLike ( {
436
417
Name : 'Prepare' ,
437
- } ,
438
- {
418
+ } ) ,
419
+ Match . objectLike ( {
439
420
Name : 'Deploy' ,
440
- } ,
441
- ] ,
442
- } ,
443
- ] ,
421
+ } ) ,
422
+ ] ) ,
423
+ } ) ,
424
+ ] ) ,
444
425
} ) ;
445
-
446
-
447
426
} ) ;
448
427
} ) ;
449
428
@@ -481,7 +460,7 @@ function createSelfUpdatingStack(pipelineStack: cdk.Stack): SelfUpdatingPipeline
481
460
} ) ;
482
461
483
462
// simple source
484
- const bucket = s3 . Bucket . fromBucketArn ( pipeline , 'PatternBucket' , 'arn:aws:s3:::totally-fake-bucket' ) ;
463
+ const bucket = s3 . Bucket . fromBucketArn ( pipeline , 'PatternBucket' , 'arn:aws:s3:::totally-fake-bucket' ) ;
485
464
const sourceOutput = new codepipeline . Artifact ( 'SourceOutput' ) ;
486
465
const sourceAction = new cpactions . S3SourceAction ( {
487
466
actionName : 'S3Source' ,
@@ -509,15 +488,16 @@ function createSelfUpdatingStack(pipelineStack: cdk.Stack): SelfUpdatingPipeline
509
488
return { synthesizedApp : buildOutput , pipeline } ;
510
489
}
511
490
512
- function hasPipelineAction ( expectedAction : any ) : ( props : any ) => boolean {
513
- return ( props : any ) => {
514
- for ( const stage of props . Stages ) {
515
- for ( const action of stage . Actions ) {
516
- if ( isSuperObject ( action , expectedAction , [ ] , true ) ) {
517
- return true ;
518
- }
519
- }
520
- }
521
- return false ;
522
- } ;
523
- }
491
+ function hasPipelineActionConfiguration ( expectedActionConfiguration : any ) : Matcher {
492
+ return Match . objectLike ( {
493
+ Stages : Match . arrayWith ( [
494
+ Match . objectLike ( {
495
+ Actions : Match . arrayWith ( [
496
+ Match . objectLike ( {
497
+ Configuration : expectedActionConfiguration ,
498
+ } ) ,
499
+ ] ) ,
500
+ } ) ,
501
+ ] ) ,
502
+ } ) ;
503
+ }
0 commit comments