Skip to content

Commit

Permalink
chore(ecs): migrate to Assertions (aws#18516)
Browse files Browse the repository at this point in the history
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
madeline-k authored and TikiTDO committed Feb 21, 2022
1 parent 6183dbe commit c7444a7
Show file tree
Hide file tree
Showing 22 changed files with 517 additions and 674 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down
45 changes: 18 additions & 27 deletions packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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: {
Expand All @@ -47,11 +47,9 @@ describe('aws log driver', () => {
'mode': 'non-blocking',
},
},
},
}),
],
});


});

test('create an aws log driver using awsLogs', () => {
Expand All @@ -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: {
Expand All @@ -84,11 +82,9 @@ describe('aws log driver', () => {
'awslogs-multiline-pattern': 'pattern',
},
},
},
}),
],
});


});

test('with a defined log group', () => {
Expand All @@ -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: {
Expand All @@ -120,11 +116,9 @@ describe('aws log driver', () => {
'awslogs-region': { Ref: 'AWS::Region' },
},
},
},
}),
],
});


});

test('without a defined log group: creates one anyway', () => {
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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: {
Expand All @@ -184,9 +176,8 @@ describe('aws log driver', () => {
'awslogs-region': logGroupRegion,
},
},
},
}),
],
});
});

});
Loading

0 comments on commit c7444a7

Please sign in to comment.