1
+ import { Template , Match } from '@aws-cdk/assertions' ;
2
+ import * as ec2 from '@aws-cdk/aws-ec2' ;
1
3
import * as cdk from '@aws-cdk/core' ;
4
+ import { App , Stack } from '@aws-cdk/core' ;
2
5
import * as ecs from '../lib' ;
3
6
4
- let stack : cdk . Stack ;
7
+ describe ( 'When import an ECS Service' , ( ) => {
8
+ let stack : cdk . Stack ;
5
9
6
- beforeEach ( ( ) => {
7
- stack = new cdk . Stack ( ) ;
8
- } ) ;
10
+ beforeEach ( ( ) => {
11
+ stack = new cdk . Stack ( ) ;
12
+ } ) ;
9
13
10
- describe ( 'When import an ECS Service' , ( ) => {
11
14
test ( 'with serviceArnWithCluster' , ( ) => {
12
15
// GIVEN
13
16
const clusterName = 'cluster-name' ;
@@ -42,3 +45,40 @@ describe('When import an ECS Service', () => {
42
45
} ) . toThrowError ( / i s n o t u s i n g t h e A R N c l u s t e r f o r m a t / ) ;
43
46
} ) ;
44
47
} ) ;
48
+
49
+ test . each ( [
50
+ /* breaker, flag => controller in template */
51
+ /* Flag off => value present if circuitbreaker */
52
+ [ false , false , false ] ,
53
+ [ true , false , true ] ,
54
+ /* Flag on => value never present */
55
+ [ false , true , false ] ,
56
+ [ true , true , false ] ,
57
+ ] ) ( 'circuitbreaker is %p /\\ flag is %p => DeploymentController in output: %p' , ( circuitBreaker , flagValue , controllerInTemplate ) => {
58
+ // GIVEN
59
+ const app = new App ( {
60
+ context : {
61
+ '@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker' : flagValue ,
62
+ } ,
63
+ } ) ;
64
+ const stack = new Stack ( app , 'Stack' ) ;
65
+ const vpc = new ec2 . Vpc ( stack , 'Vpc' ) ;
66
+ const cluster = new ecs . Cluster ( stack , 'EcsCluster' , { vpc } ) ;
67
+ const taskDefinition = new ecs . FargateTaskDefinition ( stack , 'FargateTaskDef' ) ;
68
+ taskDefinition . addContainer ( 'web' , {
69
+ image : ecs . ContainerImage . fromRegistry ( 'amazon/amazon-ecs-sample' ) ,
70
+ } ) ;
71
+
72
+ // WHEN
73
+ new ecs . FargateService ( stack , 'FargateService' , {
74
+ cluster,
75
+ taskDefinition,
76
+ circuitBreaker : circuitBreaker ? { } : undefined ,
77
+ } ) ;
78
+
79
+ // THEN
80
+ const template = Template . fromStack ( stack ) ;
81
+ template . hasResourceProperties ( 'AWS::ECS::Service' , {
82
+ DeploymentController : controllerInTemplate ? { Type : 'ECS' } : Match . absent ( ) ,
83
+ } ) ;
84
+ } ) ;
0 commit comments