1
1
import cpapi = require( '@aws-cdk/aws-codepipeline-api' ) ;
2
+ import events = require( '@aws-cdk/aws-events' ) ;
2
3
import iam = require( '@aws-cdk/aws-iam' ) ;
3
4
import cdk = require( '@aws-cdk/cdk' ) ;
4
5
import _ = require( 'lodash' ) ;
@@ -10,7 +11,7 @@ export = nodeunit.testCase({
10
11
'works' ( test : nodeunit . Test ) {
11
12
const stack = new cdk . Stack ( ) ;
12
13
const pipelineRole = new RoleDouble ( stack , 'PipelineRole' ) ;
13
- const stage = new StageDouble ( { pipelineRole } ) ;
14
+ const stage = new StageDouble ( { pipeline : new PipelineDouble ( { role : pipelineRole } ) } ) ;
14
15
const artifact = new cpapi . Artifact ( stack as any , 'TestArtifact' ) ;
15
16
const action = new cloudformation . PipelineCreateReplaceChangeSetAction ( stack , 'Action' , {
16
17
stage,
@@ -43,7 +44,7 @@ export = nodeunit.testCase({
43
44
'uses a single permission statement if the same ChangeSet name is used' ( test : nodeunit . Test ) {
44
45
const stack = new cdk . Stack ( ) ;
45
46
const pipelineRole = new RoleDouble ( stack , 'PipelineRole' ) ;
46
- const stage = new StageDouble ( { pipelineRole } ) ;
47
+ const stage = new StageDouble ( { pipeline : new PipelineDouble ( { role : pipelineRole } ) } ) ;
47
48
const artifact = new cpapi . Artifact ( stack as any , 'TestArtifact' ) ;
48
49
new cloudformation . PipelineCreateReplaceChangeSetAction ( stack , 'ActionA' , {
49
50
stage,
@@ -97,7 +98,7 @@ export = nodeunit.testCase({
97
98
'works' ( test : nodeunit . Test ) {
98
99
const stack = new cdk . Stack ( ) ;
99
100
const pipelineRole = new RoleDouble ( stack , 'PipelineRole' ) ;
100
- const stage = new StageDouble ( { pipelineRole } ) ;
101
+ const stage = new StageDouble ( { pipeline : new PipelineDouble ( { role : pipelineRole } ) } ) ;
101
102
new cloudformation . PipelineExecuteChangeSetAction ( stack , 'Action' , {
102
103
stage,
103
104
changeSetName : 'MyChangeSet' ,
@@ -120,7 +121,7 @@ export = nodeunit.testCase({
120
121
'uses a single permission statement if the same ChangeSet name is used' ( test : nodeunit . Test ) {
121
122
const stack = new cdk . Stack ( ) ;
122
123
const pipelineRole = new RoleDouble ( stack , 'PipelineRole' ) ;
123
- const stage = new StageDouble ( { pipelineRole } ) ;
124
+ const stage = new StageDouble ( { pipeline : new PipelineDouble ( { role : pipelineRole } ) } ) ;
124
125
new cloudformation . PipelineExecuteChangeSetAction ( stack , 'ActionA' , {
125
126
stage,
126
127
changeSetName : 'MyChangeSet' ,
@@ -158,7 +159,7 @@ export = nodeunit.testCase({
158
159
const stack = new cdk . Stack ( ) ;
159
160
const pipelineRole = new RoleDouble ( stack , 'PipelineRole' ) ;
160
161
const action = new cloudformation . PipelineCreateUpdateStackAction ( stack , 'Action' , {
161
- stage : new StageDouble ( { pipelineRole } ) ,
162
+ stage : new StageDouble ( { pipeline : new PipelineDouble ( { role : pipelineRole } ) } ) ,
162
163
templatePath : new cpapi . Artifact ( stack as any , 'TestArtifact' ) . atPath ( 'some/file' ) ,
163
164
stackName : 'MyStack' ,
164
165
replaceOnFailure : true ,
@@ -179,7 +180,7 @@ export = nodeunit.testCase({
179
180
const stack = new cdk . Stack ( ) ;
180
181
const pipelineRole = new RoleDouble ( stack , 'PipelineRole' ) ;
181
182
const action = new cloudformation . PipelineDeleteStackAction ( stack , 'Action' , {
182
- stage : new StageDouble ( { pipelineRole } ) ,
183
+ stage : new StageDouble ( { pipeline : new PipelineDouble ( { role : pipelineRole } ) } ) ,
183
184
stackName : 'MyStack' ,
184
185
} ) ;
185
186
const stackArn = _stackArn ( 'MyStack' ) ;
@@ -273,26 +274,42 @@ function _stackArn(stackName: string): string {
273
274
} ) ;
274
275
}
275
276
276
- class StageDouble implements cpapi . IStage , cpapi . IInternalStage {
277
- public readonly name : string ;
277
+ class PipelineDouble implements cpapi . IPipeline {
278
278
public readonly pipelineArn : string ;
279
- public readonly pipelineRole : iam . Role ;
280
- public readonly _internal = this ;
279
+ public readonly role : iam . Role ;
281
280
282
- public readonly actions = new Array < cpapi . Action > ( ) ;
283
-
284
- constructor ( { name, pipelineName, pipelineRole } : { name ?: string , pipelineName ?: string , pipelineRole : iam . Role } ) {
285
- this . name = name || 'TestStage' ;
281
+ constructor ( { pipelineName, role } : { pipelineName ?: string , role : iam . Role } ) {
286
282
this . pipelineArn = cdk . ArnUtils . fromComponents ( { service : 'codepipeline' , resource : 'pipeline' , resourceName : pipelineName || 'TestPipeline' } ) ;
287
- this . pipelineRole = pipelineRole ;
283
+ this . role = role ;
288
284
}
289
285
290
- public grantPipelineBucketRead ( ) {
291
- throw new Error ( ' Unsupported' ) ;
286
+ public get uniqueId ( ) : string {
287
+ throw new Error ( " Unsupported" ) ;
292
288
}
293
289
294
- public grantPipelineBucketReadWrite ( ) {
295
- throw new Error ( 'Unsupported' ) ;
290
+ public grantBucketRead ( ) : void {
291
+ throw new Error ( "Unsupported" ) ;
292
+ }
293
+
294
+ public grantBucketReadWrite ( ) : void {
295
+ throw new Error ( "Unsupported" ) ;
296
+ }
297
+
298
+ public asEventRuleTarget ( ) : events . EventRuleTargetProps {
299
+ throw new Error ( "Unsupported" ) ;
300
+ }
301
+ }
302
+
303
+ class StageDouble implements cpapi . IStage , cpapi . IInternalStage {
304
+ public readonly name : string ;
305
+ public readonly pipeline : cpapi . IPipeline ;
306
+ public readonly _internal = this ;
307
+
308
+ public readonly actions = new Array < cpapi . Action > ( ) ;
309
+
310
+ constructor ( { name, pipeline } : { name ?: string , pipeline : cpapi . IPipeline } ) {
311
+ this . name = name || 'TestStage' ;
312
+ this . pipeline = pipeline ;
296
313
}
297
314
298
315
public _attachAction ( action : cpapi . Action ) {
0 commit comments