Skip to content

Commit

Permalink
chore(codedeploy): migrate tests to use the Assertions module (aws#18585
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
skinny85 authored and LukvonStrom committed Jan 26, 2022
1 parent f551154 commit 6aab081
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 65 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codedeploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert-internal": "0.0.0",
"@aws-cdk/assertions": "0.0.0",
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cdk-integ-tools": "0.0.0",
"@aws-cdk/cfn2ts": "0.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-codedeploy/test/ecs/application.test.ts
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 codedeploy from '../../lib';

Expand All @@ -7,7 +7,7 @@ describe('CodeDeploy ECS Application', () => {
const stack = new cdk.Stack();
new codedeploy.EcsApplication(stack, 'MyApp');

expect(stack).toHaveResource('AWS::CodeDeploy::Application', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::Application', {
ComputePlatform: 'ECS',
});
});
Expand All @@ -18,7 +18,7 @@ describe('CodeDeploy ECS Application', () => {
applicationName: 'my-name',
});

expect(stack).toHaveResource('AWS::CodeDeploy::Application', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::Application', {
ApplicationName: 'my-name',
ComputePlatform: 'ECS',
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import '@aws-cdk/assert-internal/jest';
import { Template } from '@aws-cdk/assertions';
import * as cdk from '@aws-cdk/core';
import * as codedeploy from '../../lib';

describe('CodeDeploy Lambda Application', () => {
test('can be created', () => {
const stack = new cdk.Stack();
new codedeploy.LambdaApplication(stack, 'MyApp');
expect(stack).toHaveResource('AWS::CodeDeploy::Application', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::Application', {
ComputePlatform: 'Lambda',
});
});
Expand All @@ -16,7 +16,7 @@ describe('CodeDeploy Lambda Application', () => {
new codedeploy.LambdaApplication(stack, 'MyApp', {
applicationName: 'my-name',
});
expect(stack).toHaveResource('AWS::CodeDeploy::Application', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::Application', {
ApplicationName: 'my-name',
ComputePlatform: 'Lambda',
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ResourcePart } from '@aws-cdk/assert-internal';
import '@aws-cdk/assert-internal/jest';
import { Template } from '@aws-cdk/assertions';
import * as lambda from '@aws-cdk/aws-lambda';
import * as cdk from '@aws-cdk/core';
import * as codedeploy from '../../lib';
Expand Down Expand Up @@ -45,7 +44,7 @@ test('custom resource created', () => {
});

// THEN
expect(stack).toHaveResourceLike('Custom::AWS', {
Template.fromStack(stack).hasResourceProperties('Custom::AWS', {
ServiceToken: {
'Fn::GetAtt': [
'AWS679f53fac002430cb0da5b7982bd22872D164C4C',
Expand All @@ -57,7 +56,7 @@ test('custom resource created', () => {
Delete: '{"service":"CodeDeploy","action":"deleteDeploymentConfig","parameters":{"deploymentConfigName":"CustomConfig.LambdaCanary5Percent1Minutes"}}',
});

expect(stack).toHaveResource('AWS::IAM::Policy', {
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [
{
Expand Down Expand Up @@ -91,7 +90,7 @@ test('custom resource created with specific name', () => {
});

// THEN
expect(stack).toHaveResourceLike('Custom::AWS', {
Template.fromStack(stack).hasResourceProperties('Custom::AWS', {
Create: '{"service":"CodeDeploy","action":"createDeploymentConfig","parameters":{"deploymentConfigName":"MyDeploymentConfig","computePlatform":"Lambda","trafficRoutingConfig":{"type":"TimeBasedCanary","timeBasedCanary":{"canaryInterval":"1","canaryPercentage":"5"}}},"physicalResourceId":{"id":"MyDeploymentConfig"}}',
Update: '{"service":"CodeDeploy","action":"createDeploymentConfig","parameters":{"deploymentConfigName":"MyDeploymentConfig","computePlatform":"Lambda","trafficRoutingConfig":{"type":"TimeBasedCanary","timeBasedCanary":{"canaryInterval":"1","canaryPercentage":"5"}}},"physicalResourceId":{"id":"MyDeploymentConfig"}}',
Delete: '{"service":"CodeDeploy","action":"deleteDeploymentConfig","parameters":{"deploymentConfigName":"MyDeploymentConfig"}}',
Expand All @@ -112,7 +111,7 @@ test('can create linear custom config', () => {
});

// THEN
expect(stack).toHaveResourceLike('AWS::CodeDeploy::DeploymentGroup', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
DeploymentConfigName: 'CustomConfig.LambdaLinear5PercentEvery1Minutes',
});
});
Expand All @@ -131,7 +130,7 @@ test('can create canary custom config', () => {
});

// THEN
expect(stack).toHaveResourceLike('AWS::CodeDeploy::DeploymentGroup', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
DeploymentConfigName: 'CustomConfig.LambdaCanary5Percent1Minutes',
});
});
Expand All @@ -150,13 +149,13 @@ test('dependency on the config exists to ensure ordering', () => {
});

// THEN
expect(stack).toHaveResourceLike('AWS::CodeDeploy::DeploymentGroup', {
Template.fromStack(stack).hasResource('AWS::CodeDeploy::DeploymentGroup', {
Properties: {
DeploymentConfigName: 'CustomConfig.LambdaCanary5Percent1Minutes',
},
DependsOn: [
'CustomConfigDeploymentConfigCustomResourcePolicy0426B684',
'CustomConfigDeploymentConfigE9E1F384',
],
}, ResourcePart.CompleteDefinition);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ResourcePart } from '@aws-cdk/assert-internal';
import '@aws-cdk/assert-internal/jest';
import { Template } from '@aws-cdk/assertions';
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
import * as iam from '@aws-cdk/aws-iam';
import * as lambda from '@aws-cdk/aws-lambda';
Expand Down Expand Up @@ -33,7 +32,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
deploymentConfig: codedeploy.LambdaDeploymentConfig.ALL_AT_ONCE,
});

expect(stack).toHaveResource('AWS::CodeDeploy::DeploymentGroup', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
ApplicationName: {
Ref: 'MyApp3CE31C26',
},
Expand All @@ -56,7 +55,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
},
});

expect(stack).toHaveResource('AWS::Lambda::Alias', {
Template.fromStack(stack).hasResource('AWS::Lambda::Alias', {
Type: 'AWS::Lambda::Alias',
Properties: {
FunctionName: {
Expand All @@ -80,9 +79,9 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
},
},
},
}, ResourcePart.CompleteDefinition);
});

expect(stack).toHaveResource('AWS::IAM::Role', {
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', {
AssumeRolePolicyDocument: {
Statement: [{
Action: 'sts:AssumeRole',
Expand Down Expand Up @@ -120,7 +119,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
deploymentGroupName: 'test',
});

expect(stack).toHaveResourceLike('AWS::CodeDeploy::DeploymentGroup', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
DeploymentGroupName: 'test',
});
});
Expand All @@ -140,7 +139,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
role: serviceRole,
});

expect(stack).toHaveResource('AWS::IAM::Role', {
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', {
AssumeRolePolicyDocument: {
Statement: [{
Action: 'sts:AssumeRole',
Expand Down Expand Up @@ -176,7 +175,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
deploymentConfig: codedeploy.LambdaDeploymentConfig.LINEAR_10PERCENT_EVERY_1MINUTE,
});

expect(stack).toHaveResource('AWS::CodeDeploy::DeploymentGroup', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
ApplicationName: {
Ref: 'MyApp3CE31C26',
},
Expand Down Expand Up @@ -216,7 +215,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
})],
});

expect(stack).toHaveResourceLike('AWS::CodeDeploy::DeploymentGroup', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
AlarmConfiguration: {
Alarms: [{
Name: {
Expand Down Expand Up @@ -268,7 +267,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
deploymentConfig: codedeploy.LambdaDeploymentConfig.ALL_AT_ONCE,
});

expect(stack).toHaveResourceLike('AWS::Lambda::Alias', {
Template.fromStack(stack).hasResource('AWS::Lambda::Alias', {
UpdatePolicy: {
CodeDeployLambdaAliasUpdate: {
ApplicationName: {
Expand All @@ -282,9 +281,9 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
},
},
},
}, ResourcePart.CompleteDefinition);
});

expect(stack).toHaveResource('AWS::IAM::Policy', {
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
PolicyName: 'MyDGServiceRoleDefaultPolicy65E8E1EA',
Roles: [{
Ref: 'MyDGServiceRole5E94FD88',
Expand Down Expand Up @@ -316,7 +315,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
});
group.addPreHook(mockFunction(stack, 'PreHook'));

expect(stack).toHaveResourceLike('AWS::Lambda::Alias', {
Template.fromStack(stack).hasResource('AWS::Lambda::Alias', {
UpdatePolicy: {
CodeDeployLambdaAliasUpdate: {
ApplicationName: {
Expand All @@ -330,9 +329,9 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
},
},
},
}, ResourcePart.CompleteDefinition);
});

expect(stack).toHaveResource('AWS::IAM::Policy', {
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
PolicyName: 'MyDGServiceRoleDefaultPolicy65E8E1EA',
Roles: [{
Ref: 'MyDGServiceRole5E94FD88',
Expand Down Expand Up @@ -364,7 +363,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
deploymentConfig: codedeploy.LambdaDeploymentConfig.ALL_AT_ONCE,
});

expect(stack).toHaveResourceLike('AWS::Lambda::Alias', {
Template.fromStack(stack).hasResource('AWS::Lambda::Alias', {
UpdatePolicy: {
CodeDeployLambdaAliasUpdate: {
ApplicationName: {
Expand All @@ -378,9 +377,9 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
},
},
},
}, ResourcePart.CompleteDefinition);
});

expect(stack).toHaveResource('AWS::IAM::Policy', {
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
PolicyName: 'MyDGServiceRoleDefaultPolicy65E8E1EA',
Roles: [{
Ref: 'MyDGServiceRole5E94FD88',
Expand Down Expand Up @@ -412,7 +411,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
});
group.addPostHook(mockFunction(stack, 'PostHook'));

expect(stack).toHaveResourceLike('AWS::Lambda::Alias', {
Template.fromStack(stack).hasResource('AWS::Lambda::Alias', {
UpdatePolicy: {
CodeDeployLambdaAliasUpdate: {
ApplicationName: {
Expand All @@ -426,9 +425,9 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
},
},
},
}, ResourcePart.CompleteDefinition);
});

expect(stack).toHaveResource('AWS::IAM::Policy', {
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
PolicyName: 'MyDGServiceRoleDefaultPolicy65E8E1EA',
Roles: [{
Ref: 'MyDGServiceRole5E94FD88',
Expand Down Expand Up @@ -467,7 +466,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
})],
});

expect(stack).toHaveResourceLike('AWS::CodeDeploy::DeploymentGroup', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
AlarmConfiguration: {
Alarms: [{
Name: {
Expand All @@ -494,7 +493,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
},
});

expect(stack).toHaveResource('AWS::CodeDeploy::DeploymentGroup', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
ApplicationName: {
Ref: 'MyApp3CE31C26',
},
Expand Down Expand Up @@ -526,7 +525,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
},
});

expect(stack).toHaveResourceLike('AWS::CodeDeploy::DeploymentGroup', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
AutoRollbackConfiguration: {
Enabled: true,
Events: [
Expand Down Expand Up @@ -557,7 +556,7 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
})],
});

expect(stack).toHaveResourceLike('AWS::CodeDeploy::DeploymentGroup', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
AutoRollbackConfiguration: {
Enabled: true,
Events: [
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 codedeploy from '../../lib';

Expand All @@ -12,7 +12,7 @@ describe('CodeDeploy DeploymentConfig', () => {
minimumHealthyHosts: codedeploy.MinimumHealthyHosts.count(1),
});

expect(stack).toHaveResource('AWS::CodeDeploy::DeploymentConfig', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentConfig', {
'MinimumHealthyHosts': {
'Type': 'HOST_COUNT',
'Value': 1,
Expand All @@ -27,7 +27,7 @@ describe('CodeDeploy DeploymentConfig', () => {
minimumHealthyHosts: codedeploy.MinimumHealthyHosts.percentage(75),
});

expect(stack).toHaveResource('AWS::CodeDeploy::DeploymentConfig', {
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentConfig', {
'MinimumHealthyHosts': {
'Type': 'FLEET_PERCENT',
'Value': 75,
Expand Down
Loading

0 comments on commit 6aab081

Please sign in to comment.