diff --git a/packages/@aws-cdk/aws-ecs/package.json b/packages/@aws-cdk/aws-ecs/package.json index 4dd48f968fcf3..c3d3def173a2b 100644 --- a/packages/@aws-cdk/aws-ecs/package.json +++ b/packages/@aws-cdk/aws-ecs/package.json @@ -79,7 +79,7 @@ }, "license": "Apache-2.0", "devDependencies": { - "@aws-cdk/assert-internal": "0.0.0", + "@aws-cdk/assertions": "0.0.0", "@aws-cdk/aws-s3-deployment": "0.0.0", "@aws-cdk/cdk-build-tools": "0.0.0", "@aws-cdk/cdk-integ-tools": "0.0.0", diff --git a/packages/@aws-cdk/aws-ecs/test/app-mesh-proxy-configuration.test.ts b/packages/@aws-cdk/aws-ecs/test/app-mesh-proxy-configuration.test.ts index 7c8bd5f880f77..683a7301b54dd 100644 --- a/packages/@aws-cdk/aws-ecs/test/app-mesh-proxy-configuration.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/app-mesh-proxy-configuration.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as cdk from '@aws-cdk/core'; import * as ecs from '../lib'; @@ -33,7 +33,7 @@ describe('app mesh proxy configuration', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ProxyConfiguration: { ContainerName: 'envoy', ProxyConfigurationProperties: [ @@ -99,7 +99,7 @@ describe('app mesh proxy configuration', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ProxyConfiguration: { ContainerName: 'envoy', ProxyConfigurationProperties: [ @@ -155,7 +155,7 @@ describe('app mesh proxy configuration', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ProxyConfiguration: { ContainerName: 'envoy', ProxyConfigurationProperties: [ diff --git a/packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts index fb4d5c9f691cc..de7e4faa24f19 100644 --- a/packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as logs from '@aws-cdk/aws-logs'; import * as cdk from '@aws-cdk/core'; import * as ecs from '../lib'; @@ -29,13 +29,13 @@ describe('aws log driver', () => { }); // THEN - expect(stack).toHaveResource('AWS::Logs::LogGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', { RetentionInDays: logs.RetentionDays.ONE_MONTH, }); - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'awslogs', Options: { @@ -47,11 +47,9 @@ describe('aws log driver', () => { 'mode': 'non-blocking', }, }, - }, + }), ], }); - - }); test('create an aws log driver using awsLogs', () => { @@ -67,13 +65,13 @@ describe('aws log driver', () => { }); // THEN - expect(stack).toHaveResource('AWS::Logs::LogGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', { RetentionInDays: logs.RetentionDays.ONE_MONTH, }); - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'awslogs', Options: { @@ -84,11 +82,9 @@ describe('aws log driver', () => { 'awslogs-multiline-pattern': 'pattern', }, }, - }, + }), ], }); - - }); test('with a defined log group', () => { @@ -105,13 +101,13 @@ describe('aws log driver', () => { }); // THEN - expect(stack).toHaveResource('AWS::Logs::LogGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', { RetentionInDays: logs.RetentionDays.TWO_YEARS, }); - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'awslogs', Options: { @@ -120,11 +116,9 @@ describe('aws log driver', () => { 'awslogs-region': { Ref: 'AWS::Region' }, }, }, - }, + }), ], }); - - }); test('without a defined log group: creates one anyway', () => { @@ -137,9 +131,7 @@ describe('aws log driver', () => { }); // THEN - expect(stack).toHaveResource('AWS::Logs::LogGroup', {}); - - + Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', {}); }); test('throws when specifying log retention and log group', () => { @@ -172,10 +164,10 @@ describe('aws log driver', () => { }); // THEN - expect(stack).toCountResources('AWS::Logs::LogGroup', 0); - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).resourceCountIs('AWS::Logs::LogGroup', 0); + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'awslogs', Options: { @@ -184,9 +176,8 @@ describe('aws log driver', () => { 'awslogs-region': logGroupRegion, }, }, - }, + }), ], }); }); - }); diff --git a/packages/@aws-cdk/aws-ecs/test/cluster.test.ts b/packages/@aws-cdk/aws-ecs/test/cluster.test.ts index 15a25f6987559..f6b34f76439c0 100644 --- a/packages/@aws-cdk/aws-ecs/test/cluster.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/cluster.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { ABSENT } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as autoscaling from '@aws-cdk/aws-autoscaling'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as kms from '@aws-cdk/aws-kms'; @@ -21,9 +20,9 @@ describe('cluster', () => { instanceType: new ec2.InstanceType('t2.micro'), }); - expect(stack).toHaveResource('AWS::ECS::Cluster'); + Template.fromStack(stack).resourceCountIs('AWS::ECS::Cluster', 1); - expect(stack).toHaveResource('AWS::EC2::VPC', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::VPC', { CidrBlock: '10.0.0.0/16', EnableDnsHostnames: true, EnableDnsSupport: true, @@ -36,7 +35,7 @@ describe('cluster', () => { ], }); - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -69,7 +68,7 @@ describe('cluster', () => { }, }); - expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { MaxSize: '1', MinSize: '1', LaunchConfigurationName: { @@ -92,7 +91,7 @@ describe('cluster', () => { ], }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroup', { GroupDescription: 'Default/EcsCluster/DefaultAutoScalingGroup/InstanceSecurityGroup', SecurityGroupEgress: [ { @@ -112,7 +111,7 @@ describe('cluster', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Role', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: [ { @@ -127,7 +126,7 @@ describe('cluster', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -192,9 +191,9 @@ describe('cluster', () => { instanceType: new ec2.InstanceType('t2.micro'), }); - expect(stack).toHaveResource('AWS::ECS::Cluster'); + Template.fromStack(stack).resourceCountIs('AWS::ECS::Cluster', 1); - expect(stack).toHaveResource('AWS::EC2::VPC', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::VPC', { CidrBlock: '10.0.0.0/16', EnableDnsHostnames: true, EnableDnsSupport: true, @@ -207,7 +206,7 @@ describe('cluster', () => { ], }); - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -240,7 +239,7 @@ describe('cluster', () => { }, }); - expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { MaxSize: '1', MinSize: '1', LaunchConfigurationName: { @@ -263,7 +262,7 @@ describe('cluster', () => { ], }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroup', { GroupDescription: 'Default/EcsCluster/DefaultAutoScalingGroup/InstanceSecurityGroup', SecurityGroupEgress: [ { @@ -283,7 +282,7 @@ describe('cluster', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Role', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: [ { @@ -298,7 +297,7 @@ describe('cluster', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -381,7 +380,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::AutoScaling::LifecycleHook', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LifecycleHook', { AutoScalingGroupName: { Ref: 'EcsClusterDefaultAutoScalingGroupASGC1A785DB' }, LifecycleTransition: 'autoscaling:EC2_INSTANCE_TERMINATING', DefaultResult: 'CONTINUE', @@ -390,7 +389,7 @@ describe('cluster', () => { RoleARN: { 'Fn::GetAtt': ['EcsClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleA38EC83B', 'Arn'] }, }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Timeout: 310, Environment: { Variables: { @@ -402,7 +401,7 @@ describe('cluster', () => { Handler: 'index.lambda_handler', }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -522,7 +521,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::SNS::Topic', { + Template.fromStack(stack).hasResourceProperties('AWS::SNS::Topic', { KmsMasterKeyId: { 'Fn::GetAtt': [ 'Key961B73FD', @@ -549,16 +548,16 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::ServiceDiscovery::PrivateDnsNamespace', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::PrivateDnsNamespace', { Name: 'foo.com', Vpc: { Ref: 'MyVpcF9F0CA6F', }, }); - expect(stack).toHaveResource('AWS::ECS::Cluster'); + Template.fromStack(stack).resourceCountIs('AWS::ECS::Cluster', 1); - expect(stack).toHaveResource('AWS::EC2::VPC', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::VPC', { CidrBlock: '10.0.0.0/16', EnableDnsHostnames: true, EnableDnsSupport: true, @@ -571,7 +570,7 @@ describe('cluster', () => { ], }); - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -604,7 +603,7 @@ describe('cluster', () => { }, }); - expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { MaxSize: '1', MinSize: '1', LaunchConfigurationName: { @@ -627,7 +626,7 @@ describe('cluster', () => { ], }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroup', { GroupDescription: 'Default/EcsCluster/DefaultAutoScalingGroup/InstanceSecurityGroup', SecurityGroupEgress: [ { @@ -647,7 +646,7 @@ describe('cluster', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Role', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: [ { @@ -662,7 +661,7 @@ describe('cluster', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -727,7 +726,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { InstanceType: 'm3.large', }); @@ -746,7 +745,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { MaxSize: '3', }); @@ -767,7 +766,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiwindowsserver2019englishfullrecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -826,7 +825,7 @@ describe('cluster', () => { // THEN const assembly = app.synth(); const template = assembly.getStackByName(stack.stackName).template; - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinux2gpurecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -1028,7 +1027,7 @@ describe('cluster', () => { // THEN const assembly = app.synth(); const template = assembly.getStackByName(stack.stackName).template; - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinux2gpurecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -1059,7 +1058,7 @@ describe('cluster', () => { // THEN const assembly = app.synth(); const template = assembly.getStackByName(stack.stackName).template; - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinuxrecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -1112,7 +1111,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { SpotPrice: '0.31', }); @@ -1131,7 +1130,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::AutoScaling::LifecycleHook', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LifecycleHook', { HeartbeatTimeout: 60, }); @@ -1151,7 +1150,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { UserData: { 'Fn::Base64': { 'Fn::Join': [ @@ -1183,7 +1182,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { UserData: { 'Fn::Base64': { 'Fn::Join': [ @@ -1219,7 +1218,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::ServiceDiscovery::PrivateDnsNamespace', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::PrivateDnsNamespace', { Name: 'foo.com', Vpc: { Ref: 'MyVpcF9F0CA6F', @@ -1246,7 +1245,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::ServiceDiscovery::PublicDnsNamespace', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::PublicDnsNamespace', { Name: 'foo.com', }); @@ -1331,11 +1330,11 @@ describe('cluster', () => { cluster.connections.allowToAnyIpv4(ec2.Port.tcp(443)); // THEN - expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupEgress', { GroupId: 'sg-1', }); - expect(stack).toCountResources('AWS::EC2::SecurityGroupEgress', 1); + Template.fromStack(stack).resourceCountIs('AWS::EC2::SecurityGroupEgress', 1); }); @@ -1403,9 +1402,9 @@ describe('cluster', () => { }, }); - expect(stack).toHaveResource('AWS::ECS::Cluster'); + Template.fromStack(stack).resourceCountIs('AWS::ECS::Cluster', 1); - expect(stack).toHaveResource('AWS::EC2::VPC', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::VPC', { CidrBlock: '10.0.0.0/16', EnableDnsHostnames: true, EnableDnsSupport: true, @@ -1418,7 +1417,7 @@ describe('cluster', () => { ], }); - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -1452,7 +1451,7 @@ describe('cluster', () => { }, }); - expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { MaxSize: '1', MinSize: '1', LaunchConfigurationName: { @@ -1475,7 +1474,7 @@ describe('cluster', () => { ], }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroup', { GroupDescription: 'Default/EcsCluster/DefaultAutoScalingGroup/InstanceSecurityGroup', SecurityGroupEgress: [ { @@ -1507,7 +1506,7 @@ describe('cluster', () => { new ecs.Cluster(stack, 'EcsCluster', { containerInsights: true }); // THEN - expect(stack).toHaveResource('AWS::ECS::Cluster', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Cluster', { ClusterSettings: [ { Name: 'containerInsights', @@ -1527,7 +1526,7 @@ describe('cluster', () => { new ecs.Cluster(stack, 'EcsCluster', { containerInsights: false }); // THEN - expect(stack).toHaveResource('AWS::ECS::Cluster', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Cluster', { ClusterSettings: [ { Name: 'containerInsights', @@ -1593,9 +1592,9 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Cluster'); - expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup'); - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).resourceCountIs('AWS::ECS::Cluster', 1); + Template.fromStack(stack).resourceCountIs('AWS::AutoScaling::AutoScalingGroup', 1); + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsservicebottlerocketawsecs1x8664latestimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -1614,7 +1613,7 @@ describe('cluster', () => { }, }, }); - expect(stack).toHaveResourceLike('AWS::IAM::Role', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: [ { @@ -1685,7 +1684,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsservicebottlerocketawsecs1arm64latestimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -1714,7 +1713,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { UserData: { 'Fn::Base64': { 'Fn::Join': [ @@ -1742,11 +1741,11 @@ describe('cluster', () => { new ecs.Cluster(stack, 'EcsCluster', { capacityProviders: ['FARGATE_SPOT'] }); // THEN - expect(stack).toHaveResource('AWS::ECS::Cluster', { - CapacityProviders: ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Cluster', { + CapacityProviders: Match.absent(), }); - expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE_SPOT'], }); @@ -1764,11 +1763,11 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Cluster', { - CapacityProviders: ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Cluster', { + CapacityProviders: Match.absent(), }); - expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE', 'FARGATE_SPOT'], }); @@ -1785,11 +1784,11 @@ describe('cluster', () => { cluster.enableFargateCapacityProviders(); // THEN - expect(stack).toHaveResource('AWS::ECS::Cluster', { - CapacityProviders: ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Cluster', { + CapacityProviders: Match.absent(), }); - expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE', 'FARGATE_SPOT'], }); @@ -1807,11 +1806,11 @@ describe('cluster', () => { cluster.addCapacityProvider('FARGATE'); // does not add twice // THEN - expect(stack).toHaveResource('AWS::ECS::Cluster', { - CapacityProviders: ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Cluster', { + CapacityProviders: Match.absent(), }); - expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE'], }); @@ -1829,11 +1828,11 @@ describe('cluster', () => { cluster.addCapacityProvider('FARGATE'); // does not add twice // THEN - expect(stack).toHaveResource('AWS::ECS::Cluster', { - CapacityProviders: ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Cluster', { + CapacityProviders: Match.absent(), }); - expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE'], }); @@ -1871,7 +1870,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::CapacityProvider', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::CapacityProvider', { AutoScalingGroupProvider: { AutoScalingGroupArn: { Ref: 'asgASG4D014670', @@ -1904,12 +1903,12 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::CapacityProvider', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::CapacityProvider', { AutoScalingGroupProvider: { AutoScalingGroupArn: { Ref: 'asgASG4D014670', }, - ManagedScaling: ABSENT, + ManagedScaling: Match.absent(), ManagedTerminationProtection: 'ENABLED', }, }); @@ -1933,7 +1932,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { NewInstancesProtectedFromScaleIn: true, }); @@ -1957,10 +1956,9 @@ describe('cluster', () => { }); // THEN - expect(stack).not.toHaveResource('AWS::AutoScaling::AutoScalingGroup', { - NewInstancesProtectedFromScaleIn: true, + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { + NewInstancesProtectedFromScaleIn: Match.absent(), }); - }); test('can add ASG capacity via Capacity Provider', () => { @@ -1989,7 +1987,7 @@ describe('cluster', () => { cluster.addAsgCapacityProvider(capacityProvider); // THEN - expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::ClusterCapacityProviderAssociations', { Cluster: { Ref: 'EcsCluster97242B84', }, @@ -2036,7 +2034,7 @@ describe('cluster', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Cluster', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Cluster', { Configuration: { ExecuteCommandConfiguration: { KmsKeyId: { @@ -2186,7 +2184,7 @@ test('can add ASG capacity via Capacity Provider by not specifying machineImageT // THEN Bottlerocket LaunchConfiguration - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsservicebottlerocketawsecs1x8664latestimageidC96584B6F00A464EAD1953AFF4B05118Parameter', @@ -2208,7 +2206,7 @@ test('can add ASG capacity via Capacity Provider by not specifying machineImageT }); // THEN AmazonLinux2 LaunchConfiguration - expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -2229,7 +2227,7 @@ test('can add ASG capacity via Capacity Provider by not specifying machineImageT }, }); - expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: [ 'FARGATE', 'FARGATE_SPOT', diff --git a/packages/@aws-cdk/aws-ecs/test/container-definition.test.ts b/packages/@aws-cdk/aws-ecs/test/container-definition.test.ts index ac7a7a7824450..47ee57b4625d6 100644 --- a/packages/@aws-cdk/aws-ecs/test/container-definition.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/container-definition.test.ts @@ -1,6 +1,5 @@ -import '@aws-cdk/assert-internal/jest'; import * as path from 'path'; -import { InspectionFailure } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as ecr_assets from '@aws-cdk/aws-ecr-assets'; import * as s3 from '@aws-cdk/aws-s3'; import * as secretsmanager from '@aws-cdk/aws-secretsmanager'; @@ -24,7 +23,7 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { Essential: true, @@ -91,7 +90,7 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { Command: [ @@ -491,16 +490,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', (props: any, inspection: InspectionFailure) => { - if (props.NetworkMode === undefined) { - return true; - } - - inspection.failureReason = 'CF template should not have NetworkMode defined for a task definition that relies on NAT network mode.'; - return false; + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { + NetworkMode: Match.absent(), }); - - }); }); }); @@ -700,9 +692,9 @@ describe('container definition', () => { container.addEnvironment('SECOND_ENVIRONEMENT_VARIABLE', 'second test value'); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Environment: [{ Name: 'TEST_ENVIRONMENT_VARIABLE', Value: 'test environment variable value', @@ -711,11 +703,9 @@ describe('container definition', () => { Name: 'SECOND_ENVIRONEMENT_VARIABLE', Value: 'second test value', }], - }, + }), ], }); - - }); test('can add environment variables to container definition with no environment', () => { @@ -731,18 +721,16 @@ describe('container definition', () => { container.addEnvironment('SECOND_ENVIRONEMENT_VARIABLE', 'second test value'); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Environment: [{ Name: 'SECOND_ENVIRONEMENT_VARIABLE', Value: 'second test value', }], - }, + }), ], }); - - }); test('can add port mappings to the container definition by props', () => { @@ -758,11 +746,11 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { - PortMappings: [{ ContainerPort: 80 }], - }, + Match.objectLike({ + PortMappings: [Match.objectLike({ ContainerPort: 80 })], + }), ], }); }); @@ -782,14 +770,14 @@ describe('container definition', () => { containerDefinition.addPortMappings({ containerPort: 443 }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ PortMappings: [ - { ContainerPort: 80 }, - { ContainerPort: 443 }, + Match.objectLike({ ContainerPort: 80 }), + Match.objectLike({ ContainerPort: 443 }), ], - }, + }), ], }); }); @@ -810,9 +798,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ SystemControls: [ { Namespace: 'SomeNamespace1', @@ -823,7 +811,7 @@ describe('container definition', () => { Value: 'SomeValue2', }, ], - }, + }), ], }); }); @@ -843,9 +831,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ EnvironmentFiles: [{ Type: 's3', Value: { @@ -887,11 +875,10 @@ describe('container definition', () => { ], }, }], - }, + }), ], }); - }); test('can add s3 bucket environment file to the container definition', () => { // GIVEN @@ -909,9 +896,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ EnvironmentFiles: [{ Type: 's3', Value: { @@ -927,13 +914,12 @@ describe('container definition', () => { ], }, }], - }, + }), ], }); - - }); }); + describe('with Fargate task definitions', () => { test('can add asset environment file to the container definition', () => { // GIVEN @@ -948,9 +934,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ EnvironmentFiles: [{ Type: 's3', Value: { @@ -992,12 +978,11 @@ describe('container definition', () => { ], }, }], - }, + }), ], }); - - }); + test('can add s3 bucket environment file to the container definition', () => { // GIVEN const stack = new cdk.Stack(); @@ -1014,9 +999,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ EnvironmentFiles: [{ Type: 's3', Value: { @@ -1032,11 +1017,9 @@ describe('container definition', () => { ], }, }], - }, + }), ], }); - - }); }); }); @@ -1055,9 +1038,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Image: 'test', ResourceRequirements: [ { @@ -1065,11 +1048,9 @@ describe('container definition', () => { Value: '4', }, ], - }, + }), ], }); - - }); }); @@ -1097,14 +1078,14 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', InferenceAccelerators: [{ DeviceName: 'device1', DeviceType: 'eia2.medium', }], ContainerDefinitions: [ - { + Match.objectLike({ Image: 'test', ResourceRequirements: [ { @@ -1112,12 +1093,11 @@ describe('container definition', () => { Value: 'device1', }, ], - }, + }), ], }); - - }); + test('correctly adds resource requirements to container definition using both props and addInferenceAcceleratorResource method', () => { // GIVEN const stack = new cdk.Stack(); @@ -1146,7 +1126,7 @@ describe('container definition', () => { container.addInferenceAcceleratorResource('device2'); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', InferenceAccelerators: [{ DeviceName: 'device1', @@ -1156,7 +1136,7 @@ describe('container definition', () => { DeviceType: 'eia2.large', }], ContainerDefinitions: [ - { + Match.objectLike({ Image: 'test', ResourceRequirements: [ { @@ -1168,11 +1148,11 @@ describe('container definition', () => { Value: 'device2', }, ], - }, + }), ], }); - }); + test('throws when the value of inference accelerator resource does not match any inference accelerators defined in the Task Definition', () => { // GIVEN const stack = new cdk.Stack(); @@ -1222,14 +1202,14 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', InferenceAccelerators: [{ DeviceName: 'device1', DeviceType: 'eia2.medium', }], ContainerDefinitions: [ - { + Match.objectLike({ Image: 'test', ResourceRequirements: [{ Type: 'InferenceAccelerator', @@ -1238,7 +1218,7 @@ describe('container definition', () => { Type: 'GPU', Value: '2', }], - }, + }), ], }); }); @@ -1265,9 +1245,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Secrets: [ { Name: 'SECRET', @@ -1299,11 +1279,11 @@ describe('container definition', () => { }, }, ], - }, + }), ], }); - expect(stack).toHaveResourceLike('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -1349,8 +1329,6 @@ describe('container definition', () => { Version: '2012-10-17', }, }); - - }); test('use a specific secret JSON key as environment variable', () => { @@ -1370,9 +1348,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Secrets: [ { Name: 'SECRET_KEY', @@ -1389,11 +1367,9 @@ describe('container definition', () => { }, }, ], - }, + }), ], }); - - }); test('use a specific secret JSON field as environment variable for a Fargate task', () => { @@ -1413,9 +1389,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Secrets: [ { Name: 'SECRET_KEY', @@ -1432,11 +1408,9 @@ describe('container definition', () => { }, }, ], - }, + }), ], }); - - }); test('can add AWS logging to container definition', () => { @@ -1452,9 +1426,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'awslogs', Options: { @@ -1463,11 +1437,11 @@ describe('container definition', () => { 'awslogs-region': { Ref: 'AWS::Region' }, }, }, - }, + }), ], }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -1479,8 +1453,6 @@ describe('container definition', () => { Version: '2012-10-17', }, }); - - }); test('can set Health Check with defaults', () => { @@ -1499,20 +1471,18 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ HealthCheck: { Command: ['CMD-SHELL', hcCommand], Interval: 30, Retries: 3, Timeout: 5, }, - }, + }), ], }); - - }); test('throws when setting Health Check with no commands', () => { @@ -1531,7 +1501,7 @@ describe('container definition', () => { // THEN expect(() => { - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { HealthCheck: { @@ -1567,9 +1537,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ HealthCheck: { Command: ['CMD-SHELL', hcCommand], Interval: 20, @@ -1577,11 +1547,9 @@ describe('container definition', () => { Timeout: 5, StartPeriod: 10, }, - }, + }), ], }); - - }); test('can specify Health Check values in array form starting with CMD-SHELL', () => { @@ -1603,9 +1571,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ HealthCheck: { Command: ['CMD-SHELL', hcCommand], Interval: 20, @@ -1613,11 +1581,9 @@ describe('container definition', () => { Timeout: 5, StartPeriod: 10, }, - }, + }), ], }); - - }); test('can specify Health Check values in array form starting with CMD', () => { @@ -1639,9 +1605,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ HealthCheck: { Command: ['CMD', hcCommand], Interval: 20, @@ -1649,11 +1615,9 @@ describe('container definition', () => { Timeout: 5, StartPeriod: 10, }, - }, + }), ], }); - - }); test('can specify private registry credentials', () => { @@ -1673,18 +1637,18 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Image: 'user-x/my-app', RepositoryCredentials: { CredentialsParameter: mySecretArn, }, - }, + }), ], }); - expect(stack).toHaveResourceLike('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -1698,8 +1662,6 @@ describe('container definition', () => { ], }, }); - - }); describe('_linkContainer works properly', () => { @@ -1756,18 +1718,16 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Image: 'test', LinuxParameters: { Capabilities: {}, }, - }, + }), ], }); - - }); test('before calling addContainer', () => { @@ -1791,9 +1751,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Image: 'test', LinuxParameters: { Capabilities: { @@ -1803,11 +1763,9 @@ describe('container definition', () => { InitProcessEnabled: true, SharedMemorySize: 1024, }, - }, + }), ], }); - - }); test('after calling addContainer', () => { @@ -1833,9 +1791,9 @@ describe('container definition', () => { linuxParameters.dropCapabilities(ecs.Capability.SETUID); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Image: 'test', LinuxParameters: { Capabilities: { @@ -1845,11 +1803,9 @@ describe('container definition', () => { InitProcessEnabled: true, SharedMemorySize: 1024, }, - }, + }), ], }); - - }); test('with one or more host devices', () => { @@ -1874,9 +1830,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Image: 'test', LinuxParameters: { Devices: [ @@ -1887,11 +1843,9 @@ describe('container definition', () => { InitProcessEnabled: true, SharedMemorySize: 1024, }, - }, + }), ], }); - - }); test('with the tmpfs mount for a container', () => { @@ -1917,9 +1871,9 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Image: 'test', LinuxParameters: { Tmpfs: [ @@ -1931,11 +1885,9 @@ describe('container definition', () => { InitProcessEnabled: true, SharedMemorySize: 1024, }, - }, + }), ], }); - - }); }); @@ -1954,7 +1906,7 @@ describe('container definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { Essential: true, @@ -1976,7 +1928,7 @@ describe('container definition', () => { }, ], }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/cross-stack.test.ts b/packages/@aws-cdk/aws-ecs/test/ec2/cross-stack.test.ts index aebf98820d885..4ad3830fa7a9a 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/cross-stack.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/ec2/cross-stack.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2'; import { App, Stack } from '@aws-cdk/core'; @@ -50,7 +50,7 @@ describe('cross stack', () => { }); // THEN: it shouldn't throw due to cyclic dependencies - expect(stack2).toHaveResource('AWS::ECS::Service'); + Template.fromStack(stack2).resourceCountIs('AWS::ECS::Service', 1); expectIngress(stack2); @@ -67,7 +67,7 @@ describe('cross stack', () => { }); // THEN: it shouldn't throw due to cyclic dependencies - expect(stack2).toHaveResource('AWS::ECS::Service'); + Template.fromStack(stack2).resourceCountIs('AWS::ECS::Service', 1); expectIngress(stack2); @@ -84,7 +84,7 @@ describe('cross stack', () => { }); // THEN: it shouldn't throw due to cyclic dependencies - expect(stack2).toHaveResource('AWS::ECS::Service'); + Template.fromStack(stack2).resourceCountIs('AWS::ECS::Service', 1); expectIngress(stack2); @@ -92,7 +92,7 @@ describe('cross stack', () => { }); function expectIngress(stack: Stack) { - expect(stack).toHaveResource('AWS::EC2::SecurityGroupIngress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupIngress', { FromPort: 32768, ToPort: 65535, GroupId: { 'Fn::ImportValue': 'Stack1:ExportsOutputFnGetAttDefaultAutoScalingGroupInstanceSecurityGroupFBA881D0GroupId2F7C804A' }, diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/ec2-service.test.ts b/packages/@aws-cdk/aws-ecs/test/ec2/ec2-service.test.ts index 7e1f5532fc207..85c5d68568b22 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/ec2-service.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/ec2/ec2-service.test.ts @@ -1,5 +1,4 @@ -import { SynthUtils } from '@aws-cdk/assert-internal'; -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as autoscaling from '@aws-cdk/aws-autoscaling'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as elb from '@aws-cdk/aws-elasticloadbalancing'; @@ -36,7 +35,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { TaskDefinition: { Ref: 'Ec2TaskDef0226F28C', }, @@ -77,7 +76,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { TaskDefinition: { Ref: 'Ec2TaskDef0226F28C', }, @@ -94,7 +93,7 @@ describe('ec2 service', () => { EnableExecuteCommand: true, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -168,7 +167,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -231,7 +230,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -351,7 +350,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -442,7 +441,7 @@ describe('ec2 service', () => { ], }); - expect(stack).toHaveResource('AWS::KMS::Key', { + Template.fromStack(stack).hasResourceProperties('AWS::KMS::Key', { KeyPolicy: { Statement: [ { @@ -557,7 +556,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -663,7 +662,7 @@ describe('ec2 service', () => { ], }); - expect(stack).toHaveResource('AWS::KMS::Key', { + Template.fromStack(stack).hasResourceProperties('AWS::KMS::Key', { KeyPolicy: { Statement: [ { @@ -807,7 +806,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -835,7 +834,7 @@ describe('ec2 service', () => { }, }); - expect(stack).toHaveResource('AWS::ServiceDiscovery::PrivateDnsNamespace', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::PrivateDnsNamespace', { Name: 'scorekeep.com', Vpc: { Ref: 'MyVpcF9F0CA6F', @@ -898,7 +897,7 @@ describe('ec2 service', () => { service.addPlacementStrategies(PlacementStrategy.spreadAcross(ecs.BuiltInAttributes.AVAILABILITY_ZONE)); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { TaskDefinition: { Ref: 'Ec2TaskDef0226F28C', }, @@ -1004,7 +1003,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { CapacityProviderStrategy: [ { CapacityProvider: { @@ -1055,7 +1054,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { TaskDefinition: { Ref: 'Ec2TaskDef0226F28C', }, @@ -1095,7 +1094,7 @@ describe('ec2 service', () => { ServiceName: 'bonjour', }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroup', { GroupDescription: 'Example', GroupName: 'Bingo', SecurityGroupEgress: [ @@ -1110,7 +1109,7 @@ describe('ec2 service', () => { }, }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroup', { GroupDescription: 'Example', GroupName: 'Rolly', SecurityGroupEgress: [ @@ -1223,7 +1222,7 @@ describe('ec2 service', () => { // THEN expect(service.node.metadataEntry[0].data).toEqual('taskDefinition and launchType are blanked out when using external deployment controller.'); - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { Cluster: { Ref: 'EcsCluster97242B84', }, @@ -1329,7 +1328,7 @@ describe('ec2 service', () => { // THEN expect(() => { - SynthUtils.synthesize(stack); + Template.fromStack(stack); }).toThrow(/one essential container/); @@ -1355,15 +1354,13 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Name: 'main', - }, + }), ], }); - - }); test('sets daemon scheduling strategy', () => { @@ -1386,7 +1383,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { SchedulingStrategy: 'DAEMON', DeploymentConfiguration: { MaximumPercent: 100, @@ -1572,7 +1569,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { NetworkConfiguration: { AwsvpcConfiguration: { AssignPublicIp: 'DISABLED', @@ -1647,7 +1644,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { PlacementConstraints: [{ Type: 'distinctInstance', }], @@ -1677,7 +1674,7 @@ describe('ec2 service', () => { service.addPlacementConstraints(PlacementConstraint.memberOf('attribute:ecs.instance-type =~ t2.*')); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { PlacementConstraints: [{ Expression: 'attribute:ecs.instance-type =~ t2.*', Type: 'memberOf', @@ -1709,7 +1706,7 @@ describe('ec2 service', () => { service.addPlacementStrategies(PlacementStrategy.spreadAcrossInstances()); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { PlacementStrategies: [{ Field: 'instanceId', Type: 'spread', @@ -1740,7 +1737,7 @@ describe('ec2 service', () => { service.addPlacementStrategies(PlacementStrategy.spreadAcross(ecs.BuiltInAttributes.AVAILABILITY_ZONE)); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { PlacementStrategies: [{ Field: 'attribute:ecs.availability-zone', Type: 'spread', @@ -1841,11 +1838,9 @@ describe('ec2 service', () => { }); // THEN - expect(stack).not.toHaveResource('AWS::ECS::Service', { - PlacementConstraints: undefined, + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { + PlacementConstraints: Match.absent(), }); - - }); testDeprecated('with both propagateTags and propagateTaskTagsFrom defined', () => { @@ -1892,11 +1887,9 @@ describe('ec2 service', () => { }); // THEN - expect(stack).not.toHaveResource('AWS::ECS::Service', { - PlacementStrategies: undefined, + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { + PlacementStrategies: Match.absent(), }); - - }); test('with random placement strategy', () => { @@ -1920,7 +1913,7 @@ describe('ec2 service', () => { service.addPlacementStrategies(PlacementStrategy.randomly()); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { PlacementStrategies: [{ Type: 'random', }], @@ -1977,7 +1970,7 @@ describe('ec2 service', () => { service.addPlacementStrategies(PlacementStrategy.packedByCpu()); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { PlacementStrategies: [{ Field: 'cpu', Type: 'binpack', @@ -2008,7 +2001,7 @@ describe('ec2 service', () => { service.addPlacementStrategies(PlacementStrategy.packedByMemory()); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { PlacementStrategies: [{ Field: 'memory', Type: 'binpack', @@ -2039,7 +2032,7 @@ describe('ec2 service', () => { service.addPlacementStrategies(PlacementStrategy.packedBy(ecs.BinPackResource.MEMORY)); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { PlacementStrategies: [{ Field: 'memory', Type: 'binpack', @@ -2272,13 +2265,13 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::EC2::SecurityGroupIngress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupIngress', { Description: 'Load balancer to target', FromPort: 32768, ToPort: 65535, }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupEgress', { Description: 'Load balancer to target', FromPort: 32768, ToPort: 65535, @@ -2320,13 +2313,13 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::EC2::SecurityGroupIngress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupIngress', { Description: 'Load balancer to target', FromPort: 80, ToPort: 80, }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupEgress', { Description: 'Load balancer to target', FromPort: 80, ToPort: 80, @@ -2367,13 +2360,13 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::EC2::SecurityGroupIngress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupIngress', { Description: 'Load balancer to target', FromPort: 8001, ToPort: 8001, }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupEgress', { Description: 'Load balancer to target', FromPort: 8001, ToPort: 8001, @@ -2413,13 +2406,13 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::EC2::SecurityGroupIngress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupIngress', { Description: 'Load balancer to target', FromPort: 8001, ToPort: 8001, }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupEgress', { Description: 'Load balancer to target', FromPort: 8001, ToPort: 8001, @@ -2513,7 +2506,7 @@ describe('ec2 service', () => { lb.addTarget(service); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'web', @@ -2523,7 +2516,7 @@ describe('ec2 service', () => { ], }); - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { // if any load balancer is configured and healthCheckGracePeriodSeconds is not // set, then it should default to 60 seconds. HealthCheckGracePeriodSeconds: 60, @@ -2558,7 +2551,7 @@ describe('ec2 service', () => { })); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'web', @@ -2663,7 +2656,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { ServiceRegistries: [ { ContainerName: 'MainContainer', @@ -2678,7 +2671,7 @@ describe('ec2 service', () => { ], }); - expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -2740,7 +2733,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { ServiceRegistries: [ { ContainerName: 'MainContainer', @@ -2755,7 +2748,7 @@ describe('ec2 service', () => { ], }); - expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -2851,7 +2844,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { ServiceRegistries: [ { RegistryArn: { @@ -2864,7 +2857,7 @@ describe('ec2 service', () => { ], }); - expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -2927,7 +2920,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { ServiceRegistries: [ { ContainerName: 'MainContainer', @@ -2942,7 +2935,7 @@ describe('ec2 service', () => { ], }); - expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -3011,7 +3004,7 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { ServiceRegistries: [ { RegistryArn: { 'Fn::GetAtt': ['ServiceCloudmapService046058A4', 'Arn'] }, @@ -3020,8 +3013,6 @@ describe('ec2 service', () => { }, ], }); - - }); test('By default, the container name is the default', () => { @@ -3056,14 +3047,12 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::Service', { - ServiceRegistries: [{ + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { + ServiceRegistries: [Match.objectLike({ ContainerName: 'main', - ContainerPort: undefined, - }], + ContainerPort: Match.anyValue(), + })], }); - - }); test('For SRV, by default, container name is default container and port is the default container port', () => { @@ -3100,14 +3089,12 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::Service', { - ServiceRegistries: [{ + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { + ServiceRegistries: [Match.objectLike({ ContainerName: 'main', ContainerPort: 1234, - }], + })], }); - - }); test('allows SRV service discovery to select the container and port', () => { @@ -3147,14 +3134,12 @@ describe('ec2 service', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::Service', { - ServiceRegistries: [{ + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { + ServiceRegistries: [Match.objectLike({ ContainerName: 'second', ContainerPort: 4321, - }], + })], }); - - }); test('throws if SRV and container is not part of task definition', () => { diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/ec2-task-definition.test.ts b/packages/@aws-cdk/aws-ecs/test/ec2/ec2-task-definition.test.ts index 9217e68a412c5..27e10173bbfec 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/ec2-task-definition.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/ec2/ec2-task-definition.test.ts @@ -1,5 +1,5 @@ -import '@aws-cdk/assert-internal/jest'; import * as path from 'path'; +import { Match, Template } from '@aws-cdk/assertions'; import { Protocol } from '@aws-cdk/aws-ec2'; import { Repository } from '@aws-cdk/aws-ecr'; import * as iam from '@aws-cdk/aws-iam'; @@ -18,14 +18,13 @@ describe('ec2 task definition', () => { new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', NetworkMode: ecs.NetworkMode.BRIDGE, RequiresCompatibilities: ['EC2'], }); // test error if no container defs? - }); test('with all properties set', () => { @@ -56,7 +55,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ExecutionRoleArn: { 'Fn::GetAtt': [ 'ExecutionRole605A040B', @@ -104,7 +103,7 @@ describe('ec2 task definition', () => { taskDefinition.addPlacementConstraint(ecs.PlacementConstraint.memberOf('attribute:ecs.instance-type =~ t2.*')); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { PlacementConstraints: [ { Expression: 'attribute:ecs.instance-type =~ t2.*', @@ -125,7 +124,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { NetworkMode: ecs.NetworkMode.AWS_VPC, }); @@ -140,7 +139,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { IpcMode: ecs.IpcMode.TASK, }); @@ -155,7 +154,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { PidMode: ecs.PidMode.HOST, }); @@ -194,7 +193,7 @@ describe('ec2 task definition', () => { })); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', ContainerDefinitions: [{ Essential: true, @@ -222,7 +221,7 @@ describe('ec2 task definition', () => { }], }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Version: '2012-10-17', Statement: [ @@ -288,7 +287,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', ContainerDefinitions: [ { @@ -461,7 +460,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECR::Repository', { + Template.fromStack(stack).hasResourceProperties('AWS::ECR::Repository', { LifecyclePolicy: { // eslint-disable-next-line max-len LifecyclePolicyText: '{"rules":[{"rulePriority":10,"selection":{"tagStatus":"tagged","tagPrefixList":["abc"],"countType":"imageCountMoreThan","countNumber":1},"action":{"type":"expire"}}]}', @@ -470,7 +469,7 @@ describe('ec2 task definition', () => { RepositoryName: 'project-a/amazon-ecs-sample', }); - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', ContainerDefinitions: [{ Essential: true, @@ -543,7 +542,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [{ Essential: true, Memory: 512, @@ -613,7 +612,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [{ Essential: true, Memory: 512, @@ -684,7 +683,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECR::Repository', {}); + Template.fromStack(stack).hasResourceProperties('AWS::ECR::Repository', {}); }); @@ -739,7 +738,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'StackEc2TaskDefF03698CF', ContainerDefinitions: [ { @@ -806,9 +805,9 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', - ContainerDefinitions: [{ + ContainerDefinitions: [Match.objectLike({ MountPoints: [ { ContainerPath: './cache', @@ -816,7 +815,7 @@ describe('ec2 task definition', () => { SourceVolume: 'scratch', }, ], - }], + })], Volumes: [{ Host: { SourcePath: '/tmp/cache', @@ -824,9 +823,8 @@ describe('ec2 task definition', () => { Name: 'scratch', }], }); - - }); + test('correctly sets container dependenices', () => { // GIVEN const stack = new cdk.Stack(); @@ -857,15 +855,15 @@ describe('ec2 task definition', () => { ); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', - ContainerDefinitions: [{ + ContainerDefinitions: [Match.objectLike({ Name: 'dependency1', - }, - { + }), + Match.objectLike({ Name: 'dependency2', - }, - { + }), + Match.objectLike({ Name: 'web', DependsOn: [{ Condition: 'HEALTHY', @@ -875,7 +873,7 @@ describe('ec2 task definition', () => { Condition: 'SUCCESS', ContainerName: 'dependency2', }], - }], + })], }); @@ -906,25 +904,23 @@ describe('ec2 task definition', () => { container.addLink(linkedContainer2); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Links: [ 'linked1:linked', 'linked2', ], Name: 'web', - }, - { + }), + Match.objectLike({ Name: 'linked1', - }, - { + }), + Match.objectLike({ Name: 'linked2', - }, + }), ], }); - - }); test('correctly set policy statement to the task IAM role', () => { @@ -939,7 +935,7 @@ describe('ec2 task definition', () => { })); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Version: '2012-10-17', Statement: [ @@ -951,9 +947,8 @@ describe('ec2 task definition', () => { ], }, }); - - }); + test('correctly sets volumes from', () => { const stack = new cdk.Stack(); @@ -970,18 +965,16 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { - ContainerDefinitions: [{ + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [Match.objectLike({ VolumesFrom: [ { SourceContainer: 'SourceContainer', ReadOnly: true, }, ], - }], + })], }); - - }); test('correctly set policy statement to the task execution IAM role', () => { @@ -996,7 +989,7 @@ describe('ec2 task definition', () => { })); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Version: '2012-10-17', Statement: [ @@ -1040,9 +1033,9 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', - ContainerDefinitions: [{ + ContainerDefinitions: [Match.objectLike({ MountPoints: [ { ContainerPath: './cache', @@ -1050,7 +1043,7 @@ describe('ec2 task definition', () => { SourceVolume: 'scratch', }, ], - }], + })], Volumes: [{ Host: { SourcePath: '/tmp/cache', @@ -1058,8 +1051,6 @@ describe('ec2 task definition', () => { Name: 'scratch', }], }); - - }); test('correctly sets placement constraints', () => { @@ -1077,7 +1068,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { PlacementConstraints: [ { Expression: 'attribute:ecs.instance-type =~ t2.*', @@ -1104,7 +1095,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { TaskRoleArn: stack.resolve(taskDefinition.taskRole.roleArn), }); @@ -1117,7 +1108,7 @@ describe('ec2 task definition', () => { const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { TaskRoleArn: stack.resolve(taskDefinition.taskRole.roleArn), }); @@ -1148,7 +1139,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', Volumes: [{ Name: 'scratch', @@ -1185,7 +1176,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', Volumes: [{ Name: 'scratch', @@ -1219,7 +1210,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', InferenceAccelerators: [{ DeviceName: 'device1', @@ -1252,7 +1243,7 @@ describe('ec2 task definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'Ec2TaskDef', InferenceAccelerators: [{ DeviceName: 'device1', diff --git a/packages/@aws-cdk/aws-ecs/test/environment-file.test.ts b/packages/@aws-cdk/aws-ecs/test/environment-file.test.ts index 815973a80e602..abc64332a326b 100644 --- a/packages/@aws-cdk/aws-ecs/test/environment-file.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/environment-file.test.ts @@ -1,4 +1,3 @@ -import '@aws-cdk/assert-internal/jest'; import * as path from 'path'; import * as cdk from '@aws-cdk/core'; import * as ecs from '../lib'; diff --git a/packages/@aws-cdk/aws-ecs/test/external/external-service.test.ts b/packages/@aws-cdk/aws-ecs/test/external/external-service.test.ts index b4a3edf73ea0d..69626f7473fb0 100644 --- a/packages/@aws-cdk/aws-ecs/test/external/external-service.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/external/external-service.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as autoscaling from '@aws-cdk/aws-autoscaling'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2'; @@ -29,7 +29,7 @@ describe('external service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { TaskDefinition: { Ref: 'ExternalTaskDef6CCBDB87', }, @@ -79,7 +79,7 @@ describe('external service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { TaskDefinition: { Ref: 'ExternalTaskDef6CCBDB87', }, @@ -165,7 +165,7 @@ describe('external service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { TaskDefinition: { Ref: 'ExternalTaskDef6CCBDB87', }, @@ -177,7 +177,7 @@ describe('external service', () => { ServiceName: 'bonjour', }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroup', { GroupDescription: 'Example', GroupName: 'Bingo', SecurityGroupEgress: [ @@ -189,7 +189,7 @@ describe('external service', () => { ], }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroup', { GroupDescription: 'Example', GroupName: 'Rolly', SecurityGroupEgress: [ diff --git a/packages/@aws-cdk/aws-ecs/test/external/external-task-definition.test.ts b/packages/@aws-cdk/aws-ecs/test/external/external-task-definition.test.ts index 3b692f73fe8cf..7963ea0cfa6a1 100644 --- a/packages/@aws-cdk/aws-ecs/test/external/external-task-definition.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/external/external-task-definition.test.ts @@ -1,5 +1,5 @@ -import '@aws-cdk/assert-internal/jest'; import * as path from 'path'; +import { Template } from '@aws-cdk/assertions'; import { Protocol } from '@aws-cdk/aws-ec2'; import { Repository } from '@aws-cdk/aws-ecr'; import * as iam from '@aws-cdk/aws-iam'; @@ -16,13 +16,11 @@ describe('external task definition', () => { new ecs.ExternalTaskDefinition(stack, 'ExternalTaskDef'); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'ExternalTaskDef', NetworkMode: ecs.NetworkMode.BRIDGE, RequiresCompatibilities: ['EXTERNAL'], }); - - }); test('with all properties set', () => { @@ -43,7 +41,7 @@ describe('external task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ExecutionRoleArn: { 'Fn::GetAtt': [ 'ExecutionRole605A040B', @@ -93,7 +91,7 @@ describe('external task definition', () => { })); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'ExternalTaskDef', NetworkMode: ecs.NetworkMode.BRIDGE, RequiresCompatibilities: ['EXTERNAL'], @@ -117,7 +115,7 @@ describe('external task definition', () => { }], }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Version: '2012-10-17', Statement: [ @@ -180,7 +178,7 @@ describe('external task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'ExternalTaskDef', NetworkMode: ecs.NetworkMode.BRIDGE, RequiresCompatibilities: ['EXTERNAL'], @@ -353,7 +351,7 @@ describe('external task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECR::Repository', { + Template.fromStack(stack).hasResourceProperties('AWS::ECR::Repository', { LifecyclePolicy: { // eslint-disable-next-line max-len LifecyclePolicyText: '{"rules":[{"rulePriority":10,"selection":{"tagStatus":"tagged","tagPrefixList":["abc"],"countType":"imageCountMoreThan","countNumber":1},"action":{"type":"expire"}}]}', @@ -362,7 +360,7 @@ describe('external task definition', () => { RepositoryName: 'project-a/amazon-ecs-sample', }); - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'ExternalTaskDef', NetworkMode: ecs.NetworkMode.BRIDGE, RequiresCompatibilities: ['EXTERNAL'], @@ -437,7 +435,7 @@ describe('external task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'ExternalTaskDef', NetworkMode: ecs.NetworkMode.BRIDGE, RequiresCompatibilities: ['EXTERNAL'], @@ -510,7 +508,7 @@ describe('external task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'ExternalTaskDef', NetworkMode: ecs.NetworkMode.BRIDGE, RequiresCompatibilities: ['EXTERNAL'], @@ -585,7 +583,7 @@ describe('external task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECR::Repository', {}); + Template.fromStack(stack).hasResourceProperties('AWS::ECR::Repository', {}); }); diff --git a/packages/@aws-cdk/aws-ecs/test/fargate/fargate-service.test.ts b/packages/@aws-cdk/aws-ecs/test/fargate/fargate-service.test.ts index a8dbb29c98b10..3780c43903284 100644 --- a/packages/@aws-cdk/aws-ecs/test/fargate/fargate-service.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/fargate/fargate-service.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { ABSENT, SynthUtils } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as appscaling from '@aws-cdk/aws-applicationautoscaling'; import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; import * as ec2 from '@aws-cdk/aws-ec2'; @@ -34,7 +33,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { TaskDefinition: { Ref: 'FargateTaskDefC6FB60B4', }, @@ -70,7 +69,7 @@ describe('fargate service', () => { }, }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroup', { GroupDescription: 'Default/FargateService/SecurityGroup', SecurityGroupEgress: [ { @@ -149,15 +148,15 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Cluster', { - CapacityProviders: ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Cluster', { + CapacityProviders: Match.absent(), }); - expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE', 'FARGATE_SPOT'], }); - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { TaskDefinition: { Ref: 'FargateTaskDefC6FB60B4', }, @@ -239,15 +238,15 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Cluster', { - CapacityProviders: ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Cluster', { + CapacityProviders: Match.absent(), }); - expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE', 'FARGATE_SPOT'], }); - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { TaskDefinition: { Ref: 'FargateTaskDefC6FB60B4', }, @@ -259,7 +258,7 @@ describe('fargate service', () => { MinimumHealthyPercent: 50, }, // no launch type - LaunchType: ABSENT, + LaunchType: Match.absent(), CapacityProviderStrategy: [ { CapacityProvider: 'FARGATE_SPOT', @@ -326,7 +325,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -354,7 +353,7 @@ describe('fargate service', () => { }, }); - expect(stack).toHaveResource('AWS::ServiceDiscovery::PrivateDnsNamespace', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::PrivateDnsNamespace', { Name: 'scorekeep.com', Vpc: { Ref: 'MyVpcF9F0CA6F', @@ -401,7 +400,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { ServiceRegistries: [ { ContainerName: 'web', @@ -507,7 +506,7 @@ describe('fargate service', () => { // THEN expect(svc.cloudMapService).toBeDefined(); - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { TaskDefinition: { Ref: 'FargateTaskDefC6FB60B4', }, @@ -634,7 +633,7 @@ describe('fargate service', () => { // THEN expect(service.node.metadataEntry[0].data).toEqual('taskDefinition and launchType are blanked out when using external deployment controller.'); - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { Cluster: { Ref: 'EcsCluster97242B84', }, @@ -687,7 +686,7 @@ describe('fargate service', () => { // THEN expect(() => { - SynthUtils.synthesize(stack); + Template.fromStack(stack); }).toThrow(/one essential container/); @@ -711,15 +710,13 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Name: 'main', - }, + }), ], }); - - }); test('allows specifying assignPublicIP as enabled', () => { @@ -740,7 +737,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { NetworkConfiguration: { AwsvpcConfiguration: { AssignPublicIp: 'ENABLED', @@ -769,7 +766,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { DeploymentConfiguration: { MinimumHealthyPercent: 0, }, @@ -844,7 +841,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { TaskDefinition: { Ref: 'FargateTaskDefC6FB60B4', }, @@ -886,7 +883,7 @@ describe('fargate service', () => { }, }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroup', { GroupDescription: 'Example', GroupName: 'Bingo', SecurityGroupEgress: [ @@ -901,7 +898,7 @@ describe('fargate service', () => { }, }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroup', { GroupDescription: 'Example', GroupName: 'Rolly', SecurityGroupEgress: [ @@ -942,7 +939,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { HealthCheckGracePeriodSeconds: 10, }); @@ -978,7 +975,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', { MaxCapacity: 10, MinCapacity: 1, ResourceId: { @@ -1001,7 +998,7 @@ describe('fargate service', () => { }, }); - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', { TargetTrackingScalingPolicyConfiguration: { PredefinedMetricSpecification: { PredefinedMetricType: 'ALBRequestCountPerTarget', @@ -1018,7 +1015,7 @@ describe('fargate service', () => { }, }); - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { // if any load balancer is configured and healthCheckGracePeriodSeconds is not // set, then it should default to 60 seconds. HealthCheckGracePeriodSeconds: 60, @@ -1058,7 +1055,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', { MaxCapacity: 10, MinCapacity: 1, ResourceId: { @@ -1113,7 +1110,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1125,13 +1122,13 @@ describe('fargate service', () => { ], }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroupIngress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupIngress', { Description: 'Load balancer to target', FromPort: 8000, ToPort: 8000, }); - expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupEgress', { Description: 'Load balancer to target', FromPort: 8000, ToPort: 8000, @@ -1347,7 +1344,7 @@ describe('fargate service', () => { ); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1359,7 +1356,7 @@ describe('fargate service', () => { ], }); - expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', { Port: 80, Protocol: 'HTTP', }); @@ -1399,7 +1396,7 @@ describe('fargate service', () => { ); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1411,7 +1408,7 @@ describe('fargate service', () => { ], }); - expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', { Port: 80, Protocol: 'HTTP', }); @@ -1451,7 +1448,7 @@ describe('fargate service', () => { ); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1463,7 +1460,7 @@ describe('fargate service', () => { ], }); - expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', { Port: 443, Protocol: 'HTTPS', }); @@ -1504,7 +1501,7 @@ describe('fargate service', () => { ); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1516,7 +1513,7 @@ describe('fargate service', () => { ], }); - expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', { Port: 83, Protocol: 'HTTP', }); @@ -1556,7 +1553,7 @@ describe('fargate service', () => { ); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1568,7 +1565,7 @@ describe('fargate service', () => { ], }); - expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', { Port: 80, Protocol: 'TCP', }); @@ -1608,7 +1605,7 @@ describe('fargate service', () => { ); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1620,7 +1617,7 @@ describe('fargate service', () => { ], }); - expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', { Port: 81, Protocol: 'TCP', }); @@ -1655,7 +1652,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', { ScheduledActions: [ { ScalableTargetAction: { @@ -1698,7 +1695,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', { PolicyType: 'StepScaling', ScalingTargetId: { Ref: 'ServiceTaskCountTarget23E25614', @@ -1741,7 +1738,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', { PolicyType: 'TargetTrackingScaling', TargetTrackingScalingPolicyConfiguration: { PredefinedMetricSpecification: { PredefinedMetricType: 'ECSServiceAverageCPUUtilization' }, @@ -1775,7 +1772,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', { PolicyType: 'TargetTrackingScaling', TargetTrackingScalingPolicyConfiguration: { PredefinedMetricSpecification: { PredefinedMetricType: 'ECSServiceAverageMemoryUtilization' }, @@ -1810,7 +1807,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', { PolicyType: 'TargetTrackingScaling', TargetTrackingScalingPolicyConfiguration: { CustomizedMetricSpecification: { @@ -1878,7 +1875,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -1939,7 +1936,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -2001,7 +1998,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -2065,7 +2062,7 @@ describe('fargate service', () => { }, }); - expect(stack).toHaveResourceLike('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { ServiceRegistries: [ { RegistryArn: { 'Fn::GetAtt': ['ServiceCloudmapService046058A4', 'Arn'] }, @@ -2168,7 +2165,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { DeploymentConfiguration: { MaximumPercent: 200, MinimumHealthyPercent: 50, @@ -2233,7 +2230,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::Service', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { TaskDefinition: { Ref: 'FargateTaskDefC6FB60B4', }, @@ -2270,7 +2267,7 @@ describe('fargate service', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2344,7 +2341,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2407,7 +2404,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2527,7 +2524,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2618,7 +2615,7 @@ describe('fargate service', () => { ], }); - expect(stack).toHaveResource('AWS::KMS::Key', { + Template.fromStack(stack).hasResourceProperties('AWS::KMS::Key', { KeyPolicy: { Statement: [ { @@ -2733,7 +2730,7 @@ describe('fargate service', () => { }); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2839,7 +2836,7 @@ describe('fargate service', () => { ], }); - expect(stack).toHaveResource('AWS::KMS::Key', { + Template.fromStack(stack).hasResourceProperties('AWS::KMS::Key', { KeyPolicy: { Statement: [ { diff --git a/packages/@aws-cdk/aws-ecs/test/fargate/fargate-task-definition.test.ts b/packages/@aws-cdk/aws-ecs/test/fargate/fargate-task-definition.test.ts index 1f42e09cf83ac..e0b7afca3389f 100644 --- a/packages/@aws-cdk/aws-ecs/test/fargate/fargate-task-definition.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/fargate/fargate-task-definition.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; import * as ecs from '../../lib'; @@ -11,7 +11,7 @@ describe('fargate task definition', () => { new ecs.FargateTaskDefinition(stack, 'FargateTaskDef'); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Family: 'FargateTaskDef', NetworkMode: ecs.NetworkMode.AWS_VPC, RequiresCompatibilities: ['FARGATE'], @@ -32,7 +32,7 @@ describe('fargate task definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Cpu: '128', Memory: '1024', }); @@ -72,7 +72,7 @@ describe('fargate task definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Cpu: '128', ExecutionRoleArn: { 'Fn::GetAtt': [ @@ -265,7 +265,7 @@ describe('fargate task definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Cpu: '1024', Family: 'FargateTaskDef', Memory: '2048', @@ -299,7 +299,7 @@ describe('fargate task definition', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { Cpu: '1024', Family: 'FargateTaskDef', Memory: '2048', diff --git a/packages/@aws-cdk/aws-ecs/test/firelens-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/firelens-log-driver.test.ts index 6ab96b05df364..547382ab8d3de 100644 --- a/packages/@aws-cdk/aws-ecs/test/firelens-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/firelens-log-driver.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as secretsmanager from '@aws-cdk/aws-secretsmanager'; import * as ssm from '@aws-cdk/aws-ssm'; import * as cdk from '@aws-cdk/core'; @@ -24,23 +24,21 @@ describe('firelens log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'awsfirelens', }, - }, - { + }), + Match.objectLike({ Essential: true, FirelensConfiguration: { Type: 'fluentbit', }, - }, + }), ], }); - - }); test('create a firelens log driver with secret options', () => { @@ -71,9 +69,9 @@ describe('firelens log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'awsfirelens', Options: { @@ -116,19 +114,19 @@ describe('firelens log driver', () => { }, ], }, - }, - { + }), + Match.objectLike({ Essential: true, FirelensConfiguration: { Type: 'fluentbit', }, - }, + }), ], }); - expect(stack).toHaveResourceLike('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { - Statement: [ + Statement: Match.arrayWith([ { Action: [ 'secretsmanager:GetSecretValue', @@ -168,12 +166,10 @@ describe('firelens log driver', () => { ], }, }, - ], + ]), Version: '2012-10-17', }, }); - - }); test('create a firelens log driver to route logs to CloudWatch Logs with Fluent Bit', () => { @@ -193,9 +189,9 @@ describe('firelens log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'awsfirelens', Options: { @@ -206,17 +202,15 @@ describe('firelens log driver', () => { log_stream_prefix: 'from-fluent-bit', }, }, - }, - { + }), + Match.objectLike({ Essential: true, FirelensConfiguration: { Type: 'fluentbit', }, - }, + }), ], }); - - }); test('create a firelens log driver to route logs to kinesis firehose Logs with Fluent Bit', () => { @@ -234,9 +228,9 @@ describe('firelens log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'awsfirelens', Options: { @@ -245,17 +239,15 @@ describe('firelens log driver', () => { delivery_stream: 'my-stream', }, }, - }, - { + }), + Match.objectLike({ Essential: true, FirelensConfiguration: { Type: 'fluentbit', }, - }, + }), ], }); - - }); describe('Firelens Configuration', () => { @@ -270,7 +262,7 @@ describe('firelens log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { Essential: true, @@ -283,7 +275,6 @@ describe('firelens log driver', () => { }, ], }); - }); test('fluent-bit log router container with options', () => { @@ -304,9 +295,9 @@ describe('firelens log driver', () => { }); // THEN - expect(stack2).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack2).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Essential: true, MemoryReservation: 50, Name: 'log_router', @@ -318,11 +309,9 @@ describe('firelens log driver', () => { 'config-file-value': 'arn:aws:s3:::mybucket/fluent.conf', }, }, - }, + }), ], }); - - }); test('fluent-bit log router with file config type', () => { @@ -342,9 +331,9 @@ describe('firelens log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Essential: true, MemoryReservation: 50, Name: 'log_router', @@ -356,11 +345,9 @@ describe('firelens log driver', () => { 'config-file-value': '/my/working/dir/firelens/config', }, }, - }, + }), ], }); - - }); }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/fluentd-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/fluentd-log-driver.test.ts index 81c17b8c0b76f..7bd81fed41221 100644 --- a/packages/@aws-cdk/aws-ecs/test/fluentd-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/fluentd-log-driver.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as cdk from '@aws-cdk/core'; import * as ecs from '../lib'; @@ -10,8 +10,6 @@ describe('fluentd log driver', () => { beforeEach(() => { stack = new cdk.Stack(); td = new ecs.Ec2TaskDefinition(stack, 'TaskDefinition'); - - }); test('create a fluentd log driver with options', () => { @@ -25,20 +23,18 @@ describe('fluentd log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'fluentd', Options: { tag: 'hello', }, }, - }, + }), ], }); - - }); test('create a fluentd log driver without options', () => { @@ -50,17 +46,15 @@ describe('fluentd log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'fluentd', }, - }, + }), ], }); - - }); test('create a fluentd log driver with all possible options', () => { @@ -91,9 +85,9 @@ describe('fluentd log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'fluentd', Options: { @@ -109,11 +103,9 @@ describe('fluentd log driver', () => { 'env-regex': '[0-9]{1}', }, }, - }, + }), ], }); - - }); test('create a fluentd log driver using fluentd', () => { @@ -125,16 +117,14 @@ describe('fluentd log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'fluentd', }, - }, + }), ], }); - - }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/gelf-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/gelf-log-driver.test.ts index e8cdce10736e1..f6800bb48ac01 100644 --- a/packages/@aws-cdk/aws-ecs/test/gelf-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/gelf-log-driver.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as cdk from '@aws-cdk/core'; import * as ecs from '../lib'; @@ -25,20 +25,18 @@ describe('gelf log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'gelf', Options: { 'gelf-address': 'my-gelf-address', }, }, - }, + }), ], }); - - }); test('create a gelf log driver using gelf with minimum options', () => { @@ -52,19 +50,17 @@ describe('gelf log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'gelf', Options: { 'gelf-address': 'my-gelf-address', }, }, - }, + }), ], }); - - }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/images/tag-parameter-container-image.test.ts b/packages/@aws-cdk/aws-ecs/test/images/tag-parameter-container-image.test.ts index 3f409739d76ed..9ff3023b1e965 100644 --- a/packages/@aws-cdk/aws-ecs/test/images/tag-parameter-container-image.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/images/tag-parameter-container-image.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { SynthUtils } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as ecr from '@aws-cdk/aws-ecr'; import * as cdk from '@aws-cdk/core'; import * as ecs from '../../lib'; @@ -16,10 +15,8 @@ describe('tag parameter container image', () => { }); expect(() => { - SynthUtils.synthesize(stack); + Template.fromStack(stack); }).toThrow(/TagParameterContainerImage must be used in a container definition when using tagParameterName/); - - }); test('throws an error when tagParameterValue() is used without binding the image', () => { @@ -32,10 +29,8 @@ describe('tag parameter container image', () => { }); expect(() => { - SynthUtils.synthesize(stack); + Template.fromStack(stack); }).toThrow(/TagParameterContainerImage must be used in a container definition when using tagParameterValue/); - - }); test('can be used in a cross-account manner', () => { @@ -67,7 +62,7 @@ describe('tag parameter container image', () => { }); // THEN - expect(pipelineStack).toHaveResourceLike('AWS::ECR::Repository', { + Template.fromStack(pipelineStack).hasResourceProperties('AWS::ECR::Repository', { RepositoryName: repositoryName, RepositoryPolicyText: { Statement: [{ @@ -89,12 +84,12 @@ describe('tag parameter container image', () => { }], }, }); - expect(serviceStack).toHaveResourceLike('AWS::IAM::Role', { + Template.fromStack(serviceStack).hasResourceProperties('AWS::IAM::Role', { RoleName: 'servicestackionexecutionrolee7e2d9a783a54eb795f4', }); - expect(serviceStack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(serviceStack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ Image: { 'Fn::Join': ['', [ { @@ -126,11 +121,9 @@ describe('tag parameter container image', () => { { Ref: 'ServiceTaskDefinitionContainerImageTagParamCEC9D0BA' }, ]], }, - }, + }), ], }); - - }); }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/journald-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/journald-log-driver.test.ts index fdf67efc3bb4f..b3f25650b9e58 100644 --- a/packages/@aws-cdk/aws-ecs/test/journald-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/journald-log-driver.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as cdk from '@aws-cdk/core'; import * as ecs from '../lib'; @@ -10,8 +10,6 @@ describe('journald log driver', () => { beforeEach(() => { stack = new cdk.Stack(); td = new ecs.Ec2TaskDefinition(stack, 'TaskDefinition'); - - }); test('create a journald log driver with options', () => { @@ -25,20 +23,18 @@ describe('journald log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'journald', Options: { tag: 'hello', }, }, - }, + }), ], }); - - }); test('create a journald log driver without options', () => { @@ -50,17 +46,15 @@ describe('journald log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'journald', }, - }, + }), ], }); - - }); test('create a journald log driver using journald', () => { @@ -72,17 +66,15 @@ describe('journald log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'journald', Options: {}, }, - }, + }), ], }); - - }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/json-file-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/json-file-log-driver.test.ts index 0c21ff2d0b5f1..ed2622dc79eaa 100644 --- a/packages/@aws-cdk/aws-ecs/test/json-file-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/json-file-log-driver.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as cdk from '@aws-cdk/core'; import * as ecs from '../lib'; @@ -25,20 +25,18 @@ describe('json file log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'json-file', Options: { env: 'hello', }, }, - }, + }), ], }); - - }); test('create a json-file log driver without options', () => { @@ -50,17 +48,15 @@ describe('json file log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'json-file', }, - }, + }), ], }); - - }); test('create a json-file log driver using json-file', () => { @@ -72,17 +68,15 @@ describe('json file log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'json-file', Options: {}, }, - }, + }), ], }); - - }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/splunk-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/splunk-log-driver.test.ts index cb7678d9bc6e4..b33b4155615a4 100644 --- a/packages/@aws-cdk/aws-ecs/test/splunk-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/splunk-log-driver.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as secretsmanager from '@aws-cdk/aws-secretsmanager'; import * as ssm from '@aws-cdk/aws-ssm'; import * as cdk from '@aws-cdk/core'; @@ -28,9 +28,9 @@ describe('splunk log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'splunk', Options: { @@ -45,11 +45,9 @@ describe('splunk log driver', () => { }, }], }, - }, + }), ], }); - - }); test('create a splunk log driver using splunk with minimum options', () => { @@ -64,9 +62,9 @@ describe('splunk log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'splunk', Options: { @@ -81,11 +79,9 @@ describe('splunk log driver', () => { }, }], }, - }, + }), ], }); - - }); test('create a splunk log driver using splunk with sourcetype defined', () => { @@ -101,9 +97,9 @@ describe('splunk log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'splunk', Options: { @@ -119,11 +115,9 @@ describe('splunk log driver', () => { }, }], }, - }, + }), ], }); - - }); test('create a splunk log driver using secret splunk token from a new secret', () => { @@ -139,9 +133,9 @@ describe('splunk log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'splunk', Options: { @@ -156,11 +150,9 @@ describe('splunk log driver', () => { }, ], }, - }, + }), ], }); - - }); test('create a splunk log driver using secret splunk token from systems manager parameter store', () => { @@ -179,9 +171,9 @@ describe('splunk log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'splunk', Options: { @@ -213,11 +205,9 @@ describe('splunk log driver', () => { }, ], }, - }, + }), ], }); - - }); test('throws when neither token nor secret token are provided', () => { @@ -230,7 +220,5 @@ describe('splunk log driver', () => { memoryLimitMiB: 128, }); }).toThrow('Please provide either token or secretToken.'); - - }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/syslog-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/syslog-log-driver.test.ts index ae32f55ecd863..fa77acb52e09b 100644 --- a/packages/@aws-cdk/aws-ecs/test/syslog-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/syslog-log-driver.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as cdk from '@aws-cdk/core'; import * as ecs from '../lib'; @@ -10,8 +10,6 @@ describe('syslog log driver', () => { beforeEach(() => { stack = new cdk.Stack(); td = new ecs.Ec2TaskDefinition(stack, 'TaskDefinition'); - - }); test('create a syslog log driver with options', () => { @@ -25,20 +23,18 @@ describe('syslog log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'syslog', Options: { tag: 'hello', }, }, - }, + }), ], }); - - }); test('create a syslog log driver without options', () => { @@ -50,17 +46,15 @@ describe('syslog log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'syslog', }, - }, + }), ], }); - - }); test('create a syslog log driver using syslog', () => { @@ -72,17 +66,15 @@ describe('syslog log driver', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ - { + Match.objectLike({ LogConfiguration: { LogDriver: 'syslog', Options: {}, }, - }, + }), ], }); - - }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/task-definition.test.ts b/packages/@aws-cdk/aws-ecs/test/task-definition.test.ts index 07b3a8211da06..11e383565af81 100644 --- a/packages/@aws-cdk/aws-ecs/test/task-definition.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/task-definition.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; import * as ecs from '../lib'; @@ -17,7 +17,7 @@ describe('task definition', () => { }); // THEN - expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { NetworkMode: 'awsvpc', });