1
- import { SynthUtils } from '@aws-cdk/assert-internal' ;
2
- import '@aws-cdk/assert-internal/jest' ;
1
+ import { Match , Template } from '@aws-cdk/assertions' ;
3
2
import { AutoScalingGroup } from '@aws-cdk/aws-autoscaling' ;
4
3
import { Certificate } from '@aws-cdk/aws-certificatemanager' ;
5
4
import { MachineImage , Vpc } from '@aws-cdk/aws-ec2' ;
@@ -44,16 +43,16 @@ describe('When Application Load Balancer', () => {
44
43
} ) ;
45
44
46
45
// THEN - stack contains a load balancer, a service, and a target group.
47
- expect ( stack ) . toHaveResource ( 'AWS::ElasticLoadBalancingV2::LoadBalancer' ) ;
46
+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::ElasticLoadBalancingV2::LoadBalancer' , 1 ) ;
48
47
49
- expect ( stack ) . toHaveResource ( 'AWS::ECS::Service' , {
48
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::Service' , {
50
49
DesiredCount : 1 ,
51
50
LaunchType : 'EC2' ,
52
51
} ) ;
53
52
54
- expect ( stack ) . toHaveResourceLike ( 'AWS::ECS::TaskDefinition' , {
53
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::TaskDefinition' , {
55
54
ContainerDefinitions : [
56
- {
55
+ Match . objectLike ( {
57
56
Image : 'test' ,
58
57
LogConfiguration : {
59
58
LogDriver : 'awslogs' ,
@@ -76,7 +75,7 @@ describe('When Application Load Balancer', () => {
76
75
Protocol : 'tcp' ,
77
76
} ,
78
77
] ,
79
- } ,
78
+ } ) ,
80
79
] ,
81
80
NetworkMode : 'bridge' ,
82
81
RequiresCompatibilities : [
@@ -167,7 +166,7 @@ describe('When Application Load Balancer', () => {
167
166
} ) ;
168
167
169
168
// THEN
170
- expect ( stack ) . toHaveResource ( 'AWS::ECS::Service' , {
169
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::Service' , {
171
170
DesiredCount : 3 ,
172
171
LaunchType : 'EC2' ,
173
172
EnableECSManagedTags : true ,
@@ -192,7 +191,7 @@ describe('When Application Load Balancer', () => {
192
191
ServiceName : 'myService' ,
193
192
} ) ;
194
193
195
- expect ( stack ) . toHaveResourceLike ( 'AWS::ECS::TaskDefinition' , {
194
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::TaskDefinition' , {
196
195
ContainerDefinitions : [
197
196
{
198
197
Cpu : 256 ,
@@ -260,7 +259,7 @@ describe('When Application Load Balancer', () => {
260
259
} ,
261
260
} ) ;
262
261
263
- expect ( stack ) . toHaveResourceLike ( 'AWS::ElasticLoadBalancingV2::Listener' , {
262
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ElasticLoadBalancingV2::Listener' , {
264
263
Port : 443 ,
265
264
Protocol : 'HTTPS' ,
266
265
Certificates : [ {
@@ -270,26 +269,6 @@ describe('When Application Load Balancer', () => {
270
269
} ) ;
271
270
} ) ;
272
271
273
- test ( 'set vpc instead of cluster' , ( ) => {
274
- // GIVEN
275
- const stack = new Stack ( ) ;
276
- const vpc = new Vpc ( stack , 'VPC' ) ;
277
-
278
- // WHEN
279
- new ApplicationMultipleTargetGroupsEc2Service ( stack , 'Service' , {
280
- vpc,
281
- memoryLimitMiB : 1024 ,
282
- taskImageOptions : {
283
- image : ContainerImage . fromRegistry ( 'test' ) ,
284
- } ,
285
- } ) ;
286
-
287
- // THEN - stack does not contain a LaunchConfiguration
288
- const template = SynthUtils . synthesize ( stack , { skipValidation : true } ) ;
289
- expect ( template ) . not . toHaveResource ( 'AWS::AutoScaling::LaunchConfiguration' ) ;
290
- expect ( ( ) => SynthUtils . synthesize ( stack ) ) . toThrow ( ) ;
291
- } ) ;
292
-
293
272
test ( 'able to pass pre-defined task definition' , ( ) => {
294
273
// GIVEN
295
274
const stack = new Stack ( ) ;
@@ -319,7 +298,7 @@ describe('When Application Load Balancer', () => {
319
298
} ) ;
320
299
321
300
// THEN
322
- expect ( stack ) . toHaveResourceLike ( 'AWS::ECS::TaskDefinition' , {
301
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::TaskDefinition' , {
323
302
ContainerDefinitions : [
324
303
{
325
304
Essential : true ,
@@ -408,8 +387,8 @@ describe('When Application Load Balancer', () => {
408
387
} ) ;
409
388
410
389
// THEN
411
- const template = SynthUtils . synthesize ( stack ) . template . Outputs ;
412
- expect ( template ) . toEqual ( {
390
+ const outputs = Template . fromStack ( stack ) . findOutputs ( '*' ) ;
391
+ expect ( outputs ) . toEqual ( {
413
392
ServiceLoadBalancerDNSlb175E78BFE : {
414
393
Value : {
415
394
'Fn::GetAtt' : [
@@ -596,7 +575,7 @@ describe('When Application Load Balancer', () => {
596
575
} ) ;
597
576
598
577
// THEN
599
- expect ( stack ) . toHaveResource ( 'AWS::ECS::Service' , {
578
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::Service' , {
600
579
ServiceRegistries : [
601
580
{
602
581
ContainerName : 'web' ,
@@ -611,7 +590,7 @@ describe('When Application Load Balancer', () => {
611
590
] ,
612
591
} ) ;
613
592
614
- expect ( stack ) . toHaveResource ( 'AWS::ServiceDiscovery::Service' , {
593
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ServiceDiscovery::Service' , {
615
594
DnsConfig : {
616
595
DnsRecords : [
617
596
{
@@ -926,14 +905,14 @@ describe('When Network Load Balancer', () => {
926
905
} ) ;
927
906
928
907
// THEN - stack contains a load balancer and a service
929
- expect ( stack ) . toHaveResource ( 'AWS::ElasticLoadBalancingV2::LoadBalancer' ) ;
908
+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::ElasticLoadBalancingV2::LoadBalancer' , 1 ) ;
930
909
931
- expect ( stack ) . toHaveResource ( 'AWS::ECS::Service' , {
910
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::Service' , {
932
911
DesiredCount : 1 ,
933
912
LaunchType : 'EC2' ,
934
913
} ) ;
935
914
936
- expect ( stack ) . toHaveResourceLike ( 'AWS::ECS::TaskDefinition' , {
915
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::TaskDefinition' , {
937
916
ContainerDefinitions : [
938
917
{
939
918
Essential : true ,
@@ -1066,7 +1045,7 @@ describe('When Network Load Balancer', () => {
1066
1045
} ) ;
1067
1046
1068
1047
// THEN
1069
- expect ( stack ) . toHaveResource ( 'AWS::ECS::Service' , {
1048
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::Service' , {
1070
1049
DesiredCount : 3 ,
1071
1050
EnableECSManagedTags : true ,
1072
1051
HealthCheckGracePeriodSeconds : 2 ,
@@ -1092,7 +1071,7 @@ describe('When Network Load Balancer', () => {
1092
1071
ServiceName : 'myService' ,
1093
1072
} ) ;
1094
1073
1095
- expect ( stack ) . toHaveResourceLike ( 'AWS::ECS::TaskDefinition' , {
1074
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::TaskDefinition' , {
1096
1075
ContainerDefinitions : [
1097
1076
{
1098
1077
Cpu : 256 ,
@@ -1161,26 +1140,6 @@ describe('When Network Load Balancer', () => {
1161
1140
} ) ;
1162
1141
} ) ;
1163
1142
1164
- test ( 'set vpc instead of cluster' , ( ) => {
1165
- // GIVEN
1166
- const stack = new Stack ( ) ;
1167
- const vpc = new Vpc ( stack , 'VPC' ) ;
1168
-
1169
- // WHEN
1170
- new NetworkMultipleTargetGroupsEc2Service ( stack , 'Service' , {
1171
- vpc,
1172
- memoryLimitMiB : 256 ,
1173
- taskImageOptions : {
1174
- image : ContainerImage . fromRegistry ( 'test' ) ,
1175
- } ,
1176
- } ) ;
1177
-
1178
- // THEN - stack does not contain a LaunchConfiguration
1179
- const template = SynthUtils . synthesize ( stack , { skipValidation : true } ) ;
1180
- expect ( template ) . not . toHaveResource ( 'AWS::AutoScaling::LaunchConfiguration' ) ;
1181
- expect ( ( ) => SynthUtils . synthesize ( stack ) ) . toThrow ( ) ;
1182
- } ) ;
1183
-
1184
1143
test ( 'able to pass pre-defined task definition' , ( ) => {
1185
1144
// GIVEN
1186
1145
const stack = new Stack ( ) ;
@@ -1210,7 +1169,7 @@ describe('When Network Load Balancer', () => {
1210
1169
} ) ;
1211
1170
1212
1171
// THEN
1213
- expect ( stack ) . toHaveResourceLike ( 'AWS::ECS::TaskDefinition' , {
1172
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::TaskDefinition' , {
1214
1173
ContainerDefinitions : [
1215
1174
{
1216
1175
Essential : true ,
@@ -1357,7 +1316,7 @@ describe('When Network Load Balancer', () => {
1357
1316
} ) ;
1358
1317
1359
1318
// THEN
1360
- expect ( stack ) . toHaveResource ( 'AWS::ECS::Service' , {
1319
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::Service' , {
1361
1320
ServiceRegistries : [
1362
1321
{
1363
1322
ContainerName : 'web' ,
@@ -1372,7 +1331,7 @@ describe('When Network Load Balancer', () => {
1372
1331
] ,
1373
1332
} ) ;
1374
1333
1375
- expect ( stack ) . toHaveResource ( 'AWS::ServiceDiscovery::Service' , {
1334
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ServiceDiscovery::Service' , {
1376
1335
DnsConfig : {
1377
1336
DnsRecords : [
1378
1337
{
0 commit comments