Skip to content

Commit

Permalink
Merge branch 'master' into assert-find
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Sep 16, 2021
2 parents 0f409cb + ae4aa95 commit cbf3d7b
Show file tree
Hide file tree
Showing 89 changed files with 3,973 additions and 3,130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ nyc.config.js
!.eslintrc.js

junit.xml

!jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ tsconfig.json
**/cdk.out
junit.xml

test/
test/
jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/jest.config');
module.exports = {
...baseConfig,
coverageThreshold: {
global: {
branches: 70,
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
"organization": true
},
"license": "Apache-2.0",
"cdk-build": {
"jest": true
},
"devDependencies": {
"@types/nodeunit": "^0.0.32",
"@types/jest": "^26.0.24",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
"jest": "^26.6.3",
"nodeunit": "^0.11.3",
"pkglint": "0.0.0",
"@aws-cdk/assert-internal": "0.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { expect, haveResource, haveResourceLike } from '@aws-cdk/assert-internal';
import '@aws-cdk/assert-internal/jest';
import * as appmesh from '@aws-cdk/aws-appmesh';
import * as ecs from '@aws-cdk/aws-ecs';
import * as cdk from '@aws-cdk/core';

import { Test } from 'nodeunit';
import { AppMeshExtension, Container, Environment, ScaleOnCpuUtilization, ServiceDescription, Service } from '../lib';

export = {
'should be able to add AWS App Mesh to a service'(test: Test) {
describe('appmesh', () => {
test('should be able to add AWS App Mesh to a service', () => {
// GIVEN
const stack = new cdk.Stack();

Expand Down Expand Up @@ -37,7 +35,7 @@ export = {
// THEN

// Ensure that task has an App Mesh sidecar
expect(stack).to(haveResource('AWS::ECS::TaskDefinition', {
expect(stack).toHaveResource('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
{
Cpu: 256,
Expand Down Expand Up @@ -210,10 +208,10 @@ export = {
'Arn',
],
},
}));
});

// Ensure that the service has the right settings
expect(stack).to(haveResource('AWS::ECS::Service', {
expect(stack).toHaveResource('AWS::ECS::Service', {
Cluster: {
Ref: 'productionenvironmentclusterC6599D2D',
},
Expand Down Expand Up @@ -258,12 +256,12 @@ export = {
TaskDefinition: {
Ref: 'myservicetaskdefinitionF3E2D86F',
},
}));
});


test.done();
},
});

'should have the right maximumPercentage at desired count == 1'(test: Test) {
test('should have the right maximumPercentage at desired count == 1', () => {
// GIVEN
const stack = new cdk.Stack();

Expand Down Expand Up @@ -293,18 +291,18 @@ export = {
serviceDescription,
});

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


test.done();
},
});

'should have the right maximumPercentage at desired count == 2'(test: Test) {
test('should have the right maximumPercentage at desired count == 2', () => {
// GIVEN
const stack = new cdk.Stack();

Expand Down Expand Up @@ -334,18 +332,18 @@ export = {
serviceDescription,
});

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


test.done();
},
});

'should have the right maximumPercentage at desired count == 3'(test: Test) {
test('should have the right maximumPercentage at desired count == 3', () => {
// GIVEN
const stack = new cdk.Stack();

Expand Down Expand Up @@ -375,18 +373,18 @@ export = {
serviceDescription,
});

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


test.done();
},
});

'should have the right maximumPercentage at desired count == 4'(test: Test) {
test('should have the right maximumPercentage at desired count == 4', () => {
// GIVEN
const stack = new cdk.Stack();

Expand Down Expand Up @@ -416,18 +414,18 @@ export = {
serviceDescription,
});

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


test.done();
},
});

'should have the right maximumPercentage at desired count > 4'(test: Test) {
test('should have the right maximumPercentage at desired count > 4', () => {
// GIVEN
const stack = new cdk.Stack();

Expand Down Expand Up @@ -457,18 +455,18 @@ export = {
serviceDescription,
});

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


test.done();
},
});

'should be able to create multiple App Mesh enabled services and connect'(test: Test) {
test('should be able to create multiple App Mesh enabled services and connect', () => {
// GIVEN
const stack = new cdk.Stack();

Expand Down Expand Up @@ -529,12 +527,12 @@ export = {
greeterService.connectTo(greetingService);

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

test.done();
},

'should detect when attempting to connect services from two different envs'(test: Test) {
});

test('should detect when attempting to connect services from two different envs', () => {
// GIVEN
const stack = new cdk.Stack();

Expand Down Expand Up @@ -582,10 +580,10 @@ export = {
});

// THEN
test.throws(() => {
expect(() => {
developmentNameService.connectTo(productionNameService);
}, /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/);
}).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/);


test.done();
},
};
});
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { expect, haveResourceLike } from '@aws-cdk/assert-internal';
import '@aws-cdk/assert-internal/jest';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import * as route53 from '@aws-cdk/aws-route53';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { AssignPublicIpExtension, Container, Environment, EnvironmentCapacityType, Service, ServiceDescription } from '../lib';
import { TaskRecordManager } from '../lib/extensions/assign-public-ip/task-record-manager';

