Skip to content

Commit

Permalink
chore(ecs-service-extensions): migrate tests to assertions (aws#18649)
Browse files Browse the repository at this point in the history
`assert-internal` is [about to be] deprecated, so we are migrating all cdk modules to assertions.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kaizencc authored and TikiTDO committed Feb 21, 2022
1 parent ea85cac commit e194901
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@aws-cdk/cfn2ts": "0.0.0",
"jest": "^27.4.7",
"@aws-cdk/pkglint": "0.0.0",
"@aws-cdk/assert-internal": "0.0.0"
"@aws-cdk/assertions": "0.0.0"
},
"dependencies": {
"@aws-cdk/aws-applicationautoscaling": "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 { Match, Template } from '@aws-cdk/assertions';
import * as appmesh from '@aws-cdk/aws-appmesh';
import * as ecs from '@aws-cdk/aws-ecs';
import * as cdk from '@aws-cdk/core';
Expand Down Expand Up @@ -34,7 +34,7 @@ describe('appmesh', () => {

// THEN
// Ensure that task has an App Mesh sidecar
expect(stack).toHaveResource('AWS::ECS::TaskDefinition', {
Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
{
Cpu: 256,
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('appmesh', () => {
});

// Ensure that the service has the right settings
expect(stack).toHaveResource('AWS::ECS::Service', {
Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', {
Cluster: {
Ref: 'productionenvironmentclusterC6599D2D',
},
Expand Down Expand Up @@ -256,8 +256,6 @@ describe('appmesh', () => {
Ref: 'myservicetaskdefinitionF3E2D86F',
},
});


});

test('should have the right maximumPercentage at desired count == 1', () => {
Expand Down Expand Up @@ -288,15 +286,13 @@ describe('appmesh', () => {
desiredCount: 1,
});

expect(stack).toHaveResourceLike('AWS::ECS::Service', {
Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', {
DeploymentConfiguration: {
MaximumPercent: 200,
MinimumHealthyPercent: 100,
},
DesiredCount: 1,
});


});

test('should have the right maximumPercentage at desired count == 2', () => {
Expand Down Expand Up @@ -327,15 +323,13 @@ describe('appmesh', () => {
desiredCount: 2,
});

expect(stack).toHaveResourceLike('AWS::ECS::Service', {
Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', {
DeploymentConfiguration: {
MaximumPercent: 150,
MinimumHealthyPercent: 100,
},
DesiredCount: 2,
});


});

test('should have the right maximumPercentage at desired count == 3', () => {
Expand Down Expand Up @@ -366,15 +360,13 @@ describe('appmesh', () => {
desiredCount: 3,
});

expect(stack).toHaveResourceLike('AWS::ECS::Service', {
Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', {
DeploymentConfiguration: {
MaximumPercent: 150,
MinimumHealthyPercent: 100,
},
DesiredCount: 3,
});


});

test('should have the right maximumPercentage at desired count == 4', () => {
Expand Down Expand Up @@ -405,15 +397,13 @@ describe('appmesh', () => {
desiredCount: 4,
});

expect(stack).toHaveResourceLike('AWS::ECS::Service', {
Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', {
DeploymentConfiguration: {
MaximumPercent: 125,
MinimumHealthyPercent: 100,
},
DesiredCount: 4,
});


});

test('should have the right maximumPercentage at desired count > 4', () => {
Expand Down Expand Up @@ -444,15 +434,13 @@ describe('appmesh', () => {
desiredCount: 8,
});

expect(stack).toHaveResourceLike('AWS::ECS::Service', {
Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', {
DeploymentConfiguration: {
MaximumPercent: 125,
MinimumHealthyPercent: 100,
},
DesiredCount: 8,
});


});

test('should be able to create multiple App Mesh enabled services and connect', () => {
Expand Down Expand Up @@ -516,9 +504,7 @@ describe('appmesh', () => {
greeterService.connectTo(greetingService);

// THEN
expect(stack).toHaveResource('AWS::ECS::TaskDefinition');


Template.fromStack(stack).hasResource('AWS::ECS::TaskDefinition', Match.anyValue());
});

test('should detect when attempting to connect services from two different envs', () => {
Expand Down Expand Up @@ -572,7 +558,5 @@ describe('appmesh', () => {
expect(() => {
developmentNameService.connectTo(productionNameService);
}).toThrow(/Unable to connect service 'name-development' in environment 'development' to service 'name-production' in environment 'production' because services can not be connected across environment boundaries/);


});
});
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 autoscaling from '@aws-cdk/aws-autoscaling';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
Expand Down Expand Up @@ -29,15 +29,13 @@ describe('assign public ip', () => {
});

// THEN
expect(stack).toHaveResourceLike('AWS::ECS::Service', {
Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', {
NetworkConfiguration: {
AwsvpcConfiguration: {
AssignPublicIp: 'ENABLED',
},
},
});


});

test('errors when adding a public ip to ec2-backed service', () => {
Expand Down Expand Up @@ -76,8 +74,6 @@ describe('assign public ip', () => {
serviceDescription,
});
}).toThrow(/Fargate/i);


});

test('should not add a task record manager by default', () => {
Expand All @@ -103,8 +99,6 @@ describe('assign public ip', () => {

// THEN
expect(service.ecsService.node.tryFindChild('TaskRecordManager')).toBeUndefined();


});

test('should add a task record manager when dns is requested', () => {
Expand Down Expand Up @@ -138,8 +132,6 @@ describe('assign public ip', () => {

// THEN
expect(service.ecsService.node.tryFindChild('TaskRecordManager')).toBeDefined();


});

test('task record manager listens for ecs events', () => {
Expand Down Expand Up @@ -172,7 +164,7 @@ describe('assign public ip', () => {
});

// THEN
expect(stack).toHaveResourceLike('AWS::Events::Rule', {
Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', {
EventPattern: {
'source': ['aws.ecs'],
'detail-type': [
Expand All @@ -185,7 +177,7 @@ describe('assign public ip', () => {
},
});

expect(stack).toHaveResourceLike('AWS::Events::Rule', {
Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', {
EventPattern: {
'source': ['aws.ecs'],
'detail-type': [
Expand All @@ -197,7 +189,5 @@ describe('assign public ip', () => {
},
},
});


});
});
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 ecs from '@aws-cdk/aws-ecs';
import * as cdk from '@aws-cdk/core';
import { CloudwatchAgentExtension, Container, Environment, Service, ServiceDescription } from '../lib';
Expand Down Expand Up @@ -27,7 +27,7 @@ describe('cloudwatch agent', () => {
});

// THEN
expect(stack).toHaveResource('AWS::ECS::TaskDefinition', {
Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
{
Cpu: 256,
Expand Down Expand Up @@ -102,8 +102,5 @@ describe('cloudwatch agent', () => {
],
},
});


});

});
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 autoscaling from '@aws-cdk/aws-autoscaling';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
Expand Down Expand Up @@ -46,9 +46,9 @@ describe('container', () => {
});

// THEN
expect(stack).toCountResources('AWS::ECS::Service', 1);
Template.fromStack(stack).resourceCountIs('AWS::ECS::Service', 1);

expect(stack).toHaveResource('AWS::ECS::TaskDefinition', {
Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
{
Cpu: 256,
Expand Down Expand Up @@ -86,8 +86,6 @@ describe('container', () => {
],
},
});


});

test('should be able to enable default logging behavior - with enable default log driver feature flag', () => {
Expand Down Expand Up @@ -129,12 +127,12 @@ describe('container', () => {
});

// THEN
expect(stack).toCountResources('AWS::ECS::Service', 1);
Template.fromStack(stack).resourceCountIs('AWS::ECS::Service', 1);

// Ensure that the log group was created
expect(stack).toHaveResource('AWS::Logs::LogGroup');
Template.fromStack(stack).resourceCountIs('AWS::Logs::LogGroup', 1);

expect(stack).toHaveResource('AWS::ECS::TaskDefinition', {
Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
{
Cpu: 256,
Expand Down Expand Up @@ -184,8 +182,6 @@ describe('container', () => {
],
},
});


});

test('should be able to add user-provided log group in the log driver options', () => {
Expand Down Expand Up @@ -228,12 +224,12 @@ describe('container', () => {
});

// THEN
expect(stack).toCountResources('AWS::ECS::Service', 1);
Template.fromStack(stack).resourceCountIs('AWS::ECS::Service', 1);

// Ensure that the log group was created
expect(stack).toHaveResource('AWS::Logs::LogGroup');
Template.fromStack(stack).resourceCountIs('AWS::Logs::LogGroup', 1);

expect(stack).toHaveResource('AWS::ECS::TaskDefinition', {
Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
{
Cpu: 256,
Expand Down Expand Up @@ -283,8 +279,6 @@ describe('container', () => {
],
},
});


});

test('should error when log group is provided in the container extension and another observability extension is added', () => {
Expand Down Expand Up @@ -312,5 +306,4 @@ describe('container', () => {
});
}).toThrow(/Log configuration already specified. You cannot provide a log group for the application container of service 'my-service' while also adding log configuration separately using service extensions./);
});

});
Loading

0 comments on commit e194901

Please sign in to comment.