export = {
'should assign a public ip to fargate tasks'(test: Test) {
describe('assign public ip', () => {
test('should assign a public ip to fargate tasks', () => {
// GIVEN
const stack = new cdk.Stack();

Expand All @@ -29,18 +28,18 @@ export = {
});

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


test.done();
},
});

'errors when adding a public ip to ec2-backed service'(test: Test) {
test('errors when adding a public ip to ec2-backed service', () => {
// GIVEN
const stack = new cdk.Stack();

Expand All @@ -66,17 +65,17 @@ export = {
serviceDescription.add(new AssignPublicIpExtension());

// WHEN / THEN
test.throws(() => {
expect(() => {
new Service(stack, 'my-service', {
environment,
serviceDescription,
});
}, /Fargate/i);
}).toThrow(/Fargate/i);

test.done();
},

'should not add a task record manager by default'(test: Test) {
});

test('should not add a task record manager by default', () => {
// GIVEN
const stack = new cdk.Stack();

Expand All @@ -98,12 +97,12 @@ export = {
});

// THEN
test.strictEqual(service.ecsService.node.tryFindChild('TaskRecordManager'), undefined, 'task record manager should not be present');
expect(service.ecsService.node.tryFindChild('TaskRecordManager')).toBeUndefined();


test.done();
},
});

'should add a task record manager when dns is requested'(test: Test) {
test('should add a task record manager when dns is requested', () => {
// GIVEN
const stack = new cdk.Stack();
const dnsZone = new route53.PublicHostedZone(stack, 'zone', {
Expand Down Expand Up @@ -133,12 +132,12 @@ export = {
});

// THEN
test.notEqual(service.ecsService.node.tryFindChild('TaskRecordManager'), undefined, 'task record manager should be present');
expect(service.ecsService.node.tryFindChild('TaskRecordManager')).toBeDefined();


test.done();
},
});

'task record manager listens for ecs events'(test: Test) {
test('task record manager listens for ecs events', () => {
// GIVEN
const stack = new cdk.Stack();
const dnsZone = new route53.PublicHostedZone(stack, 'zone', {
Expand Down Expand Up @@ -168,7 +167,7 @@ export = {
});

// THEN
expect(stack).to(haveResourceLike('AWS::Events::Rule', {
expect(stack).toHaveResourceLike('AWS::Events::Rule', {
EventPattern: {
'source': ['aws.ecs'],
'detail-type': [
Expand All @@ -179,9 +178,9 @@ export = {
desiredStatus: ['RUNNING'],
},
},
}));
});

expect(stack).to(haveResourceLike('AWS::Events::Rule', {
expect(stack).toHaveResourceLike('AWS::Events::Rule', {
EventPattern: {
'source': ['aws.ecs'],
'detail-type': [
Expand All @@ -192,8 +191,8 @@ export = {
desiredStatus: ['STOPPED'],
},
},
}));
});


test.done();
},
}
});
});
Loading

0 comments on commit cbf3d7b

Please sign in to comment.