From f3b1ec860bf2a9cd3047064ab155a91d1474b2ae Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Tue, 28 Dec 2021 13:50:02 -0500 Subject: [PATCH 1/9] chore(chatbot): migrate tests to assertions --- packages/@aws-cdk/aws-chatbot/package.json | 2 +- .../test/slack-channel-configuration.test.ts | 29 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/packages/@aws-cdk/aws-chatbot/package.json b/packages/@aws-cdk/aws-chatbot/package.json index efe5c1e39ad75..0a2c84c8216f6 100644 --- a/packages/@aws-cdk/aws-chatbot/package.json +++ b/packages/@aws-cdk/aws-chatbot/package.json @@ -74,7 +74,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", diff --git a/packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts b/packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts index a5d2b443ed486..9918dba29a1a1 100644 --- a/packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts +++ b/packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts @@ -1,5 +1,4 @@ -import { ABSENT } from '@aws-cdk/assert-internal'; -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; import * as iam from '@aws-cdk/aws-iam'; import * as logs from '@aws-cdk/aws-logs'; @@ -21,7 +20,7 @@ describe('SlackChannelConfiguration', () => { slackChannelConfigurationName: 'Test', }); - expect(stack).toHaveResourceLike('AWS::Chatbot::SlackChannelConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::Chatbot::SlackChannelConfiguration', { ConfigurationName: 'Test', IamRoleArn: { 'Fn::GetAtt': [ @@ -33,7 +32,7 @@ describe('SlackChannelConfiguration', () => { SlackWorkspaceId: 'ABC123', }); - expect(stack).toHaveResourceLike('AWS::IAM::Role', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: [ { @@ -57,7 +56,7 @@ describe('SlackChannelConfiguration', () => { loggingLevel: chatbot.LoggingLevel.ERROR, }); - expect(stack).toHaveResourceLike('AWS::Chatbot::SlackChannelConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::Chatbot::SlackChannelConfiguration', { ConfigurationName: 'Test', IamRoleArn: { 'Fn::GetAtt': [ @@ -81,7 +80,7 @@ describe('SlackChannelConfiguration', () => { notificationTopics: [topic], }); - expect(stack).toHaveResourceLike('AWS::Chatbot::SlackChannelConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::Chatbot::SlackChannelConfiguration', { ConfigurationName: 'Test', IamRoleArn: { 'Fn::GetAtt': [ @@ -109,7 +108,7 @@ describe('SlackChannelConfiguration', () => { const topic = new sns.Topic(stack, 'MyTopic'); slackChannel.addNotificationTopic(topic); - expect(stack).toHaveResourceLike('AWS::Chatbot::SlackChannelConfiguration', { + Template.fromStack(stack).hasResourceProperties('AWS::Chatbot::SlackChannelConfiguration', { ConfigurationName: 'Test', SnsTopicArns: [ { @@ -129,7 +128,7 @@ describe('SlackChannelConfiguration', () => { role: role, }); - expect(stack).toCountResources('AWS::IAM::Role', 0); + Template.fromStack(stack).resourceCountIs('AWS::IAM::Role', 0); }); test('created with new role and extra iam policies', () => { @@ -147,7 +146,7 @@ describe('SlackChannelConfiguration', () => { resources: ['arn:aws:s3:::abc/xyz/123.txt'], })); - expect(stack).toHaveResourceLike('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -169,7 +168,7 @@ describe('SlackChannelConfiguration', () => { logRetention: logs.RetentionDays.ONE_MONTH, }); - expect(stack).toHaveResourceLike('Custom::LogRetention', { + Template.fromStack(stack).hasResourceProperties('Custom::LogRetention', { LogGroupName: '/aws/chatbot/ConfigurationName', RetentionInDays: 30, LogGroupRegion: 'us-east-1', @@ -199,7 +198,7 @@ describe('SlackChannelConfiguration', () => { }, metricName: 'MetricName', })); - expect(stack).toHaveResourceLike('AWS::CloudWatch::Alarm', { + Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { Namespace: 'AWS/Chatbot', MetricName: 'MetricName', Dimensions: [ @@ -228,10 +227,10 @@ describe('SlackChannelConfiguration', () => { region: 'us-east-1', metricName: 'MetricName', })); - expect(stack).toHaveResourceLike('AWS::CloudWatch::Alarm', { + Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { Namespace: 'AWS/Chatbot', MetricName: 'MetricName', - Dimensions: ABSENT, + Dimensions: Match.absent(), ComparisonOperator: 'GreaterThanThreshold', EvaluationPeriods: 1, Threshold: 0, @@ -249,8 +248,8 @@ describe('SlackChannelConfiguration', () => { resources: ['arn:aws:s3:::abc/xyz/123.txt'], })); - expect(stack).toCountResources('AWS::IAM::Role', 0); - expect(stack).toCountResources('AWS::IAM::Policy', 0); + Template.fromStack(stack).resourceCountIs('AWS::IAM::Role', 0); + Template.fromStack(stack).resourceCountIs('AWS::IAM::Policy', 0); }); test('should throw error if ARN invalid', () => { From 4dcb6a92ea8b6f7caa0668117462a212ac55eb27 Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Tue, 28 Dec 2021 14:08:16 -0500 Subject: [PATCH 2/9] chore(opensearch): migrate tests to assertions --- .../aws-opensearchservice/package.json | 2 +- .../aws-opensearchservice/test/domain.test.ts | 157 +++++++++--------- .../test/log-group-resource-policy.test.ts | 4 +- .../test/opensearch-access-policy.test.ts | 6 +- 4 files changed, 84 insertions(+), 85 deletions(-) diff --git a/packages/@aws-cdk/aws-opensearchservice/package.json b/packages/@aws-cdk/aws-opensearchservice/package.json index cb7bea7e5e0b4..7a4133a720c22 100644 --- a/packages/@aws-cdk/aws-opensearchservice/package.json +++ b/packages/@aws-cdk/aws-opensearchservice/package.json @@ -84,7 +84,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", diff --git a/packages/@aws-cdk/aws-opensearchservice/test/domain.test.ts b/packages/@aws-cdk/aws-opensearchservice/test/domain.test.ts index 2389c30ab7c29..3739031d6f3b2 100644 --- a/packages/@aws-cdk/aws-opensearchservice/test/domain.test.ts +++ b/packages/@aws-cdk/aws-opensearchservice/test/domain.test.ts @@ -1,6 +1,5 @@ /* eslint-disable jest/expect-expect */ -import '@aws-cdk/assert-internal/jest'; -import * as assert from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as acm from '@aws-cdk/aws-certificatemanager'; import { Metric, Statistic } from '@aws-cdk/aws-cloudwatch'; import { Vpc, EbsDeviceVolumeType, SecurityGroup } from '@aws-cdk/aws-ec2'; @@ -55,7 +54,7 @@ test('subnets and security groups can be provided when vpc is used', () => { }); expect(domain.connections.securityGroups[0].securityGroupId).toEqual(securityGroup.securityGroupId); - expect(stack).toHaveResource('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { VPCOptions: { SecurityGroupIds: [ { @@ -84,7 +83,7 @@ test('default subnets and security group when vpc is used', () => { }); expect(stack.resolve(domain.connections.securityGroups[0].securityGroupId)).toEqual({ 'Fn::GetAtt': ['DomainSecurityGroup48AA5FD6', 'GroupId'] }); - expect(stack).toHaveResource('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { VPCOptions: { SecurityGroupIds: [ { @@ -115,9 +114,9 @@ test('default removalpolicy is retain', () => { version: defaultVersion, }); - expect(stack).toHaveResource('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResource('AWS::OpenSearchService::Domain', { DeletionPolicy: 'Retain', - }, assert.ResourcePart.CompleteDefinition); + }); }); test('grants kms permissions if needed', () => { @@ -153,7 +152,7 @@ test('grants kms permissions if needed', () => { Version: '2012-10-17', }; - const resources = assert.expect(stack).value.Resources; + const resources = Template.fromStack(stack).toJSON().Resources; expect(resources.AWS679f53fac002430cb0da5b7982bd2287ServiceRoleDefaultPolicyD28E1A5E.Properties.PolicyDocument).toStrictEqual(expectedPolicy); }); @@ -161,7 +160,7 @@ test('grants kms permissions if needed', () => { test('minimal example renders correctly', () => { new Domain(stack, 'Domain', { version: defaultVersion }); - expect(stack).toHaveResource('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { CognitoOptions: { Enabled: false, }, @@ -181,10 +180,10 @@ test('minimal example renders correctly', () => { Enabled: false, }, LogPublishingOptions: { - AUDIT_LOGS: assert.ABSENT, - ES_APPLICATION_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + ES_APPLICATION_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, NodeToNodeEncryptionOptions: { Enabled: false, @@ -198,11 +197,11 @@ test('can enable version upgrade update policy', () => { enableVersionUpgrade: true, }); - expect(stack).toHaveResource('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResource('AWS::OpenSearchService::Domain', { UpdatePolicy: { EnableVersionUpgrade: true, }, - }, assert.ResourcePart.CompleteDefinition); + }); }); describe('UltraWarm instances', () => { @@ -216,7 +215,7 @@ describe('UltraWarm instances', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { ClusterConfig: { DedicatedMasterEnabled: true, WarmEnabled: true, @@ -236,7 +235,7 @@ describe('UltraWarm instances', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { ClusterConfig: { DedicatedMasterEnabled: true, WarmEnabled: true, @@ -261,7 +260,7 @@ test('can use tokens in capacity configuration', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { ClusterConfig: { InstanceCount: { Ref: 'dataNodes', @@ -297,7 +296,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { LogPublishingOptions: { SEARCH_SLOW_LOGS: { CloudWatchLogsLogGroupArn: { @@ -308,9 +307,9 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, - ES_APPLICATION_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + ES_APPLICATION_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, }); }); @@ -323,7 +322,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { LogPublishingOptions: { INDEX_SLOW_LOGS: { CloudWatchLogsLogGroupArn: { @@ -334,9 +333,9 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, - ES_APPLICATION_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + ES_APPLICATION_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), }, }); }); @@ -349,7 +348,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { LogPublishingOptions: { ES_APPLICATION_LOGS: { CloudWatchLogsLogGroupArn: { @@ -360,9 +359,9 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, }); }); @@ -383,7 +382,7 @@ describe('log groups', () => { enforceHttps: true, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { LogPublishingOptions: { AUDIT_LOGS: { CloudWatchLogsLogGroupArn: { @@ -394,9 +393,9 @@ describe('log groups', () => { }, Enabled: true, }, - ES_APPLICATION_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + ES_APPLICATION_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, }); }); @@ -418,7 +417,7 @@ describe('log groups', () => { slowIndexLogEnabled: true, }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { LogPublishingOptions: { ES_APPLICATION_LOGS: { CloudWatchLogsLogGroupArn: { @@ -447,10 +446,10 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { LogPublishingOptions: { ES_APPLICATION_LOGS: { CloudWatchLogsLogGroupArn: { @@ -479,7 +478,7 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), }, }); }); @@ -499,7 +498,7 @@ describe('log groups', () => { }); // Domain1 - expect(stack).toHaveResourceLike('Custom::CloudwatchLogResourcePolicy', { + Template.fromStack(stack).hasResourceProperties('Custom::CloudwatchLogResourcePolicy', { Create: { 'Fn::Join': [ '', @@ -517,7 +516,7 @@ describe('log groups', () => { }, }); // Domain2 - expect(stack).toHaveResourceLike('Custom::CloudwatchLogResourcePolicy', { + Template.fromStack(stack).hasResourceProperties('Custom::CloudwatchLogResourcePolicy', { Create: { 'Fn::Join': [ '', @@ -556,7 +555,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { LogPublishingOptions: { SEARCH_SLOW_LOGS: { CloudWatchLogsLogGroupArn: { @@ -567,9 +566,9 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, - ES_APPLICATION_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + ES_APPLICATION_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, }); }); @@ -585,7 +584,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { LogPublishingOptions: { INDEX_SLOW_LOGS: { CloudWatchLogsLogGroupArn: { @@ -596,9 +595,9 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, - ES_APPLICATION_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + ES_APPLICATION_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), }, }); }); @@ -614,7 +613,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { LogPublishingOptions: { ES_APPLICATION_LOGS: { CloudWatchLogsLogGroupArn: { @@ -625,9 +624,9 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, }); }); @@ -651,7 +650,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { LogPublishingOptions: { AUDIT_LOGS: { CloudWatchLogsLogGroupArn: { @@ -662,9 +661,9 @@ describe('log groups', () => { }, Enabled: true, }, - ES_APPLICATION_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + ES_APPLICATION_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, }); }); @@ -746,7 +745,7 @@ describe('grants', () => { domain.grantReadWrite(user); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -938,7 +937,7 @@ describe('import', () => { expect(imported.domainArn).toMatch(RegExp(`es:testregion:1234:domain/${domainName}$`)); expect(imported.domainEndpoint).toEqual(domainEndpointWithoutHttps); - expect(stack).not.toHaveResource('AWS::OpenSearchService::Domain'); + Template.fromStack(stack).resourceCountIs('AWS::OpenSearchService::Domain', 0); }); test('static fromDomainAttributes(attributes) allows importing an external/existing domain', () => { @@ -955,7 +954,7 @@ describe('import', () => { expect(imported.domainArn).toEqual(domainArn); expect(imported.domainEndpoint).toEqual(domainEndpointWithoutHttps); - expect(stack).not.toHaveResource('AWS::OpenSearchService::Domain'); + Template.fromStack(stack).resourceCountIs('AWS::OpenSearchService::Domain', 0); }); test('static fromDomainAttributes(attributes) allows importing with token arn and endpoint', () => { @@ -993,7 +992,7 @@ describe('import', () => { expect(imported.domainArn).toEqual(domainArn); expect(imported.domainEndpoint).toEqual(domainEndpoint); - expect(stack).not.toHaveResource('AWS::OpenSearchService::Domain'); + Template.fromStack(stack).resourceCountIs('AWS::OpenSearchService::Domain', 0); }); }); @@ -1016,7 +1015,7 @@ describe('advanced security options', () => { enforceHttps: true, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { AdvancedSecurityOptions: { Enabled: true, InternalUserDatabaseEnabled: false, @@ -1050,7 +1049,7 @@ describe('advanced security options', () => { enforceHttps: true, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { AdvancedSecurityOptions: { Enabled: true, InternalUserDatabaseEnabled: true, @@ -1084,7 +1083,7 @@ describe('advanced security options', () => { enforceHttps: true, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { AdvancedSecurityOptions: { Enabled: true, InternalUserDatabaseEnabled: true, @@ -1115,7 +1114,7 @@ describe('advanced security options', () => { }, }); - expect(stack).toHaveResourceLike('AWS::SecretsManager::Secret', { + Template.fromStack(stack).hasResourceProperties('AWS::SecretsManager::Secret', { GenerateSecretString: { GenerateStringKey: 'password', }, @@ -1192,7 +1191,7 @@ describe('custom endpoints', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { DomainEndpointOptions: { EnforceHTTPS: true, CustomEndpointEnabled: true, @@ -1202,7 +1201,7 @@ describe('custom endpoints', () => { }, }, }); - expect(stack).toHaveResourceLike('AWS::CertificateManager::Certificate', { + Template.fromStack(stack).hasResourceProperties('AWS::CertificateManager::Certificate', { DomainName: customDomainName, ValidationMethod: 'EMAIL', }); @@ -1220,7 +1219,7 @@ describe('custom endpoints', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { DomainEndpointOptions: { EnforceHTTPS: true, CustomEndpointEnabled: true, @@ -1230,7 +1229,7 @@ describe('custom endpoints', () => { }, }, }); - expect(stack).toHaveResourceLike('AWS::CertificateManager::Certificate', { + Template.fromStack(stack).hasResourceProperties('AWS::CertificateManager::Certificate', { DomainName: customDomainName, DomainValidationOptions: [ { @@ -1242,7 +1241,7 @@ describe('custom endpoints', () => { ], ValidationMethod: 'DNS', }); - expect(stack).toHaveResourceLike('AWS::Route53::RecordSet', { + Template.fromStack(stack).hasResourceProperties('AWS::Route53::RecordSet', { Name: 'search.example.com.', Type: 'CNAME', HostedZoneId: { @@ -1278,7 +1277,7 @@ describe('custom endpoints', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { DomainEndpointOptions: { EnforceHTTPS: true, CustomEndpointEnabled: true, @@ -1288,7 +1287,7 @@ describe('custom endpoints', () => { }, }, }); - expect(stack).toHaveResourceLike('AWS::Route53::RecordSet', { + Template.fromStack(stack).hasResourceProperties('AWS::Route53::RecordSet', { Name: 'search.example.com.', Type: 'CNAME', HostedZoneId: { @@ -1550,7 +1549,7 @@ describe('custom error responses', () => { }, }); // both configurations pass synth-time validation - expect(stack).toCountResources('AWS::OpenSearchService::Domain', 2); + Template.fromStack(stack).resourceCountIs('AWS::OpenSearchService::Domain', 2); }); test('error when availabilityZoneCount is not 2 or 3', () => { @@ -1608,7 +1607,7 @@ describe('custom error responses', () => { test('can specify future version', () => { new Domain(stack, 'Domain', { version: EngineVersion.elasticsearch('8.2') }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { EngineVersion: 'Elasticsearch_8.2', }); }); @@ -1620,7 +1619,7 @@ describe('unsigned basic auth', () => { useUnsignedBasicAuth: true, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { AdvancedSecurityOptions: { Enabled: true, InternalUserDatabaseEnabled: true, @@ -1651,7 +1650,7 @@ describe('unsigned basic auth', () => { useUnsignedBasicAuth: true, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { AdvancedSecurityOptions: { Enabled: true, InternalUserDatabaseEnabled: false, @@ -1685,7 +1684,7 @@ describe('unsigned basic auth', () => { useUnsignedBasicAuth: true, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { AdvancedSecurityOptions: { Enabled: true, InternalUserDatabaseEnabled: true, @@ -1748,7 +1747,7 @@ describe('advanced options', () => { }, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { AdvancedOptions: { 'rest.action.multi.allow_explicit_index': 'true', 'indices.fielddata.cache.size': '50', @@ -1761,8 +1760,8 @@ describe('advanced options', () => { version: defaultVersion, }); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { - AdvancedOptions: assert.ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { + AdvancedOptions: Match.absent(), }); }); }); @@ -1802,7 +1801,7 @@ function testGrant( ? resolvedPaths : resolvedPaths[0]; - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { diff --git a/packages/@aws-cdk/aws-opensearchservice/test/log-group-resource-policy.test.ts b/packages/@aws-cdk/aws-opensearchservice/test/log-group-resource-policy.test.ts index 68518297588c9..815c0086d4a99 100644 --- a/packages/@aws-cdk/aws-opensearchservice/test/log-group-resource-policy.test.ts +++ b/packages/@aws-cdk/aws-opensearchservice/test/log-group-resource-policy.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 { App, Stack } from '@aws-cdk/core'; import { LogGroupResourcePolicy } from '../lib/log-group-resource-policy'; @@ -24,7 +24,7 @@ test('minimal example renders correctly', () => { })], }); - expect(stack).toHaveResource('Custom::CloudwatchLogResourcePolicy', { + Template.fromStack(stack).hasResourceProperties('Custom::CloudwatchLogResourcePolicy', { ServiceToken: { 'Fn::GetAtt': [ 'AWS679f53fac002430cb0da5b7982bd22872D164C4C', diff --git a/packages/@aws-cdk/aws-opensearchservice/test/opensearch-access-policy.test.ts b/packages/@aws-cdk/aws-opensearchservice/test/opensearch-access-policy.test.ts index 62e4361f76e46..6e449d3521adb 100644 --- a/packages/@aws-cdk/aws-opensearchservice/test/opensearch-access-policy.test.ts +++ b/packages/@aws-cdk/aws-opensearchservice/test/opensearch-access-policy.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 { App, Stack } from '@aws-cdk/core'; import { OpenSearchAccessPolicy } from '../lib/opensearch-access-policy'; @@ -28,7 +28,7 @@ test('minimal example renders correctly', () => { })], }); - expect(stack).toHaveResource('Custom::OpenSearchAccessPolicy', { + Template.fromStack(stack).hasResourceProperties('Custom::OpenSearchAccessPolicy', { ServiceToken: { 'Fn::GetAtt': [ 'AWS679f53fac002430cb0da5b7982bd22872D164C4C', @@ -56,7 +56,7 @@ test('minimal example renders correctly', () => { physicalResourceId: { id: 'TestDomainAccessPolicy' }, }), }); - expect(stack).toHaveResourceLike('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [{ Action: 'es:UpdateDomainConfig', From 2c87d05202d4dc63c6c635c9b9488e32fce33b97 Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Tue, 28 Dec 2021 14:21:43 -0500 Subject: [PATCH 3/9] chore(elasticsearch): migrate tests to assertions --- .../@aws-cdk/aws-elasticsearch/package.json | 2 +- .../aws-elasticsearch/test/domain.test.ts | 159 +++++++++--------- .../test/elasticsearch-access-policy.test.ts | 4 +- .../test/log-group-resource-policy.test.ts | 4 +- 4 files changed, 83 insertions(+), 86 deletions(-) diff --git a/packages/@aws-cdk/aws-elasticsearch/package.json b/packages/@aws-cdk/aws-elasticsearch/package.json index 73b7bafbe8b41..b1263c7bce71e 100644 --- a/packages/@aws-cdk/aws-elasticsearch/package.json +++ b/packages/@aws-cdk/aws-elasticsearch/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/cdk-build-tools": "0.0.0", "@aws-cdk/cdk-integ-tools": "0.0.0", "@aws-cdk/cfn2ts": "0.0.0", diff --git a/packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts b/packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts index 5fc9035dc92f7..3242e75d2c253 100644 --- a/packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts +++ b/packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts @@ -1,6 +1,5 @@ /* eslint-disable jest/expect-expect */ -import '@aws-cdk/assert-internal/jest'; -import * as assert from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as acm from '@aws-cdk/aws-certificatemanager'; import { Metric, Statistic } from '@aws-cdk/aws-cloudwatch'; import { Vpc, EbsDeviceVolumeType, SecurityGroup } from '@aws-cdk/aws-ec2'; @@ -53,7 +52,7 @@ test('subnets and security groups can be provided when vpc is used', () => { }); expect(domain.connections.securityGroups[0].securityGroupId).toEqual(securityGroup.securityGroupId); - expect(stack).toHaveResource('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { VPCOptions: { SecurityGroupIds: [ { @@ -70,7 +69,6 @@ test('subnets and security groups can be provided when vpc is used', () => { ], }, }); - }); test('default subnets and security group when vpc is used', () => { @@ -82,7 +80,7 @@ test('default subnets and security group when vpc is used', () => { }); expect(stack.resolve(domain.connections.securityGroups[0].securityGroupId)).toEqual({ 'Fn::GetAtt': ['DomainSecurityGroup48AA5FD6', 'GroupId'] }); - expect(stack).toHaveResource('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { VPCOptions: { SecurityGroupIds: [ { @@ -105,7 +103,6 @@ test('default subnets and security group when vpc is used', () => { ], }, }); - }); test('default removalpolicy is retain', () => { @@ -113,9 +110,9 @@ test('default removalpolicy is retain', () => { version: ElasticsearchVersion.V7_1, }); - expect(stack).toHaveResource('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResource('AWS::Elasticsearch::Domain', { DeletionPolicy: 'Retain', - }, assert.ResourcePart.CompleteDefinition); + }); }); test('grants kms permissions if needed', () => { @@ -151,7 +148,7 @@ test('grants kms permissions if needed', () => { Version: '2012-10-17', }; - const resources = assert.expect(stack).value.Resources; + const resources = Template.fromStack(stack).toJSON().Resources; expect(resources.AWS679f53fac002430cb0da5b7982bd2287ServiceRoleDefaultPolicyD28E1A5E.Properties.PolicyDocument).toStrictEqual(expectedPolicy); }); @@ -159,7 +156,7 @@ test('grants kms permissions if needed', () => { test('minimal example renders correctly', () => { new Domain(stack, 'Domain', { version: ElasticsearchVersion.V7_1 }); - expect(stack).toHaveResource('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { CognitoOptions: { Enabled: false, }, @@ -179,10 +176,10 @@ test('minimal example renders correctly', () => { Enabled: false, }, LogPublishingOptions: { - AUDIT_LOGS: assert.ABSENT, - ES_APPLICATION_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + ES_APPLICATION_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, NodeToNodeEncryptionOptions: { Enabled: false, @@ -196,11 +193,11 @@ test('can enable version upgrade update policy', () => { enableVersionUpgrade: true, }); - expect(stack).toHaveResource('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResource('AWS::Elasticsearch::Domain', { UpdatePolicy: { EnableVersionUpgrade: true, }, - }, assert.ResourcePart.CompleteDefinition); + }); }); describe('UltraWarm instances', () => { @@ -214,7 +211,7 @@ describe('UltraWarm instances', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { ElasticsearchClusterConfig: { DedicatedMasterEnabled: true, WarmEnabled: true, @@ -234,7 +231,7 @@ describe('UltraWarm instances', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { ElasticsearchClusterConfig: { DedicatedMasterEnabled: true, WarmEnabled: true, @@ -259,7 +256,7 @@ test('can use tokens in capacity configuration', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { ElasticsearchClusterConfig: { InstanceCount: { Ref: 'dataNodes', @@ -295,7 +292,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { LogPublishingOptions: { SEARCH_SLOW_LOGS: { CloudWatchLogsLogGroupArn: { @@ -306,9 +303,9 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, - ES_APPLICATION_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + ES_APPLICATION_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, }); }); @@ -321,7 +318,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { LogPublishingOptions: { INDEX_SLOW_LOGS: { CloudWatchLogsLogGroupArn: { @@ -332,9 +329,9 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, - ES_APPLICATION_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + ES_APPLICATION_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), }, }); }); @@ -347,7 +344,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { LogPublishingOptions: { ES_APPLICATION_LOGS: { CloudWatchLogsLogGroupArn: { @@ -358,9 +355,9 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, }); }); @@ -381,7 +378,7 @@ describe('log groups', () => { enforceHttps: true, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { LogPublishingOptions: { AUDIT_LOGS: { CloudWatchLogsLogGroupArn: { @@ -392,9 +389,9 @@ describe('log groups', () => { }, Enabled: true, }, - ES_APPLICATION_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + ES_APPLICATION_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, }); }); @@ -416,7 +413,7 @@ describe('log groups', () => { slowIndexLogEnabled: true, }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { LogPublishingOptions: { ES_APPLICATION_LOGS: { CloudWatchLogsLogGroupArn: { @@ -445,10 +442,10 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { LogPublishingOptions: { ES_APPLICATION_LOGS: { CloudWatchLogsLogGroupArn: { @@ -477,7 +474,7 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), }, }); }); @@ -497,7 +494,7 @@ describe('log groups', () => { }); // Domain1 - expect(stack).toHaveResourceLike('Custom::CloudwatchLogResourcePolicy', { + Template.fromStack(stack).hasResourceProperties('Custom::CloudwatchLogResourcePolicy', { Create: { 'Fn::Join': [ '', @@ -515,7 +512,7 @@ describe('log groups', () => { }, }); // Domain2 - expect(stack).toHaveResourceLike('Custom::CloudwatchLogResourcePolicy', { + Template.fromStack(stack).hasResourceProperties('Custom::CloudwatchLogResourcePolicy', { Create: { 'Fn::Join': [ '', @@ -554,7 +551,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { LogPublishingOptions: { SEARCH_SLOW_LOGS: { CloudWatchLogsLogGroupArn: { @@ -565,9 +562,9 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, - ES_APPLICATION_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + ES_APPLICATION_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, }); }); @@ -583,7 +580,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { LogPublishingOptions: { INDEX_SLOW_LOGS: { CloudWatchLogsLogGroupArn: { @@ -594,9 +591,9 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, - ES_APPLICATION_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + ES_APPLICATION_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), }, }); }); @@ -612,7 +609,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { LogPublishingOptions: { ES_APPLICATION_LOGS: { CloudWatchLogsLogGroupArn: { @@ -623,9 +620,9 @@ describe('log groups', () => { }, Enabled: true, }, - AUDIT_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + AUDIT_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, }); }); @@ -649,7 +646,7 @@ describe('log groups', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { LogPublishingOptions: { AUDIT_LOGS: { CloudWatchLogsLogGroupArn: { @@ -660,9 +657,9 @@ describe('log groups', () => { }, Enabled: true, }, - ES_APPLICATION_LOGS: assert.ABSENT, - SEARCH_SLOW_LOGS: assert.ABSENT, - INDEX_SLOW_LOGS: assert.ABSENT, + ES_APPLICATION_LOGS: Match.absent(), + SEARCH_SLOW_LOGS: Match.absent(), + INDEX_SLOW_LOGS: Match.absent(), }, }); }); @@ -744,7 +741,7 @@ describe('grants', () => { domain.grantReadWrite(user); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -936,7 +933,7 @@ describe('import', () => { expect(imported.domainArn).toMatch(RegExp(`es:testregion:1234:domain/${domainName}$`)); expect(imported.domainEndpoint).toEqual(domainEndpointWithoutHttps); - expect(stack).not.toHaveResource('AWS::Elasticsearch::Domain'); + Template.fromStack(stack).resourceCountIs('AWS::Elasticsearch::Domain', 0); }); test('static fromDomainAttributes(attributes) allows importing an external/existing domain', () => { @@ -953,7 +950,7 @@ describe('import', () => { expect(imported.domainArn).toEqual(domainArn); expect(imported.domainEndpoint).toEqual(domainEndpointWithoutHttps); - expect(stack).not.toHaveResource('AWS::Elasticsearch::Domain'); + Template.fromStack(stack).resourceCountIs('AWS::Elasticsearch::Domain', 0); }); test('static fromDomainAttributes(attributes) allows importing with token arn and endpoint', () => { @@ -991,7 +988,7 @@ describe('import', () => { expect(imported.domainArn).toEqual(domainArn); expect(imported.domainEndpoint).toEqual(domainEndpoint); - expect(stack).not.toHaveResource('AWS::Elasticsearch::Domain'); + Template.fromStack(stack).resourceCountIs('AWS::Elasticsearch::Domain', 0); }); }); @@ -1014,7 +1011,7 @@ describe('advanced security options', () => { enforceHttps: true, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { AdvancedSecurityOptions: { Enabled: true, InternalUserDatabaseEnabled: false, @@ -1048,7 +1045,7 @@ describe('advanced security options', () => { enforceHttps: true, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { AdvancedSecurityOptions: { Enabled: true, InternalUserDatabaseEnabled: true, @@ -1082,7 +1079,7 @@ describe('advanced security options', () => { enforceHttps: true, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { AdvancedSecurityOptions: { Enabled: true, InternalUserDatabaseEnabled: true, @@ -1113,7 +1110,7 @@ describe('advanced security options', () => { }, }); - expect(stack).toHaveResourceLike('AWS::SecretsManager::Secret', { + Template.fromStack(stack).hasResourceProperties('AWS::SecretsManager::Secret', { GenerateSecretString: { GenerateStringKey: 'password', }, @@ -1190,7 +1187,7 @@ describe('custom endpoints', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { DomainEndpointOptions: { EnforceHTTPS: true, CustomEndpointEnabled: true, @@ -1200,7 +1197,7 @@ describe('custom endpoints', () => { }, }, }); - expect(stack).toHaveResourceLike('AWS::CertificateManager::Certificate', { + Template.fromStack(stack).hasResourceProperties('AWS::CertificateManager::Certificate', { DomainName: customDomainName, ValidationMethod: 'EMAIL', }); @@ -1218,7 +1215,7 @@ describe('custom endpoints', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { DomainEndpointOptions: { EnforceHTTPS: true, CustomEndpointEnabled: true, @@ -1228,7 +1225,7 @@ describe('custom endpoints', () => { }, }, }); - expect(stack).toHaveResourceLike('AWS::CertificateManager::Certificate', { + Template.fromStack(stack).hasResourceProperties('AWS::CertificateManager::Certificate', { DomainName: customDomainName, DomainValidationOptions: [ { @@ -1240,7 +1237,7 @@ describe('custom endpoints', () => { ], ValidationMethod: 'DNS', }); - expect(stack).toHaveResourceLike('AWS::Route53::RecordSet', { + Template.fromStack(stack).hasResourceProperties('AWS::Route53::RecordSet', { Name: 'search.example.com.', Type: 'CNAME', HostedZoneId: { @@ -1276,7 +1273,7 @@ describe('custom endpoints', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { DomainEndpointOptions: { EnforceHTTPS: true, CustomEndpointEnabled: true, @@ -1286,7 +1283,7 @@ describe('custom endpoints', () => { }, }, }); - expect(stack).toHaveResourceLike('AWS::Route53::RecordSet', { + Template.fromStack(stack).hasResourceProperties('AWS::Route53::RecordSet', { Name: 'search.example.com.', Type: 'CNAME', HostedZoneId: { @@ -1548,7 +1545,7 @@ describe('custom error responses', () => { }, }); // both configurations pass synth-time validation - expect(stack).toCountResources('AWS::Elasticsearch::Domain', 2); + Template.fromStack(stack).resourceCountIs('AWS::Elasticsearch::Domain', 2); }); test('error when availabilityZoneCount is not 2 or 3', () => { @@ -1606,7 +1603,7 @@ describe('custom error responses', () => { test('can specify future version', () => { new Domain(stack, 'Domain', { version: ElasticsearchVersion.of('8.2') }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { ElasticsearchVersion: '8.2', }); }); @@ -1618,7 +1615,7 @@ describe('unsigned basic auth', () => { useUnsignedBasicAuth: true, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { AdvancedSecurityOptions: { Enabled: true, InternalUserDatabaseEnabled: true, @@ -1649,7 +1646,7 @@ describe('unsigned basic auth', () => { useUnsignedBasicAuth: true, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { AdvancedSecurityOptions: { Enabled: true, InternalUserDatabaseEnabled: false, @@ -1683,7 +1680,7 @@ describe('unsigned basic auth', () => { useUnsignedBasicAuth: true, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { AdvancedSecurityOptions: { Enabled: true, InternalUserDatabaseEnabled: true, @@ -1746,7 +1743,7 @@ describe('advanced options', () => { }, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { AdvancedOptions: { 'rest.action.multi.allow_explicit_index': 'true', 'indices.fielddata.cache.size': '50', @@ -1759,8 +1756,8 @@ describe('advanced options', () => { version: ElasticsearchVersion.V7_1, }); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { - AdvancedOptions: assert.ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { + AdvancedOptions: Match.absent(), }); }); }); @@ -1800,7 +1797,7 @@ function testGrant( ? resolvedPaths : resolvedPaths[0]; - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { diff --git a/packages/@aws-cdk/aws-elasticsearch/test/elasticsearch-access-policy.test.ts b/packages/@aws-cdk/aws-elasticsearch/test/elasticsearch-access-policy.test.ts index 53d6afe3b2cb0..38ffc94c0c05b 100644 --- a/packages/@aws-cdk/aws-elasticsearch/test/elasticsearch-access-policy.test.ts +++ b/packages/@aws-cdk/aws-elasticsearch/test/elasticsearch-access-policy.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 { App, Stack } from '@aws-cdk/core'; import { ElasticsearchAccessPolicy } from '../lib/elasticsearch-access-policy'; @@ -26,7 +26,7 @@ test('minimal example renders correctly', () => { })], }); - expect(stack).toHaveResource('Custom::ElasticsearchAccessPolicy', { + Template.fromStack(stack).hasResourceProperties('Custom::ElasticsearchAccessPolicy', { ServiceToken: { 'Fn::GetAtt': [ 'AWS679f53fac002430cb0da5b7982bd22872D164C4C', diff --git a/packages/@aws-cdk/aws-elasticsearch/test/log-group-resource-policy.test.ts b/packages/@aws-cdk/aws-elasticsearch/test/log-group-resource-policy.test.ts index 68518297588c9..815c0086d4a99 100644 --- a/packages/@aws-cdk/aws-elasticsearch/test/log-group-resource-policy.test.ts +++ b/packages/@aws-cdk/aws-elasticsearch/test/log-group-resource-policy.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 { App, Stack } from '@aws-cdk/core'; import { LogGroupResourcePolicy } from '../lib/log-group-resource-policy'; @@ -24,7 +24,7 @@ test('minimal example renders correctly', () => { })], }); - expect(stack).toHaveResource('Custom::CloudwatchLogResourcePolicy', { + Template.fromStack(stack).hasResourceProperties('Custom::CloudwatchLogResourcePolicy', { ServiceToken: { 'Fn::GetAtt': [ 'AWS679f53fac002430cb0da5b7982bd22872D164C4C', From a5893c63abb6b61afead9bc911be2499f99dde91 Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Tue, 18 Jan 2022 14:42:13 -0500 Subject: [PATCH 4/9] chore(appmesh): migrate tests to assertions --- packages/@aws-cdk/aws-appmesh/package.json | 2 +- .../aws-appmesh/test/gateway-route.test.ts | 85 ++++------- .../aws-appmesh/test/health-check.test.ts | 9 -- .../@aws-cdk/aws-appmesh/test/mesh.test.ts | 63 +++----- .../@aws-cdk/aws-appmesh/test/route.test.ts | 113 +++++--------- .../aws-appmesh/test/virtual-gateway.test.ts | 114 +++++--------- .../aws-appmesh/test/virtual-node.test.ts | 141 ++++++------------ .../aws-appmesh/test/virtual-router.test.ts | 49 +++--- .../aws-appmesh/test/virtual-service.test.ts | 26 +--- 9 files changed, 195 insertions(+), 407 deletions(-) diff --git a/packages/@aws-cdk/aws-appmesh/package.json b/packages/@aws-cdk/aws-appmesh/package.json index 7936a9364e84c..e2a885f180327 100644 --- a/packages/@aws-cdk/aws-appmesh/package.json +++ b/packages/@aws-cdk/aws-appmesh/package.json @@ -84,7 +84,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", diff --git a/packages/@aws-cdk/aws-appmesh/test/gateway-route.test.ts b/packages/@aws-cdk/aws-appmesh/test/gateway-route.test.ts index 6ae344e7ff297..63516490d37a8 100644 --- a/packages/@aws-cdk/aws-appmesh/test/gateway-route.test.ts +++ b/packages/@aws-cdk/aws-appmesh/test/gateway-route.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 cdk from '@aws-cdk/core'; import * as appmesh from '../lib'; @@ -50,9 +49,9 @@ describe('gateway route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http-route', - MeshOwner: ABSENT, + MeshOwner: Match.absent(), Spec: { HttpRoute: { Action: { @@ -70,7 +69,7 @@ describe('gateway route', () => { }, }, }); - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http2-route', Spec: { Http2Route: { @@ -89,7 +88,7 @@ describe('gateway route', () => { }, }, }); - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-grpc-route', Spec: { GrpcRoute: { @@ -163,11 +162,9 @@ describe('gateway route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { MeshOwner: meshEnv.account, }); - - }); }); @@ -214,7 +211,7 @@ describe('gateway route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http-route', Spec: { HttpRoute: { @@ -229,7 +226,7 @@ describe('gateway route', () => { }, }); - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-grpc-route', Spec: { GrpcRoute: { @@ -243,8 +240,6 @@ describe('gateway route', () => { }, }, }); - - }); }); @@ -279,10 +274,8 @@ describe('gateway route', () => { }), gatewayRouteName: 'gateway-http2-route', }); - - // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http2-route', Spec: { Http2Route: { @@ -296,8 +289,6 @@ describe('gateway route', () => { }, }, }); - - }); }); @@ -355,7 +346,7 @@ describe('gateway route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http-route', Spec: { HttpRoute: { @@ -370,7 +361,7 @@ describe('gateway route', () => { }, }); - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http2-route', Spec: { Http2Route: { @@ -385,18 +376,16 @@ describe('gateway route', () => { }, }); - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http2-route-1', Spec: { Http2Route: { Action: { - Rewrite: ABSENT, + Rewrite: Match.absent(), }, }, }, }); - - }); test("should throw an error if the prefix match does not start and end with '/'", () => { @@ -429,8 +418,6 @@ describe('gateway route', () => { gatewayRouteName: 'gateway-http-route', }); }).toThrow(/Prefix path for the match must start with \'\/\', got: test\//); - - expect(() => { virtualGateway.addGatewayRoute('gateway-http2-route', { routeSpec: appmesh.GatewayRouteSpec.http2({ @@ -442,8 +429,6 @@ describe('gateway route', () => { gatewayRouteName: 'gateway-http2-route', }); }).toThrow(/When prefix path for the rewrite is specified, prefix path for the match must end with \'\/\', got: \/test/); - - }); test("should throw an error if the custom prefix does not start and end with '/'", () => { @@ -488,8 +473,6 @@ describe('gateway route', () => { gatewayRouteName: 'gateway-http2-route', }); }).toThrow(/Prefix path for the rewrite must start and end with \'\/\', got: \/rewrittenUri/); - - }); }); @@ -535,7 +518,7 @@ describe('gateway route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http-route', Spec: { HttpRoute: { @@ -545,13 +528,13 @@ describe('gateway route', () => { }, }, Action: { - Rewrite: ABSENT, + Rewrite: Match.absent(), }, }, }, }); - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-grpc-route', Spec: { GrpcRoute: { @@ -563,8 +546,6 @@ describe('gateway route', () => { }, }, }); - - }); }); @@ -610,7 +591,7 @@ describe('gateway route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-grpc-route', Spec: { GrpcRoute: { @@ -681,8 +662,6 @@ describe('gateway route', () => { }, }, }); - - }); test('should throw an error if the array length is invalid', () => { @@ -742,8 +721,6 @@ describe('gateway route', () => { gatewayRouteName: 'gateway-grpc-route', }); }).toThrow(/Number of metadata provided for matching must be between 1 and 10/); - - }); }); @@ -790,7 +767,7 @@ describe('gateway route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http-route', Spec: { HttpRoute: { @@ -861,8 +838,6 @@ describe('gateway route', () => { }, }, }); - - }); }); @@ -898,7 +873,7 @@ describe('gateway route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http-route', Spec: { HttpRoute: { @@ -908,8 +883,6 @@ describe('gateway route', () => { }, }, }); - - }); }); @@ -956,7 +929,7 @@ describe('gateway route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http-route', Spec: { HttpRoute: { @@ -966,13 +939,13 @@ describe('gateway route', () => { }, }, Action: { - Rewrite: ABSENT, + Rewrite: Match.absent(), }, }, }, }); - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http2-route', Spec: { Http2Route: { @@ -984,8 +957,6 @@ describe('gateway route', () => { }, }, }); - - }); test('should throw an error if empty string is passed', () => { @@ -1019,8 +990,6 @@ describe('gateway route', () => { gatewayRouteName: 'gateway-http-route', }); }).toThrow(/Exact Path for the rewrite cannot be empty. Unlike startsWith\(\) method, no automatic rewrite on whole path match/); - - }); }); @@ -1058,7 +1027,7 @@ describe('gateway route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http-route', Spec: { HttpRoute: { @@ -1075,8 +1044,6 @@ describe('gateway route', () => { }, }, }); - - }); }); }); @@ -1112,7 +1079,7 @@ describe('gateway route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'gateway-http-route', Spec: { HttpRoute: { @@ -1157,7 +1124,7 @@ describe('gateway route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { Spec: { Priority: 100, }, @@ -1197,7 +1164,7 @@ describe('gateway route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { Spec: { Priority: 500, }, diff --git a/packages/@aws-cdk/aws-appmesh/test/health-check.test.ts b/packages/@aws-cdk/aws-appmesh/test/health-check.test.ts index 7abb6ed92f249..ebc78039d8cc4 100644 --- a/packages/@aws-cdk/aws-appmesh/test/health-check.test.ts +++ b/packages/@aws-cdk/aws-appmesh/test/health-check.test.ts @@ -1,5 +1,4 @@ import * as cdk from '@aws-cdk/core'; - import * as appmesh from '../lib'; let idCounter = 0; @@ -29,8 +28,6 @@ describe('health check', () => { expect(() => toThrow(max)).not.toThrow(); expect(() => toThrow(min - 1)).toThrow(/interval must be between 5 seconds and 300 seconds/); expect(() => toThrow(max + 1)).toThrow(/interval must be between 5 seconds and 300 seconds/); - - }); test('timeout', () => { // GIVEN @@ -48,8 +45,6 @@ describe('health check', () => { expect(() => toThrow(max)).not.toThrow(); expect(() => toThrow(min - 1)).toThrow(/timeout must be between 2 seconds and 60 seconds/); expect(() => toThrow(max + 1)).toThrow(/timeout must be between 2 seconds and 60 seconds/); - - }); test('healthyThreshold', () => { // GIVEN @@ -67,8 +62,6 @@ describe('health check', () => { expect(() => toThrow(max)).not.toThrow(); expect(() => toThrow(min - 1)).toThrow(/healthyThreshold must be between 2 and 10/); expect(() => toThrow(max + 1)).toThrow(/healthyThreshold must be between 2 and 10/); - - }); test('unhealthyThreshold', () => { // GIVEN @@ -86,7 +79,5 @@ describe('health check', () => { expect(() => toThrow(max)).not.toThrow(); expect(() => toThrow(min - 1)).toThrow(/unhealthyThreshold must be between 2 and 10/); expect(() => toThrow(max + 1)).toThrow(/unhealthyThreshold must be between 2 and 10/); - - }); }); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-appmesh/test/mesh.test.ts b/packages/@aws-cdk/aws-appmesh/test/mesh.test.ts index 294701e0d550a..e8f7588e59f4f 100644 --- a/packages/@aws-cdk/aws-appmesh/test/mesh.test.ts +++ b/packages/@aws-cdk/aws-appmesh/test/mesh.test.ts @@ -1,8 +1,7 @@ -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as cloudmap from '@aws-cdk/aws-servicediscovery'; import * as cdk from '@aws-cdk/core'; - import * as appmesh from '../lib'; describe('mesh', () => { @@ -16,13 +15,11 @@ describe('mesh', () => { new appmesh.Mesh(stack, 'mesh', { meshName: 'test-mesh' }); // THEN - expect(stack). - toHaveResource('AWS::AppMesh::Mesh', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::Mesh', { Spec: { }, }); - - }); }); @@ -38,16 +35,14 @@ describe('mesh', () => { }); // THEN - expect(stack). - toHaveResource('AWS::AppMesh::Mesh', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::Mesh', { Spec: { EgressFilter: { Type: 'ALLOW_ALL', }, }, }); - - }); }); }); @@ -66,8 +61,8 @@ describe('mesh', () => { mesh.addVirtualRouter('router'); // THEN - expect(stack). - toHaveResource('AWS::AppMesh::VirtualRouter', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::VirtualRouter', { Spec: { Listeners: [ { @@ -79,8 +74,6 @@ describe('mesh', () => { ], }, }); - - }); }); }); @@ -105,7 +98,7 @@ describe('mesh', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { ServiceDiscovery: { AWSCloudMap: { @@ -115,8 +108,6 @@ describe('mesh', () => { }, }, }); - - }); test('VirtualService can use CloudMap service with instanceAttributes', () => { @@ -142,7 +133,7 @@ describe('mesh', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { ServiceDiscovery: { AWSCloudMap: { @@ -158,8 +149,6 @@ describe('mesh', () => { }, }, }); - - }); describe('When adding a VirtualNode to a mesh', () => { @@ -178,8 +167,8 @@ describe('mesh', () => { }); // THEN - expect(stack). - toHaveResource('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::VirtualNode', { MeshName: { 'Fn::GetAtt': ['meshACDFE68E', 'MeshName'], }, @@ -192,8 +181,6 @@ describe('mesh', () => { }, }, }); - - }); }); describe('with added listeners', () => { @@ -214,8 +201,8 @@ describe('mesh', () => { }); // THEN - expect(stack). - toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::VirtualNode', { MeshName: { 'Fn::GetAtt': ['meshACDFE68E', 'MeshName'], }, @@ -230,8 +217,6 @@ describe('mesh', () => { ], }, }); - - }); }); describe('with added listeners with healthchecks', () => { @@ -259,14 +244,14 @@ describe('mesh', () => { }); // THEN - expect(stack). - toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::VirtualNode', { MeshName: { 'Fn::GetAtt': ['meshACDFE68E', 'MeshName'], }, Spec: { Listeners: [ - { + Match.objectLike({ HealthCheck: { HealthyThreshold: 3, IntervalMillis: 5000, @@ -276,12 +261,10 @@ describe('mesh', () => { TimeoutMillis: 2000, UnhealthyThreshold: 2, }, - }, + }), ], }, }); - - }); }); describe('with backends', () => { @@ -308,8 +291,8 @@ describe('mesh', () => { }); // THEN - expect(stack). - toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Backends: [ { @@ -320,8 +303,6 @@ describe('mesh', () => { ], }, }); - - }); }); }); @@ -336,13 +317,11 @@ describe('mesh', () => { }); // THEN - expect(stack2). - toHaveResourceLike('AWS::AppMesh::VirtualService', { + Template.fromStack(stack2). + hasResourceProperties('AWS::AppMesh::VirtualService', { MeshName: 'abc', Spec: {}, VirtualServiceName: 'test.domain.local', }); - - }); }); diff --git a/packages/@aws-cdk/aws-appmesh/test/route.test.ts b/packages/@aws-cdk/aws-appmesh/test/route.test.ts index e39b20585a03c..130a46f058f63 100644 --- a/packages/@aws-cdk/aws-appmesh/test/route.test.ts +++ b/packages/@aws-cdk/aws-appmesh/test/route.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 cdk from '@aws-cdk/core'; import * as appmesh from '../lib'; @@ -80,7 +79,7 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { HttpRoute: { Action: { @@ -111,11 +110,11 @@ describe('route', () => { }, }, }, - MeshOwner: ABSENT, + MeshOwner: Match.absent(), RouteName: 'test-http-route', }); - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { Http2Route: { Action: { @@ -149,7 +148,7 @@ describe('route', () => { RouteName: 'test-http2-route', }); - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { TcpRoute: { Action: { @@ -176,7 +175,7 @@ describe('route', () => { RouteName: 'test-tcp-route', }); - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { GrpcRoute: { Action: { @@ -209,8 +208,6 @@ describe('route', () => { }, RouteName: 'test-grpc-route', }); - - }); test('should have expected features', () => { @@ -247,7 +244,7 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { HttpRoute: { Action: { @@ -311,7 +308,7 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { HttpRoute: { RetryPolicy: { @@ -326,11 +323,9 @@ describe('route', () => { }, }, }); - - }); - test('http retry events are ABSENT when specified as an empty array', () => { + test('http retry events are Match.absent() when specified as an empty array', () => { // GIVEN const stack = new cdk.Stack(); const mesh = new appmesh.Mesh(stack, 'mesh', { @@ -370,28 +365,26 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { HttpRoute: { RetryPolicy: { - HttpRetryEvents: ABSENT, + HttpRetryEvents: Match.absent(), TcpRetryEvents: ['connection-error'], }, }, }, }); - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { HttpRoute: { RetryPolicy: { HttpRetryEvents: ['client-error'], - TcpRetryEvents: ABSENT, + TcpRetryEvents: Match.absent(), }, }, }, }); - - }); test('errors when http retry policy has no events', () => { @@ -420,8 +413,6 @@ describe('route', () => { }), }); }).toThrow(/specify one value for at least/i); - - }); test('should allow grpc retries', () => { @@ -454,7 +445,7 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { GrpcRoute: { RetryPolicy: { @@ -470,11 +461,9 @@ describe('route', () => { }, }, }); - - }); - test('grpc retry events are ABSENT when specified as an empty array', () => { + test('grpc retry events are Match.absent() when specified as an empty array', () => { // GIVEN const stack = new cdk.Stack(); const mesh = new appmesh.Mesh(stack, 'mesh', { @@ -518,30 +507,28 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { GrpcRoute: { RetryPolicy: { - GrpcRetryEvents: ABSENT, - HttpRetryEvents: ABSENT, + GrpcRetryEvents: Match.absent(), + HttpRetryEvents: Match.absent(), TcpRetryEvents: ['connection-error'], }, }, }, }); - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { GrpcRoute: { RetryPolicy: { GrpcRetryEvents: ['cancelled'], - HttpRetryEvents: ABSENT, - TcpRetryEvents: ABSENT, + HttpRetryEvents: Match.absent(), + TcpRetryEvents: Match.absent(), }, }, }, }); - - }); test('errors when grpc retry policy has no events', () => { @@ -571,8 +558,6 @@ describe('route', () => { }), }); }).toThrow(/specify one value for at least/i); - - }); describe('with shared service mesh', () => { @@ -605,11 +590,9 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { MeshOwner: meshEnv.account, }); - - }); }); }); @@ -653,7 +636,7 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { Http2Route: { Match: { @@ -724,8 +707,6 @@ describe('route', () => { }, }, }); - - }); test('should match routes based on method', () => { @@ -756,7 +737,7 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { Http2Route: { Match: { @@ -766,8 +747,6 @@ describe('route', () => { }, }, }); - - }); test('should match routes based on scheme', () => { @@ -798,7 +777,7 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { Http2Route: { Match: { @@ -808,8 +787,6 @@ describe('route', () => { }, }, }); - - }); test('should match routes based on metadata', () => { @@ -852,7 +829,7 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { GrpcRoute: { Match: { @@ -922,8 +899,6 @@ describe('route', () => { }, }, }); - - }); test('should match routes based on path', () => { @@ -966,7 +941,7 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { HttpRoute: { Match: { @@ -978,7 +953,7 @@ describe('route', () => { }, }); - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { Http2Route: { Match: { @@ -989,8 +964,6 @@ describe('route', () => { }, }, }); - - }); test('should match routes based query parameter', () => { @@ -1022,7 +995,7 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { HttpRoute: { Match: { @@ -1038,8 +1011,6 @@ describe('route', () => { }, }, }); - - }); test('should match routes based method name', () => { @@ -1073,7 +1044,7 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { GrpcRoute: { Match: { @@ -1083,8 +1054,6 @@ describe('route', () => { }, }, }); - - }); test('should throw an error with invalid number of headers', () => { @@ -1141,8 +1110,6 @@ describe('route', () => { }), }); }).toThrow(/Number of headers provided for matching must be between 1 and 10, got: 11/); - - }); test('should throw an error with invalid number of query parameters', () => { @@ -1199,8 +1166,6 @@ describe('route', () => { }), }); }).toThrow(/Number of query parameters provided for matching must be between 1 and 10, got: 11/); - - }); test('should throw an error with invalid number of metadata', () => { @@ -1260,8 +1225,6 @@ describe('route', () => { }), }); }).toThrow(/Number of metadata provided for matching must be between 1 and 10, got: 11/); - - }); test('should throw an error if no gRPC match type is defined', () => { @@ -1292,8 +1255,6 @@ describe('route', () => { }), }); }).toThrow(/At least one gRPC route match property must be provided/); - - }); test('should throw an error if method name is specified without service name', () => { @@ -1326,8 +1287,6 @@ describe('route', () => { }), }); }).toThrow(/If you specify a method name, you must also specify a service name/); - - }); test('should allow route priority', () => { @@ -1376,32 +1335,30 @@ describe('route', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { Priority: 0, Http2Route: {}, }, }); - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { Priority: 10, HttpRoute: {}, }, }); - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { Priority: 20, GrpcRoute: {}, }, }); - expect(stack).toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::Route', { Spec: { Priority: 30, TcpRoute: {}, }, }); - - }); test('Can import Routes using an ARN', () => { @@ -1443,7 +1400,5 @@ describe('route', () => { // THEN expect(route.routeName).toEqual(routeName); expect(route.virtualRouter.mesh.meshName).toEqual(meshName); - - }); }); diff --git a/packages/@aws-cdk/aws-appmesh/test/virtual-gateway.test.ts b/packages/@aws-cdk/aws-appmesh/test/virtual-gateway.test.ts index 17a78b7d361d6..eadfebec29493 100644 --- a/packages/@aws-cdk/aws-appmesh/test/virtual-gateway.test.ts +++ b/packages/@aws-cdk/aws-appmesh/test/virtual-gateway.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 acm from '@aws-cdk/aws-certificatemanager'; import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; @@ -39,7 +38,7 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { Spec: { Listeners: [ { @@ -53,7 +52,7 @@ describe('virtual gateway', () => { VirtualGatewayName: 'testGateway', }); - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { Spec: { Listeners: [ { @@ -74,10 +73,10 @@ describe('virtual gateway', () => { ], }, VirtualGatewayName: 'httpGateway', - MeshOwner: ABSENT, + MeshOwner: Match.absent(), }); - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { Spec: { Listeners: [ { @@ -99,7 +98,6 @@ describe('virtual gateway', () => { }, VirtualGatewayName: 'http2Gateway', }); - }); test('should have expected features', () => { @@ -122,7 +120,7 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { Spec: { Listeners: [ { @@ -150,7 +148,6 @@ describe('virtual gateway', () => { }, VirtualGatewayName: 'test-gateway', }); - }); test('with an http listener with a TLS certificate from ACM', () => { @@ -179,10 +176,10 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { Spec: { Listeners: [ - { + Match.objectLike({ TLS: { Mode: appmesh.TlsMode.STRICT, Certificate: { @@ -193,12 +190,10 @@ describe('virtual gateway', () => { }, }, }, - }, + }), ], }, }); - - }); test('with an grpc listener with a TLS certificate from file', () => { @@ -223,10 +218,10 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { Spec: { Listeners: [ - { + Match.objectLike({ TLS: { Mode: appmesh.TlsMode.STRICT, Certificate: { @@ -236,12 +231,10 @@ describe('virtual gateway', () => { }, }, }, - }, + }), ], }, }); - - }); test('with an http2 listener with a TLS certificate from SDS', () => { @@ -265,10 +258,10 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { Spec: { Listeners: [ - { + Match.objectLike({ TLS: { Mode: appmesh.TlsMode.STRICT, Certificate: { @@ -277,12 +270,10 @@ describe('virtual gateway', () => { }, }, }, - }, + }), ], }, }); - - }); describe('with an grpc listener with a TLS validation from file', () => { @@ -310,10 +301,10 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { Spec: { Listeners: [ - { + Match.objectLike({ TLS: { Mode: appmesh.TlsMode.STRICT, Certificate: { @@ -330,12 +321,10 @@ describe('virtual gateway', () => { }, }, }, - }, + }), ], }, }); - - }); }); @@ -365,10 +354,10 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { Spec: { Listeners: [ - { + Match.objectLike({ TLS: { Mode: appmesh.TlsMode.STRICT, Certificate: { @@ -384,12 +373,10 @@ describe('virtual gateway', () => { }, }, }, - }, + }), ], }, }); - - }); }); @@ -415,10 +402,10 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { Spec: { Listeners: [ - { + Match.objectLike({ TLS: { Mode: appmesh.TlsMode.PERMISSIVE, Certificate: { @@ -428,12 +415,10 @@ describe('virtual gateway', () => { }, }, }, - }, + }), ], }, }); - - }); describe('with shared service mesh', () => { @@ -455,11 +440,9 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { MeshOwner: meshEnv.account, }); - - }); }); }); @@ -491,7 +474,7 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'test-gateway-route', Spec: { HttpRoute: { @@ -510,7 +493,6 @@ describe('virtual gateway', () => { }, }, }); - }); }); @@ -542,13 +524,12 @@ describe('virtual gateway', () => { }), }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'test-gateway-route', }); - expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::GatewayRoute', { GatewayRouteName: 'test-gateway-route-2', }); - }); }); @@ -575,7 +556,7 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { VirtualGatewayName: 'virtual-gateway', Spec: { BackendDefaults: { @@ -593,8 +574,6 @@ describe('virtual gateway', () => { }, }, }); - - }); describe("with client's TLS certificate from SDS", () => { @@ -621,7 +600,7 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { VirtualGatewayName: 'virtual-gateway', Spec: { BackendDefaults: { @@ -649,8 +628,6 @@ describe('virtual gateway', () => { }, }, }); - - }); }); }); @@ -679,23 +656,21 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { VirtualGatewayName: 'virtual-gateway', Spec: { Listeners: [ - { + Match.objectLike({ ConnectionPool: { HTTP: { MaxConnections: 100, MaxPendingRequests: 10, }, }, - }, + }), ], }, }); - - }); test('Can add an grpc connection pool to listener', () => { @@ -721,22 +696,20 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { VirtualGatewayName: 'virtual-gateway', Spec: { Listeners: [ - { + Match.objectLike({ ConnectionPool: { GRPC: { MaxRequests: 10, }, }, - }, + }), ], }, }); - - }); test('Can add an http2 connection pool to listener', () => { @@ -762,22 +735,20 @@ describe('virtual gateway', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualGateway', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualGateway', { VirtualGatewayName: 'virtual-gateway', Spec: { Listeners: [ - { + Match.objectLike({ ConnectionPool: { HTTP2: { MaxRequests: 10, }, }, - }, + }), ], }, }); - - }); test('Can import VirtualGateways using an ARN', () => { @@ -796,7 +767,6 @@ describe('virtual gateway', () => { // THEN expect(virtualGateway.mesh.meshName).toEqual(meshName); expect(virtualGateway.virtualGatewayName).toEqual(virtualGatewayName); - }); test('Can import VirtualGateways using attributes', () => { @@ -816,8 +786,6 @@ describe('virtual gateway', () => { // THEN expect(virtualGateway.mesh.meshName).toEqual(meshName); expect(virtualGateway.virtualGatewayName).toEqual(virtualGatewayName); - - }); test('Can grant an identity StreamAggregatedResources for a given VirtualGateway', () => { @@ -835,7 +803,7 @@ describe('virtual gateway', () => { gateway.grantStreamAggregatedResources(user); // THEN - expect(stack).toHaveResourceLike('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -848,7 +816,5 @@ describe('virtual gateway', () => { ], }, }); - - }); }); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-appmesh/test/virtual-node.test.ts b/packages/@aws-cdk/aws-appmesh/test/virtual-node.test.ts index 842c061f68a15..f419f7ac41733 100644 --- a/packages/@aws-cdk/aws-appmesh/test/virtual-node.test.ts +++ b/packages/@aws-cdk/aws-appmesh/test/virtual-node.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 acmpca from '@aws-cdk/aws-acmpca'; import * as acm from '@aws-cdk/aws-certificatemanager'; import * as iam from '@aws-cdk/aws-iam'; @@ -36,7 +35,7 @@ describe('virtual node', () => { node.addBackend(appmesh.Backend.virtualService(service2)); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Backends: [ { @@ -51,7 +50,7 @@ describe('virtual node', () => { }, ], }, - MeshOwner: ABSENT, + MeshOwner: Match.absent(), }); }); }); @@ -75,7 +74,7 @@ describe('virtual node', () => { })); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Listeners: [ { @@ -87,8 +86,6 @@ describe('virtual node', () => { ], }, }); - - }); }); @@ -115,7 +112,7 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Listeners: [ { @@ -139,8 +136,6 @@ describe('virtual node', () => { ], }, }); - - }); }); @@ -165,10 +160,10 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Listeners: [ - { + Match.objectLike({ HealthCheck: { HealthyThreshold: 2, IntervalMillis: 5000, @@ -189,12 +184,10 @@ describe('virtual node', () => { }, }, }, - }, + }), ], }, }); - - }); }); @@ -222,10 +215,10 @@ describe('virtual node', () => { })); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Listeners: [ - { + Match.objectLike({ HealthCheck: { HealthyThreshold: 2, IntervalMillis: 5000, @@ -246,12 +239,10 @@ describe('virtual node', () => { }, }, }, - }, + }), ], }, }); - - }); }); @@ -281,7 +272,7 @@ describe('virtual node', () => { })); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Listeners: [ { @@ -305,8 +296,6 @@ describe('virtual node', () => { ], }, }); - - }); }); @@ -336,7 +325,7 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { BackendDefaults: { ClientPolicy: { @@ -354,8 +343,6 @@ describe('virtual node', () => { }, }, }); - - }); }); @@ -384,7 +371,7 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { BackendDefaults: { ClientPolicy: { @@ -412,8 +399,6 @@ describe('virtual node', () => { }, }, }); - - }); }); @@ -447,7 +432,7 @@ describe('virtual node', () => { })); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Backends: [ { @@ -494,7 +479,7 @@ describe('virtual node', () => { node.addBackend(appmesh.Backend.virtualService(myVirtualService)); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Backends: [ { @@ -528,7 +513,7 @@ describe('virtual node', () => { node.addBackend(appmesh.Backend.virtualService(myVirtualService)); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Backends: [ { @@ -570,10 +555,10 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Listeners: [ - { + Match.objectLike({ TLS: { Mode: appmesh.TlsMode.STRICT, Certificate: { @@ -584,12 +569,10 @@ describe('virtual node', () => { }, }, }, - }, + }), ], }, }); - - }); }); @@ -616,10 +599,10 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Listeners: [ - { + Match.objectLike({ TLS: { Mode: appmesh.TlsMode.STRICT, Certificate: { @@ -629,12 +612,10 @@ describe('virtual node', () => { }, }, }, - }, + }), ], }, }); - - }); }); @@ -660,10 +641,10 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Listeners: [ - { + Match.objectLike({ TLS: { Mode: appmesh.TlsMode.STRICT, Certificate: { @@ -672,12 +653,10 @@ describe('virtual node', () => { }, }, }, - }, + }), ], }, }); - - }); }); @@ -704,10 +683,10 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Listeners: [ - { + Match.objectLike({ TLS: { Mode: appmesh.TlsMode.PERMISSIVE, Certificate: { @@ -717,12 +696,10 @@ describe('virtual node', () => { }, }, }, - }, + }), ], }, }); - - }); }); @@ -750,22 +727,20 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Listeners: [ - { + Match.objectLike({ ConnectionPool: { HTTP: { MaxConnections: 100, MaxPendingRequests: 10, }, }, - }, + }), ], }, }); - - }); test('Can add an tcp connection pool to listener', () => { @@ -791,21 +766,19 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { - Listeners: [ - { + Listeners: Match.arrayWith([ + Match.objectLike({ ConnectionPool: { TCP: { MaxConnections: 100, }, }, - }, - ], + }), + ]), }, }); - - }); test('Can add an grpc connection pool to listener', () => { @@ -831,21 +804,19 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { - Listeners: [ - { + Listeners: Match.arrayWith([ + Match.objectLike({ ConnectionPool: { GRPC: { MaxRequests: 10, }, }, - }, - ], + }), + ]), }, }); - - }); test('Can add an http2 connection pool to listener', () => { @@ -871,21 +842,19 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { Listeners: [ - { + Match.objectLike({ ConnectionPool: { HTTP2: { MaxRequests: 10, }, }, - }, + }), ], }, }); - - }); }); @@ -903,8 +872,6 @@ describe('virtual node', () => { // THEN expect(virtualNode.mesh.meshName).toEqual(meshName); expect(virtualNode.virtualNodeName).toEqual(virtualNodeName); - - }); test('Can import Virtual Nodes using attributes', () => { @@ -920,8 +887,6 @@ describe('virtual node', () => { // THEN expect(virtualNode.mesh.meshName).toEqual(meshName); expect(virtualNode.virtualNodeName).toEqual(virtualNodeName); - - }); test('Can grant an identity StreamAggregatedResources for a given VirtualNode', () => { @@ -947,7 +912,7 @@ describe('virtual node', () => { node.grantStreamAggregatedResources(user); // THEN - expect(stack).toHaveResourceLike('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -960,8 +925,6 @@ describe('virtual node', () => { ], }, }); - - }); describe('When creating a VirtualNode', () => { @@ -984,11 +947,9 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { MeshOwner: meshEnv.account, }); - - }); }); @@ -1008,7 +969,7 @@ describe('virtual node', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualNode', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualNode', { Spec: { ServiceDiscovery: { DNS: { @@ -1018,8 +979,6 @@ describe('virtual node', () => { }, }, }); - - }); }); @@ -1053,11 +1012,7 @@ describe('virtual node', () => { expect(() => { node.addListener(appmesh.VirtualNodeListener.http()); }).toThrow(/Service discovery information is required for a VirtualNode with a listener/); - - }); }); }); }); - - diff --git a/packages/@aws-cdk/aws-appmesh/test/virtual-router.test.ts b/packages/@aws-cdk/aws-appmesh/test/virtual-router.test.ts index 7342aa8f052bd..24df84fd051ad 100644 --- a/packages/@aws-cdk/aws-appmesh/test/virtual-router.test.ts +++ b/packages/@aws-cdk/aws-appmesh/test/virtual-router.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 cdk from '@aws-cdk/core'; import * as appmesh from '../lib'; @@ -11,10 +10,11 @@ describe('virtual router', () => { const mesh = new appmesh.Mesh(stack, 'mesh', { meshName: 'test-mesh', }); + // WHEN mesh.addVirtualRouter('http-router-listener'); - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualRouter', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualRouter', { VirtualRouterName: 'meshhttprouterlistenerF57BCB2F', Spec: { Listeners: [ @@ -27,14 +27,15 @@ describe('virtual router', () => { ], }, }); - }); + test('should have protocol variant listeners', () => { // GIVEN const stack = new cdk.Stack(); const mesh = new appmesh.Mesh(stack, 'mesh', { meshName: 'test-mesh', }); + // WHEN mesh.addVirtualRouter('http-router-listener', { listeners: [ @@ -67,7 +68,7 @@ describe('virtual router', () => { // THEN const expectedPorts = [appmesh.Protocol.HTTP, appmesh.Protocol.HTTP2, appmesh.Protocol.GRPC, appmesh.Protocol.TCP]; expectedPorts.forEach(protocol => { - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualRouter', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualRouter', { VirtualRouterName: `${protocol}-router-listener`, Spec: { Listeners: [ @@ -79,11 +80,9 @@ describe('virtual router', () => { }, ], }, - MeshOwner: ABSENT, + MeshOwner: Match.absent(), }); }); - - }); describe('with shared service mesh', () => { @@ -105,11 +104,9 @@ describe('virtual router', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualRouter', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualRouter', { MeshOwner: meshEnv.account, }); - - }); }); }); @@ -154,8 +151,8 @@ describe('virtual router', () => { }); // THEN - expect(stack). - toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::Route', { RouteName: 'route-1', Spec: { HttpRoute: { @@ -178,8 +175,6 @@ describe('virtual router', () => { 'Fn::GetAtt': ['meshrouter81B8087E', 'VirtualRouterName'], }, }); - - }); }); describe('When adding routes to a VirtualRouter with existing routes', () => { @@ -268,8 +263,8 @@ describe('virtual router', () => { }); // THEN - expect(stack). - toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::Route', { RouteName: 'route-1', Spec: { HttpRoute: { @@ -290,8 +285,8 @@ describe('virtual router', () => { }, }); - expect(stack). - toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::Route', { RouteName: 'route-2', Spec: { HttpRoute: { @@ -312,8 +307,8 @@ describe('virtual router', () => { }, }); - expect(stack). - toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::Route', { RouteName: 'route-3', Spec: { HttpRoute: { @@ -333,8 +328,6 @@ describe('virtual router', () => { }, }, }); - - }); }); describe('When adding a TCP route to existing VirtualRouter', () => { @@ -374,8 +367,8 @@ describe('virtual router', () => { }); // THEN - expect(stack). - toHaveResourceLike('AWS::AppMesh::Route', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::Route', { RouteName: 'route-tcp-1', Spec: { TcpRoute: { @@ -395,8 +388,6 @@ describe('virtual router', () => { 'Fn::GetAtt': ['meshrouter81B8087E', 'VirtualRouterName'], }, }); - - }); }); @@ -414,8 +405,6 @@ describe('virtual router', () => { // THEN expect(virtualRouter.mesh.meshName).toEqual(meshName); expect(virtualRouter.virtualRouterName).toEqual(virtualRouterName); - - }); test('Can import Virtual Routers using attributes', () => { // GIVEN @@ -433,7 +422,5 @@ describe('virtual router', () => { // THEN expect(virtualRouter1.mesh.meshName).toEqual(meshName); expect(virtualRouter1.virtualRouterName).toEqual(virtualRouterName); - - }); }); diff --git a/packages/@aws-cdk/aws-appmesh/test/virtual-service.test.ts b/packages/@aws-cdk/aws-appmesh/test/virtual-service.test.ts index d74ad01920ef0..2cec646ed7377 100644 --- a/packages/@aws-cdk/aws-appmesh/test/virtual-service.test.ts +++ b/packages/@aws-cdk/aws-appmesh/test/virtual-service.test.ts @@ -1,7 +1,5 @@ -import '@aws-cdk/assert-internal/jest'; -import { ABSENT } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as cdk from '@aws-cdk/core'; - import * as appmesh from '../lib'; describe('virtual service', () => { @@ -17,8 +15,6 @@ describe('virtual service', () => { // THEN expect(virtualRouter.mesh.meshName).toEqual(meshName); expect(virtualRouter.virtualRouterName).toEqual(virtualServiceName); - - }); test('Can import Virtual Services using attributes', () => { @@ -36,8 +32,6 @@ describe('virtual service', () => { // THEN expect(virtualService.mesh.meshName).toEqual(meshName); expect(virtualService.virtualServiceName).toEqual(virtualServiceName); - - }); describe('When adding a VirtualService to a mesh', () => { @@ -63,8 +57,8 @@ describe('virtual service', () => { }); // THEN - expect(stack). - toHaveResource('AWS::AppMesh::VirtualService', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::VirtualService', { Spec: { Provider: { VirtualRouter: { @@ -74,10 +68,8 @@ describe('virtual service', () => { }, }, }, - MeshOwner: ABSENT, + MeshOwner: Match.absent(), }); - - }); }); @@ -104,8 +96,8 @@ describe('virtual service', () => { }); // THEN - expect(stack). - toHaveResource('AWS::AppMesh::VirtualService', { + Template.fromStack(stack). + hasResourceProperties('AWS::AppMesh::VirtualService', { Spec: { Provider: { VirtualNode: { @@ -116,8 +108,6 @@ describe('virtual service', () => { }, }, }); - - }); }); }); @@ -149,11 +139,9 @@ describe('virtual service', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::AppMesh::VirtualService', { + Template.fromStack(stack).hasResourceProperties('AWS::AppMesh::VirtualService', { MeshOwner: meshEnv.account, }); - - }); }); }); From 1963e6148d735d68f66803311196cc38b7d7fef8 Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Tue, 18 Jan 2022 15:23:08 -0500 Subject: [PATCH 5/9] chore(lambda): migrate tests to assertions --- packages/@aws-cdk/aws-lambda/package.json | 2 +- .../@aws-cdk/aws-lambda/test/alias.test.ts | 71 +++---- .../test/code-signing-config.test.ts | 10 +- .../@aws-cdk/aws-lambda/test/code.test.ts | 38 ++-- .../test/event-source-mapping.test.ts | 19 +- .../aws-lambda/test/function-hash.test.ts | 1 - .../@aws-cdk/aws-lambda/test/function.test.ts | 183 ++++++++---------- .../aws-lambda/test/lambda-insights.test.ts | 48 ++--- .../aws-lambda/test/lambda-version.test.ts | 12 +- .../@aws-cdk/aws-lambda/test/layers.test.ts | 21 +- .../@aws-cdk/aws-lambda/test/runtime.test.ts | 1 - .../aws-lambda/test/singleton-lambda.test.ts | 21 +- .../aws-lambda/test/vpc-lambda.test.ts | 22 +-- 13 files changed, 213 insertions(+), 236 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda/package.json b/packages/@aws-cdk/aws-lambda/package.json index a45dfbc33c284..cadb86ebca6b4 100644 --- a/packages/@aws-cdk/aws-lambda/package.json +++ b/packages/@aws-cdk/aws-lambda/package.json @@ -83,7 +83,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", diff --git a/packages/@aws-cdk/aws-lambda/test/alias.test.ts b/packages/@aws-cdk/aws-lambda/test/alias.test.ts index a470ace2a366a..2a37ffb285060 100644 --- a/packages/@aws-cdk/aws-lambda/test/alias.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/alias.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { arrayWith, objectLike } 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 { testDeprecated } from '@aws-cdk/cdk-build-tools'; @@ -22,11 +21,11 @@ describe('alias', () => { version, }); - expect(stack).toHaveResource('AWS::Lambda::Version', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Version', { FunctionName: { Ref: 'MyLambdaCCE802FB' }, }); - expect(stack).toHaveResource('AWS::Lambda::Alias', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Alias', { FunctionName: { Ref: 'MyLambdaCCE802FB' }, FunctionVersion: stack.resolve(version.version), Name: 'prod', @@ -46,12 +45,12 @@ describe('alias', () => { version: fn.latestVersion, }); - expect(stack).toHaveResource('AWS::Lambda::Alias', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Alias', { FunctionName: { Ref: 'MyLambdaCCE802FB' }, FunctionVersion: '$LATEST', Name: 'latest', }); - expect(stack).not.toHaveResource('AWS::Lambda::Version'); + Template.fromStack(stack).resourceCountIs('AWS::Lambda::Version', 0); }); testDeprecated('can use newVersion to create a new Version', () => { @@ -69,11 +68,11 @@ describe('alias', () => { version, }); - expect(stack).toHaveResourceLike('AWS::Lambda::Version', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Version', { FunctionName: { Ref: 'MyLambdaCCE802FB' }, }); - expect(stack).toHaveResourceLike('AWS::Lambda::Alias', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Alias', { FunctionName: { Ref: 'MyLambdaCCE802FB' }, Name: 'prod', }); @@ -97,7 +96,7 @@ describe('alias', () => { additionalVersions: [{ version: version2, weight: 0.1 }], }); - expect(stack).toHaveResource('AWS::Lambda::Alias', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Alias', { FunctionVersion: stack.resolve(version1.version), RoutingConfig: { AdditionalVersionWeights: [ @@ -127,13 +126,13 @@ describe('alias', () => { provisionedConcurrentExecutions: pce, }); - expect(stack).toHaveResource('AWS::Lambda::Version', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Version', { ProvisionedConcurrencyConfig: { ProvisionedConcurrentExecutions: 5, }, }); - expect(stack).toHaveResource('AWS::Lambda::Alias', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Alias', { FunctionVersion: stack.resolve(version.version), Name: 'prod', ProvisionedConcurrencyConfig: { @@ -194,7 +193,7 @@ describe('alias', () => { }); // THEN - expect(stack).toHaveResource('AWS::CloudWatch::Alarm', { + Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { Dimensions: [{ Name: 'FunctionName', Value: { @@ -325,7 +324,7 @@ describe('alias', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::EventInvokeConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventInvokeConfig', { FunctionName: { Ref: 'fn5FF616E3', }, @@ -384,7 +383,7 @@ describe('alias', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::EventInvokeConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventInvokeConfig', { FunctionName: 'function-name', Qualifier: 'alias-name', MaximumRetryAttempts: 1, @@ -409,22 +408,23 @@ describe('alias', () => { alias.addAutoScaling({ maxCapacity: 5 }); // THEN - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', { MinCapacity: 1, MaxCapacity: 5, - ResourceId: objectLike({ - 'Fn::Join': arrayWith(arrayWith( + ResourceId: Match.objectLike({ + 'Fn::Join': Match.arrayWith([Match.arrayWith([ 'function:', - objectLike({ - 'Fn::Select': arrayWith( + Match.objectLike({ + 'Fn::Select': Match.arrayWith([ { - 'Fn::Split': arrayWith( - { Ref: 'Alias325C5727' }), + 'Fn::Split': Match.arrayWith([ + { Ref: 'Alias325C5727' }, + ]), }, - ), + ]), }), ':prod', - )), + ])]), }), }); }); @@ -448,26 +448,27 @@ describe('alias', () => { alias.addAutoScaling({ maxCapacity: 5 }); // THEN - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', { MinCapacity: 1, MaxCapacity: 5, - ResourceId: objectLike({ - 'Fn::Join': arrayWith(arrayWith( + ResourceId: Match.objectLike({ + 'Fn::Join': Match.arrayWith([Match.arrayWith([ 'function:', - objectLike({ - 'Fn::Select': arrayWith( + Match.objectLike({ + 'Fn::Select': Match.arrayWith([ { - 'Fn::Split': arrayWith( - { Ref: 'Alias325C5727' }), + 'Fn::Split': Match.arrayWith([ + { Ref: 'Alias325C5727' }, + ]), }, - ), + ]), }), ':prod', - )), + ])]), }), }); - expect(stack).toHaveResourceLike('AWS::Lambda::Alias', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Alias', { ProvisionedConcurrencyConfig: { ProvisionedConcurrentExecutions: 10, }, @@ -495,7 +496,7 @@ describe('alias', () => { target.scaleOnUtilization({ utilizationTarget: Lazy.number({ produce: () => 0.95 }) }); // THEN: no exception - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', { PolicyType: 'TargetTrackingScaling', TargetTrackingScalingPolicyConfiguration: { PredefinedMetricSpecification: { PredefinedMetricType: 'LambdaProvisionedConcurrencyUtilization' }, @@ -568,7 +569,7 @@ describe('alias', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ApplicationAutoScaling::ScalableTarget', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', { ScheduledActions: [ { ScalableTargetAction: { MaxCapacity: 10 }, diff --git a/packages/@aws-cdk/aws-lambda/test/code-signing-config.test.ts b/packages/@aws-cdk/aws-lambda/test/code-signing-config.test.ts index 7b38e2cb7e178..68674b6f4bf6a 100644 --- a/packages/@aws-cdk/aws-lambda/test/code-signing-config.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/code-signing-config.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as signer from '@aws-cdk/aws-signer'; import * as cdk from '@aws-cdk/core'; import * as lambda from '../lib'; @@ -18,7 +18,7 @@ describe('code signing config', () => { signingProfiles: [signingProfile], }); - expect(stack).toHaveResource('AWS::Lambda::CodeSigningConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::CodeSigningConfig', { AllowedPublishers: { SigningProfileVersionArns: [{ 'Fn::GetAtt': [ @@ -41,7 +41,7 @@ describe('code signing config', () => { signingProfiles: [signingProfile1, signingProfile2, signingProfile3], }); - expect(stack).toHaveResource('AWS::Lambda::CodeSigningConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::CodeSigningConfig', { AllowedPublishers: { SigningProfileVersionArns: [ { @@ -76,7 +76,7 @@ describe('code signing config', () => { description: 'test description', }); - expect(stack).toHaveResource('AWS::Lambda::CodeSigningConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::CodeSigningConfig', { CodeSigningPolicies: { UntrustedArtifactOnDeployment: 'Enforce', }, @@ -91,7 +91,7 @@ describe('code signing config', () => { expect(codeSigningConfig.codeSigningConfigArn).toBe(codeSigningConfigArn); expect(codeSigningConfig.codeSigningConfigId).toBe(codeSigningConfigId); - expect(stack).toCountResources('AWS::Lambda::CodeSigningConfig', 0); + Template.fromStack(stack).resourceCountIs('AWS::Lambda::CodeSigningConfig', 0); }); test('fail import with malformed code signing config arn', () => { diff --git a/packages/@aws-cdk/aws-lambda/test/code.test.ts b/packages/@aws-cdk/aws-lambda/test/code.test.ts index 25e937b8e6415..76e771596d735 100644 --- a/packages/@aws-cdk/aws-lambda/test/code.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/code.test.ts @@ -1,6 +1,5 @@ -import '@aws-cdk/assert-internal/jest'; import * as path from 'path'; -import { ABSENT, ResourcePart } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as ecr from '@aws-cdk/aws-ecr'; import { testFutureBehavior } from '@aws-cdk/cdk-build-tools'; import * as cdk from '@aws-cdk/core'; @@ -20,6 +19,7 @@ describe('code', () => { .toThrow(/Lambda source is too large, must be <= 4096 but is 4097/); }); }); + describe('lambda.Code.fromAsset', () => { test('fails if a non-zip asset is used', () => { // GIVEN @@ -71,13 +71,13 @@ describe('code', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { Metadata: { [cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: 'asset.9678c34eca93259d11f2d714177347afd66c50116e1e08996eff893d3ca81232', [cxapi.ASSET_RESOURCE_METADATA_IS_BUNDLED_KEY]: false, [cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY]: 'Code', }, - }, ResourcePart.CompleteDefinition); + }); }); test('fails if asset is bound with a second stack', () => { @@ -111,7 +111,7 @@ describe('code', () => { handler: 'index.handler', }); - expect(stack).toHaveResourceLike('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Code: { S3Bucket: { Ref: 'FunctionLambdaSourceBucketNameParameter9E9E108F', @@ -157,7 +157,7 @@ describe('code', () => { handler: 'index.handler', }); - expect(stack).toHaveResourceLike('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Code: { S3Bucket: { Ref: 'BucketNameParam', @@ -207,11 +207,11 @@ describe('code', () => { }); // then - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Code: { ImageUri: stack.resolve(repo.repositoryUriForTag('latest')), }, - ImageConfig: ABSENT, + ImageConfig: Match.absent(), }); }); @@ -233,7 +233,7 @@ describe('code', () => { }); // then - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Code: { ImageUri: stack.resolve(repo.repositoryUriForTag('mytag')), }, @@ -258,7 +258,7 @@ describe('code', () => { }); // then - expect(stack).toHaveResourceLike('AWS::ECR::Repository', { + Template.fromStack(stack).hasResourceProperties('AWS::ECR::Repository', { RepositoryPolicyText: { Statement: [ { @@ -292,7 +292,7 @@ describe('code', () => { }); // then - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Code: { ImageUri: { 'Fn::Join': ['', [ @@ -305,7 +305,7 @@ describe('code', () => { ]], }, }, - ImageConfig: ABSENT, + ImageConfig: Match.absent(), }); }); @@ -325,7 +325,7 @@ describe('code', () => { }); // then - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { ImageConfig: { Command: ['cmd', 'param1'], EntryPoint: ['entrypoint', 'param2'], @@ -382,7 +382,7 @@ describe('code', () => { }); // then - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { Metadata: { [cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: 'asset.650a009a909c30e767a843a84ff7812616447251d245e0ab65d9bfb37f413e32', [cxapi.ASSET_RESOURCE_METADATA_DOCKERFILE_PATH_KEY]: dockerfilePath, @@ -390,7 +390,7 @@ describe('code', () => { [cxapi.ASSET_RESOURCE_METADATA_DOCKER_BUILD_TARGET_KEY]: dockerBuildTarget, [cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY]: 'Code.ImageUri', }, - }, ResourcePart.CompleteDefinition); + }); }); test('adds code asset metadata with default dockerfile path', () => { @@ -406,13 +406,13 @@ describe('code', () => { }); // then - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { Metadata: { [cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: 'asset.a3cc4528c34874616814d9b3436ff0e5d01514c1d563ed8899657ca00982f308', [cxapi.ASSET_RESOURCE_METADATA_DOCKERFILE_PATH_KEY]: 'Dockerfile', [cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY]: 'Code.ImageUri', }, - }, ResourcePart.CompleteDefinition); + }); }); test('fails if asset is bound with a second stack', () => { @@ -470,13 +470,13 @@ describe('code', () => { }); // then - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { Metadata: { [cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: 'asset.fbafdbb9ae8d1bae0def415b791a93c486d18ebc63270c748abecc3ac0ab9533', [cxapi.ASSET_RESOURCE_METADATA_IS_BUNDLED_KEY]: false, [cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY]: 'Code', }, - }, ResourcePart.CompleteDefinition); + }); expect(fromBuildMock).toHaveBeenCalledWith(path.join(__dirname, 'docker-build-lambda'), {}); expect(cpMock).toHaveBeenCalledWith('/asset/.', undefined); diff --git a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts index c974a7c82b4c4..793e9abb4c42d 100644 --- a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts @@ -1,5 +1,4 @@ -import { ABSENT } from '@aws-cdk/assert-internal'; -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as cdk from '@aws-cdk/core'; import { Code, EventSourceMapping, Function, Runtime } from '../lib'; @@ -165,7 +164,7 @@ describe('event source mapping', () => { kafkaTopic: topicNameParam.valueAsString, }); - expect(stack).toHaveResourceLike('AWS::Lambda::EventSourceMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventSourceMapping', { Topics: [{ Ref: 'TopicNameParam', }], @@ -234,7 +233,7 @@ describe('event source mapping', () => { kafkaTopic: topicNameParam.valueAsString, }); - expect(stack).toHaveResourceLike('AWS::Lambda::EventSourceMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventSourceMapping', { EventSourceArn: eventSourceArn, }); }); @@ -258,7 +257,7 @@ describe('event source mapping', () => { kafkaTopic: topicNameParam.valueAsString, }); - expect(stack).toHaveResourceLike('AWS::Lambda::EventSourceMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventSourceMapping', { SelfManagedEventSource: { Endpoints: { KafkaBootstrapServers: kafkaBootstrapServers } }, }); }); @@ -309,7 +308,7 @@ describe('event source mapping', () => { reportBatchItemFailures: true, }); - expect(stack).toHaveResourceLike('AWS::Lambda::EventSourceMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventSourceMapping', { FunctionResponseTypes: ['ReportBatchItemFailures'], }); }); @@ -328,8 +327,8 @@ describe('event source mapping', () => { eventSourceArn: '', }); - expect(stack).toHaveResourceLike('AWS::Lambda::EventSourceMapping', { - FunctionResponseTypes: ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventSourceMapping', { + FunctionResponseTypes: Match.absent(), }); }); @@ -348,8 +347,8 @@ describe('event source mapping', () => { reportBatchItemFailures: false, }); - expect(stack).toHaveResourceLike('AWS::Lambda::EventSourceMapping', { - FunctionResponseTypes: ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventSourceMapping', { + FunctionResponseTypes: Match.absent(), }); }); }); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda/test/function-hash.test.ts b/packages/@aws-cdk/aws-lambda/test/function-hash.test.ts index dbadd01b0975b..de07180924ef5 100644 --- a/packages/@aws-cdk/aws-lambda/test/function-hash.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/function-hash.test.ts @@ -1,4 +1,3 @@ -import '@aws-cdk/assert-internal/jest'; import * as path from 'path'; import { resourceSpecification } from '@aws-cdk/cfnspec'; import { App, CfnOutput, CfnResource, Stack } from '@aws-cdk/core'; diff --git a/packages/@aws-cdk/aws-lambda/test/function.test.ts b/packages/@aws-cdk/aws-lambda/test/function.test.ts index 04a8ab862b5b7..d4f1af8f02cf0 100644 --- a/packages/@aws-cdk/aws-lambda/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/function.test.ts @@ -1,6 +1,5 @@ -import '@aws-cdk/assert-internal/jest'; import * as path from 'path'; -import { ABSENT, ResourcePart, SynthUtils } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import { ProfilingGroup } from '@aws-cdk/aws-codeguruprofiler'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as efs from '@aws-cdk/aws-efs'; @@ -26,7 +25,7 @@ describe('function', () => { runtime: lambda.Runtime.NODEJS_10_X, }); - expect(stack).toHaveResource('AWS::IAM::Role', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: @@ -41,7 +40,7 @@ describe('function', () => { [{ 'Fn::Join': ['', ['arn:', { Ref: 'AWS::Partition' }, ':iam::aws:policy/service-role/AWSLambdaBasicExecutionRole']] }], }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { Properties: { Code: { ZipFile: 'foo' }, @@ -50,7 +49,7 @@ describe('function', () => { Runtime: 'nodejs10.x', }, DependsOn: ['MyLambdaServiceRole4539ECB6'], - }, ResourcePart.CompleteDefinition); + }); }); test('adds policy permissions', () => { @@ -61,7 +60,7 @@ describe('function', () => { runtime: lambda.Runtime.NODEJS_10_X, initialPolicy: [new iam.PolicyStatement({ actions: ['*'], resources: ['*'] })], }); - expect(stack).toHaveResource('AWS::IAM::Role', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: @@ -76,7 +75,7 @@ describe('function', () => { // eslint-disable-next-line max-len [{ 'Fn::Join': ['', ['arn:', { Ref: 'AWS::Partition' }, ':iam::aws:policy/service-role/AWSLambdaBasicExecutionRole']] }], }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -95,7 +94,7 @@ describe('function', () => { ], }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { Properties: { Code: { ZipFile: 'foo' }, Handler: 'index.handler', @@ -103,7 +102,7 @@ describe('function', () => { Runtime: 'nodejs10.x', }, DependsOn: ['MyLambdaServiceRoleDefaultPolicy5BBC6F68', 'MyLambdaServiceRole4539ECB6'], - }, ResourcePart.CompleteDefinition); + }); }); test('fails if inline code is used for an invalid runtime', () => { @@ -127,7 +126,7 @@ describe('function', () => { sourceArn: 'arn:aws:s3:::my_bucket', }); - expect(stack).toHaveResource('AWS::IAM::Role', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: [ { @@ -145,7 +144,7 @@ describe('function', () => { [{ 'Fn::Join': ['', ['arn:', { Ref: 'AWS::Partition' }, ':iam::aws:policy/service-role/AWSLambdaBasicExecutionRole']] }], }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { Properties: { Code: { ZipFile: 'foo', @@ -162,9 +161,9 @@ describe('function', () => { DependsOn: [ 'MyLambdaServiceRole4539ECB6', ], - }, ResourcePart.CompleteDefinition); + }); - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { Action: 'lambda:*', FunctionName: { 'Fn::GetAtt': [ @@ -209,7 +208,7 @@ describe('function', () => { fn.addPermission('S1', { principal: principal }); - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { Action: 'lambda:InvokeFunction', FunctionName: { 'Fn::GetAtt': [ @@ -272,7 +271,7 @@ describe('function', () => { fn.addToRolePolicy(new iam.PolicyStatement({ actions: ['explicit:explicit'], resources: ['*'] })); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Version: '2012-10-17', Statement: [ @@ -343,7 +342,7 @@ describe('function', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::Permission'); + Template.fromStack(stack).resourceCountIs('AWS::Lambda::Permission', 1); }); test('imported Function w/ unresolved account', () => { @@ -360,7 +359,7 @@ describe('function', () => { }); // THEN - expect(stack).not.toHaveResource('AWS::Lambda::Permission'); + Template.fromStack(stack).resourceCountIs('AWS::Lambda::Permission', 0); }); test('imported Function w/ unresolved account & allowPermissions set', () => { @@ -378,7 +377,7 @@ describe('function', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::Permission'); + Template.fromStack(stack).resourceCountIs('AWS::Lambda::Permission', 1); }); test('imported Function w/different account', () => { @@ -397,7 +396,7 @@ describe('function', () => { }); // THEN - expect(stack).not.toHaveResource('AWS::Lambda::Permission'); + Template.fromStack(stack).resourceCountIs('AWS::Lambda::Permission', 0); }); }); @@ -411,7 +410,7 @@ describe('function', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Code: { S3Bucket: { Ref: 'AssetParameters9678c34eca93259d11f2d714177347afd66c50116e1e08996eff893d3ca81232S3Bucket1354C645', @@ -445,7 +444,7 @@ describe('function', () => { deadLetterQueueEnabled: true, }); - expect(stack).toHaveResource('AWS::IAM::Role', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: [ { @@ -473,7 +472,7 @@ describe('function', () => { }, ], }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -496,7 +495,7 @@ describe('function', () => { }, ], }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { Properties: { Code: { ZipFile: 'foo', @@ -523,7 +522,7 @@ describe('function', () => { 'MyLambdaServiceRoleDefaultPolicy5BBC6F68', 'MyLambdaServiceRole4539ECB6', ], - }, ResourcePart.CompleteDefinition); + }); }); test('default function with SQS DLQ when client sets deadLetterQueueEnabled to true and functionName not defined by client', () => { @@ -536,11 +535,11 @@ describe('function', () => { deadLetterQueueEnabled: true, }); - expect(stack).toHaveResource('AWS::SQS::Queue', { + Template.fromStack(stack).hasResourceProperties('AWS::SQS::Queue', { MessageRetentionPeriod: 1209600, }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { DeadLetterConfig: { TargetArn: { 'Fn::GetAtt': [ @@ -562,7 +561,7 @@ describe('function', () => { deadLetterQueueEnabled: false, }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Code: { ZipFile: 'foo', }, @@ -592,7 +591,7 @@ describe('function', () => { deadLetterQueue: dlQueue, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -610,7 +609,7 @@ describe('function', () => { }, }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { DeadLetterConfig: { TargetArn: { 'Fn::GetAtt': [ @@ -638,7 +637,7 @@ describe('function', () => { deadLetterQueue: dlQueue, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -656,7 +655,7 @@ describe('function', () => { }, }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { DeadLetterConfig: { TargetArn: { 'Fn::GetAtt': [ @@ -695,7 +694,7 @@ describe('function', () => { tracing: lambda.Tracing.ACTIVE, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -717,7 +716,7 @@ describe('function', () => { ], }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { Properties: { Code: { ZipFile: 'foo', @@ -738,7 +737,7 @@ describe('function', () => { 'MyLambdaServiceRoleDefaultPolicy5BBC6F68', 'MyLambdaServiceRole4539ECB6', ], - }, ResourcePart.CompleteDefinition); + }); }); test('default function with PassThrough tracing', () => { @@ -751,7 +750,7 @@ describe('function', () => { tracing: lambda.Tracing.PASS_THROUGH, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -773,7 +772,7 @@ describe('function', () => { ], }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { Properties: { Code: { ZipFile: 'foo', @@ -794,7 +793,7 @@ describe('function', () => { 'MyLambdaServiceRoleDefaultPolicy5BBC6F68', 'MyLambdaServiceRole4539ECB6', ], - }, ResourcePart.CompleteDefinition); + }); }); test('default function with Disabled tracing', () => { @@ -807,29 +806,9 @@ describe('function', () => { tracing: lambda.Tracing.DISABLED, }); - expect(stack).not.toHaveResource('AWS::IAM::Policy', { - PolicyDocument: { - Statement: [ - { - Action: [ - 'xray:PutTraceSegments', - 'xray:PutTelemetryRecords', - ], - Effect: 'Allow', - Resource: '*', - }, - ], - Version: '2012-10-17', - }, - PolicyName: 'MyLambdaServiceRoleDefaultPolicy5BBC6F68', - Roles: [ - { - Ref: 'MyLambdaServiceRole4539ECB6', - }, - ], - }); + Template.fromStack(stack).resourceCountIs('AWS::IAM::Policy', 0); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { Properties: { Code: { ZipFile: 'foo', @@ -846,7 +825,7 @@ describe('function', () => { DependsOn: [ 'MyLambdaServiceRole4539ECB6', ], - }, ResourcePart.CompleteDefinition); + }); }); test('runtime and handler set to FROM_IMAGE are set to undefined in CloudFormation', () => { @@ -858,9 +837,9 @@ describe('function', () => { runtime: lambda.Runtime.FROM_IMAGE, }); - expect(stack).toHaveResource('AWS::Lambda::Function', { - Runtime: ABSENT, - Handler: ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { + Runtime: Match.absent(), + Handler: Match.absent(), PackageType: 'Image', }); }); @@ -883,7 +862,7 @@ describe('function', () => { fn.grantInvoke(role); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Version: '2012-10-17', Statement: [ @@ -911,7 +890,7 @@ describe('function', () => { fn.grantInvoke(service); // THEN - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { Action: 'lambda:InvokeFunction', FunctionName: { 'Fn::GetAtt': [ @@ -937,7 +916,7 @@ describe('function', () => { fn.grantInvoke(account); // THEN - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { Action: 'lambda:InvokeFunction', FunctionName: { 'Fn::GetAtt': [ @@ -963,7 +942,7 @@ describe('function', () => { fn.grantInvoke(account); // THEN - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { Action: 'lambda:InvokeFunction', FunctionName: { 'Fn::GetAtt': [ @@ -990,7 +969,7 @@ describe('function', () => { fn.grantInvoke(service); // THEN - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { Action: 'lambda:InvokeFunction', FunctionName: { 'Fn::GetAtt': [ @@ -1017,7 +996,7 @@ describe('function', () => { fn.grantInvoke(iam.Role.fromRoleArn(stack, 'ForeignRole', 'arn:aws:iam::123456789012:role/someRole')); // THEN - expect(stack).toHaveResourceLike('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -1046,7 +1025,7 @@ describe('function', () => { fn.grantInvoke(iam.Role.fromRoleArn(stack, 'ForeignRole', 'arn:aws:iam::123456789012:role/someRole')); // THEN - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { Action: 'lambda:InvokeFunction', FunctionName: { 'Fn::GetAtt': [ @@ -1069,7 +1048,7 @@ describe('function', () => { fn.grantInvoke(new iam.ServicePrincipal('elasticloadbalancing.amazonaws.com')); // THEN - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { Action: 'lambda:InvokeFunction', FunctionName: 'arn:aws:lambda:us-east-1:123456789012:function:MyFn', Principal: 'elasticloadbalancing.amazonaws.com', @@ -1097,7 +1076,7 @@ describe('function', () => { fn.grantInvoke(new iam.ServicePrincipal('elasticloadbalancing.amazonaws.com')); // THEN - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { Action: 'lambda:InvokeFunction', FunctionName: 'arn:aws:lambda:us-east-1:123456789012:function:MyFn', Principal: 'elasticloadbalancing.amazonaws.com', @@ -1209,7 +1188,7 @@ describe('function', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Environment: { Variables: { SOME: 'Variable', @@ -1233,7 +1212,7 @@ describe('function', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Environment: { Variables: { SOME: 'Variable', @@ -1252,7 +1231,7 @@ describe('function', () => { reservedConcurrentExecutions: 10, }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { ReservedConcurrentExecutions: 10, }); }); @@ -1304,7 +1283,7 @@ describe('function', () => { }); // THEN - expect(stack).toHaveResource('Custom::LogRetention', { + Template.fromStack(stack).hasResourceProperties('Custom::LogRetention', { LogGroupName: { 'Fn::Join': [ '', @@ -1335,7 +1314,7 @@ describe('function', () => { fn.connections.allowToAnyIpv4(ec2.Port.tcp(443)); // THEN - expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupEgress', { GroupId: 'sg-123456789', }); }); @@ -1360,7 +1339,7 @@ describe('function', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::EventInvokeConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventInvokeConfig', { FunctionName: { Ref: 'fn5FF616E3', }, @@ -1405,7 +1384,7 @@ describe('function', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::EventInvokeConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventInvokeConfig', { FunctionName: 'my-function', Qualifier: '$LATEST', MaximumRetryAttempts: 1, @@ -1427,7 +1406,7 @@ describe('function', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::EventInvokeConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventInvokeConfig', { FunctionName: { Ref: 'fn5FF616E3', }, @@ -1455,8 +1434,8 @@ describe('function', () => { fn._checkEdgeCompatibility(); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { - Environment: ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { + Environment: Match.absent(), }); }); @@ -1678,7 +1657,7 @@ describe('function', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Environment: { Variables: { SOME: 'Variable', @@ -1704,12 +1683,12 @@ describe('function', () => { profiling: true, }); - expect(stack).toHaveResource('AWS::CodeGuruProfiler::ProfilingGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::CodeGuruProfiler::ProfilingGroup', { ProfilingGroupName: 'MyLambdaProfilingGroupC5B6CCD8', ComputePlatform: 'AWSLambda', }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -1733,7 +1712,7 @@ describe('function', () => { ], }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Environment: { Variables: { AWS_CODEGURU_PROFILER_GROUP_ARN: { 'Fn::GetAtt': ['MyLambdaProfilingGroupEC6DE32F', 'Arn'] }, @@ -1753,7 +1732,7 @@ describe('function', () => { profilingGroup: new ProfilingGroup(stack, 'ProfilingGroup'), }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -1777,7 +1756,7 @@ describe('function', () => { ], }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Environment: { Variables: { AWS_CODEGURU_PROFILER_GROUP_ARN: { @@ -1806,9 +1785,9 @@ describe('function', () => { profilingGroup: new ProfilingGroup(stack, 'ProfilingGroup'), }); - expect(stack).not.toHaveResource('AWS::IAM::Policy'); + Template.fromStack(stack).resourceCountIs('AWS::IAM::Policy', 0); - expect(stack).not.toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', Match.not({ Environment: { Variables: { AWS_CODEGURU_PROFILER_GROUP_ARN: { @@ -1823,7 +1802,7 @@ describe('function', () => { AWS_CODEGURU_PROFILER_ENABLED: 'TRUE', }, }, - }); + })); }); test('default function with profiling enabled and client provided env vars', () => { @@ -1936,8 +1915,8 @@ describe('function', () => { }); // THEN - const template1 = SynthUtils.synthesize(stack1).template; - const template2 = SynthUtils.synthesize(stack2).template; + const template1 = Template.fromStack(stack1).toJSON(); + const template2 = Template.fromStack(stack2).toJSON(); // these functions are different in their configuration but the original // logical ID of the version would be the same unless the logical ID @@ -1970,7 +1949,7 @@ describe('function', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { FileSystemConfigs: [ { Arn: { @@ -2053,7 +2032,7 @@ describe('function', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { DependsOn: [ 'EfsEfsMountTarget195B2DD2E', 'EfsEfsMountTarget2315C927F', @@ -2062,7 +2041,7 @@ describe('function', () => { 'MyFunctionServiceRoleDefaultPolicyB705ABD4', 'MyFunctionServiceRole3C357FF2', ], - }, ResourcePart.CompleteDefinition); + }); }); }); @@ -2158,11 +2137,11 @@ describe('function', () => { runtime: lambda.Runtime.FROM_IMAGE, }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Code: { ImageUri: 'ecr image uri', }, - ImageConfig: ABSENT, + ImageConfig: Match.absent(), }); }); @@ -2182,7 +2161,7 @@ describe('function', () => { runtime: lambda.Runtime.FROM_IMAGE, }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { ImageConfig: { Command: ['cmd', 'param1'], EntryPoint: ['entrypoint', 'param2'], @@ -2211,7 +2190,7 @@ describe('function', () => { codeSigningConfig, }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { CodeSigningConfigArn: { 'Fn::GetAtt': [ 'CodeSigningConfigD8D41C10', @@ -2247,7 +2226,7 @@ describe('function', () => { architectures: [lambda.Architecture.ARM_64], }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Architectures: ['arm64'], }); }); @@ -2262,7 +2241,7 @@ describe('function', () => { architecture: lambda.Architecture.ARM_64, }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Architectures: ['arm64'], }); }); diff --git a/packages/@aws-cdk/aws-lambda/test/lambda-insights.test.ts b/packages/@aws-cdk/aws-lambda/test/lambda-insights.test.ts index 581106e7a1f92..761d7262b412e 100644 --- a/packages/@aws-cdk/aws-lambda/test/lambda-insights.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/lambda-insights.test.ts @@ -1,9 +1,8 @@ -import '@aws-cdk/assert-internal/jest'; -import { arrayWith, 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 lambda from '../lib'; import { Fact, FactName } from '@aws-cdk/region-info'; +import * as lambda from '../lib'; /** * Boilerplate code to create a Function with a given insights version @@ -28,7 +27,7 @@ function functionWithInsightsVersion( * Check if the function's Role has the Lambda Insights IAM policy */ function verifyRoleHasCorrectPolicies(stack: cdk.Stack) { - expect(stack).toHaveResource('AWS::IAM::Role', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { ManagedPolicyArns: [ { 'Fn::Join': ['', ['arn:', { Ref: 'AWS::Partition' }, ':iam::aws:policy/service-role/AWSLambdaBasicExecutionRole']] }, @@ -47,7 +46,7 @@ describe('lambda-insights', () => { verifyRoleHasCorrectPolicies(stack); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Layers: [layerArn], }); @@ -64,7 +63,7 @@ describe('lambda-insights', () => { verifyRoleHasCorrectPolicies(stack); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Layers: ['arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:2'], }); @@ -91,7 +90,7 @@ describe('lambda-insights', () => { functionWithInsightsVersion(stack, 'MyLambda', lambda.LambdaInsightsVersion.VERSION_1_0_98_0); // Still resolves because all elements of the mapping map to the same value - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Layers: [{ 'Fn::FindInMap': [ 'CloudwatchlambdainsightsversionMap', @@ -115,23 +114,24 @@ describe('lambda-insights', () => { functionWithInsightsVersion(stack, 'MyLambda1', lambda.LambdaInsightsVersion.VERSION_1_0_98_0); functionWithInsightsVersion(stack, 'MyLambda2', lambda.LambdaInsightsVersion.VERSION_1_0_98_0); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { FunctionName: 'MyLambda1', Layers: [{ 'Fn::FindInMap': ['CloudwatchlambdainsightsversionMap', { Ref: 'AWS::Region' }, '1_0_98_0_x86_64'], }], }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { FunctionName: 'MyLambda2', Layers: [{ 'Fn::FindInMap': ['CloudwatchlambdainsightsversionMap', { Ref: 'AWS::Region' }, '1_0_98_0_x86_64'], }], }); - const template = SynthUtils.toCloudFormation(stack); - expect(template.Mappings.CloudwatchlambdainsightsversionMap?.['af-south-1']).toEqual({ - '1_0_98_0_x86_64': 'arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:8', + Template.fromStack(stack).hasMapping('CloudwatchlambdainsightsversionMap', { + 'af-south-1': { + '1_0_98_0_x86_64': 'arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:8', + }, }); // On synthesis it should not throw an error @@ -146,18 +146,19 @@ describe('lambda-insights', () => { insightsVersion: lambda.LambdaInsightsVersion.VERSION_1_0_98_0, }); - expect(stack).toCountResources('AWS::Lambda::LayerVersion', 0); + Template.fromStack(stack).resourceCountIs('AWS::Lambda::LayerVersion', 0); - expect(stack).toHaveResourceLike('AWS::IAM::Role', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: [ { Action: 'sts:AssumeRole', + Effect: 'Allow', Principal: { Service: 'lambda.amazonaws.com' }, }, ], }, - ManagedPolicyArns: arrayWith( + ManagedPolicyArns: Match.arrayWith([ { 'Fn::Join': ['', [ 'arn:', @@ -165,7 +166,7 @@ describe('lambda-insights', () => { ':iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy', ]], }, - ), + ]), }); }); @@ -176,7 +177,7 @@ describe('lambda-insights', () => { }); functionWithInsightsVersion(stack, 'MyLambda', lambda.LambdaInsightsVersion.VERSION_1_0_119_0, lambda.Architecture.ARM_64); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Layers: ['arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:1'], }); @@ -214,24 +215,25 @@ describe('lambda-insights', () => { functionWithInsightsVersion(stack, 'MyLambda1', lambda.LambdaInsightsVersion.VERSION_1_0_119_0); functionWithInsightsVersion(stack, 'MyLambda2', lambda.LambdaInsightsVersion.VERSION_1_0_119_0, lambda.Architecture.ARM_64); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { FunctionName: 'MyLambda1', Layers: [{ 'Fn::FindInMap': ['CloudwatchlambdainsightsversionMap', { Ref: 'AWS::Region' }, '1_0_119_0_x86_64'], }], }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { FunctionName: 'MyLambda2', Layers: [{ 'Fn::FindInMap': ['CloudwatchlambdainsightsversionMap', { Ref: 'AWS::Region' }, '1_0_119_0_arm64'], }], }); - const template = SynthUtils.toCloudFormation(stack); - expect(template.Mappings.CloudwatchlambdainsightsversionMap?.['ap-south-1']).toEqual({ - '1_0_119_0_x86_64': 'arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:16', - '1_0_119_0_arm64': 'arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:1', + Template.fromStack(stack).hasMapping('CloudwatchlambdainsightsversionMap', { + 'ap-south-1': { + '1_0_119_0_x86_64': 'arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:16', + '1_0_119_0_arm64': 'arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:1', + }, }); // On synthesis it should not throw an error diff --git a/packages/@aws-cdk/aws-lambda/test/lambda-version.test.ts b/packages/@aws-cdk/aws-lambda/test/lambda-version.test.ts index c5daabab66b5d..ed98e802998dd 100644 --- a/packages/@aws-cdk/aws-lambda/test/lambda-version.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/lambda-version.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 lambda from '../lib'; @@ -14,7 +14,7 @@ describe('lambda version', () => { new cdk.CfnOutput(stack, 'Name', { value: version.functionName }); // THEN - expect(stack).toMatchTemplate({ + Template.fromStack(stack).templateMatches({ Outputs: { ARN: { Value: 'arn:aws:lambda:region:account-id:function:function-name:version', @@ -43,7 +43,7 @@ describe('lambda version', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::EventInvokeConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventInvokeConfig', { FunctionName: { Ref: 'Fn9270CBC0', }, @@ -91,12 +91,12 @@ describe('lambda version', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::EventInvokeConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventInvokeConfig', { FunctionName: 'function-name', Qualifier: 'version1', MaximumRetryAttempts: 1, }); - expect(stack).toHaveResource('AWS::Lambda::EventInvokeConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventInvokeConfig', { FunctionName: 'function-name', Qualifier: 'version2', MaximumRetryAttempts: 0, @@ -117,7 +117,7 @@ describe('lambda version', () => { version.addAlias('foo'); // THEN - expect(stack).toHaveResource('AWS::Lambda::Alias', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Alias', { FunctionName: { Ref: 'Fn9270CBC0', }, diff --git a/packages/@aws-cdk/aws-lambda/test/layers.test.ts b/packages/@aws-cdk/aws-lambda/test/layers.test.ts index c8c700585c686..5f818c480e2da 100644 --- a/packages/@aws-cdk/aws-lambda/test/layers.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/layers.test.ts @@ -1,6 +1,5 @@ -import '@aws-cdk/assert-internal/jest'; import * as path from 'path'; -import { canonicalizeTemplate, ResourcePart, SynthUtils } from '@aws-cdk/assert-internal'; +import { Template } from '@aws-cdk/assertions'; import * as s3 from '@aws-cdk/aws-s3'; import * as cdk from '@aws-cdk/core'; import * as cxapi from '@aws-cdk/cx-api'; @@ -20,7 +19,7 @@ describe('layers', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::LayerVersion', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', { Content: { S3Bucket: stack.resolve(bucket.bucketName), S3Key: 'ObjectKey', @@ -44,12 +43,12 @@ describe('layers', () => { layer.addPermission('GrantUsage-o-123456', { accountId: '*', organizationId: 'o-123456' }); // THEN - expect(stack).toHaveResource('AWS::Lambda::LayerVersionPermission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersionPermission', { Action: 'lambda:GetLayerVersion', LayerVersionArn: stack.resolve(layer.layerVersionArn), Principal: '123456789012', }); - expect(stack).toHaveResource('AWS::Lambda::LayerVersionPermission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersionPermission', { Action: 'lambda:GetLayerVersion', LayerVersionArn: stack.resolve(layer.layerVersionArn), Principal: '*', @@ -79,13 +78,13 @@ describe('layers', () => { }); // THEN - expect(canonicalizeTemplate(SynthUtils.toCloudFormation(stack))).toHaveResource('AWS::Lambda::LayerVersion', { + Template.fromStack(stack).hasResource('AWS::Lambda::LayerVersion', { Metadata: { - 'aws:asset:path': 'asset.Asset1Hash', + 'aws:asset:path': 'asset.8811a2632ac5564a08fd269e159298f7e497f259578b0dc5e927a1f48ab24d34', 'aws:asset:is-bundled': false, 'aws:asset:property': 'Content', }, - }, ResourcePart.CompleteDefinition); + }); }); test('creating a layer with a removal policy', () => { @@ -99,10 +98,10 @@ describe('layers', () => { }); // THEN - expect(canonicalizeTemplate(SynthUtils.toCloudFormation(stack))).toHaveResource('AWS::Lambda::LayerVersion', { + Template.fromStack(stack).hasResource('AWS::Lambda::LayerVersion', { UpdateReplacePolicy: 'Retain', DeletionPolicy: 'Retain', - }, ResourcePart.CompleteDefinition); + }); }); test('specified compatible architectures is recognized', () => { @@ -114,7 +113,7 @@ describe('layers', () => { compatibleArchitectures: [lambda.Architecture.ARM_64], }); - expect(stack).toHaveResource('AWS::Lambda::LayerVersion', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', { CompatibleArchitectures: ['arm64'], }); }); diff --git a/packages/@aws-cdk/aws-lambda/test/runtime.test.ts b/packages/@aws-cdk/aws-lambda/test/runtime.test.ts index 17203a11f9d7e..f3976e70c4327 100644 --- a/packages/@aws-cdk/aws-lambda/test/runtime.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/runtime.test.ts @@ -1,4 +1,3 @@ -import '@aws-cdk/assert-internal/jest'; import * as lambda from '../lib'; describe('runtime', () => { diff --git a/packages/@aws-cdk/aws-lambda/test/singleton-lambda.test.ts b/packages/@aws-cdk/aws-lambda/test/singleton-lambda.test.ts index 1e9f984b4aee5..3e6db8d6ea422 100644 --- a/packages/@aws-cdk/aws-lambda/test/singleton-lambda.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/singleton-lambda.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { ResourcePart } from '@aws-cdk/assert-internal'; +import { Template } from '@aws-cdk/assertions'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as iam from '@aws-cdk/aws-iam'; import * as s3 from '@aws-cdk/aws-s3'; @@ -23,7 +22,7 @@ describe('singleton lambda', () => { } // THEN - expect(stack).toMatchTemplate({ + Template.fromStack(stack).templateMatches({ Resources: { SingletonLambda84c0de93353f42179b0b45b6c993251aServiceRole26D59235: { Type: 'AWS::IAM::Role', @@ -78,12 +77,12 @@ describe('singleton lambda', () => { singleton.addDependency(dependency); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { DependsOn: [ 'dependencyUser1B9CB07E', 'SingletonLambda84c0de93353f42179b0b45b6c993251aServiceRole26D59235', ], - }, ResourcePart.CompleteDefinition); + }); }); test('dependsOn are correctly added', () => { @@ -102,12 +101,12 @@ describe('singleton lambda', () => { singleton.dependOn(user); // THEN - expect(stack).toHaveResource('AWS::IAM::User', { + Template.fromStack(stack).hasResource('AWS::IAM::User', { DependsOn: [ 'SingletonLambda84c0de93353f42179b0b45b6c993251a840BCC38', 'SingletonLambda84c0de93353f42179b0b45b6c993251aServiceRole26D59235', ], - }, ResourcePart.CompleteDefinition); + }); }); test('Environment is added to Lambda, when .addEnvironment() is provided one key pair', () => { @@ -125,7 +124,7 @@ describe('singleton lambda', () => { singleton.addEnvironment('KEY', 'value'); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Environment: { Variables: { KEY: 'value', @@ -154,7 +153,7 @@ describe('singleton lambda', () => { singleton.addLayers(layer); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Layers: [{ Ref: 'myLayerBA1B098A', }], @@ -176,7 +175,7 @@ describe('singleton lambda', () => { const statement = stack.resolve(invokeResult.resourceStatement); // THEN - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { Action: 'lambda:InvokeFunction', Principal: 'events.amazonaws.com', }); @@ -256,7 +255,7 @@ describe('singleton lambda', () => { version.addAlias('foo'); // THEN - expect(stack).toHaveResource('AWS::Lambda::Version', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Version', { FunctionName: { Ref: 'SingletonLambda84c0de93353f42179b0b45b6c993251a840BCC38', }, diff --git a/packages/@aws-cdk/aws-lambda/test/vpc-lambda.test.ts b/packages/@aws-cdk/aws-lambda/test/vpc-lambda.test.ts index 409ffc5fa3a45..aa7587411fa26 100644 --- a/packages/@aws-cdk/aws-lambda/test/vpc-lambda.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/vpc-lambda.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 { testDeprecated } from '@aws-cdk/cdk-build-tools'; import * as cdk from '@aws-cdk/core'; @@ -29,7 +29,7 @@ describe('lambda + vpc', () => { test('has subnet and securitygroup', () => { // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { VpcConfig: { SecurityGroupIds: [ { 'Fn::GetAtt': ['LambdaSecurityGroupE74659A1', 'GroupId'] }, @@ -52,7 +52,7 @@ describe('lambda + vpc', () => { securityGroup: new ec2.SecurityGroup(stack, 'CustomSecurityGroupX', { vpc }), }); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { VpcConfig: { SecurityGroupIds: [ { 'Fn::GetAtt': ['CustomSecurityGroupX6C7F3A78', 'GroupId'] }, @@ -78,7 +78,7 @@ describe('lambda + vpc', () => { ], }); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { VpcConfig: { SecurityGroupIds: [ { 'Fn::GetAtt': ['CustomSecurityGroupA267F62DE', 'GroupId'] }, @@ -118,7 +118,7 @@ describe('lambda + vpc', () => { fn.connections.allowTo(somethingConnectable, ec2.Port.allTcp(), 'Lambda can call connectable'); // THEN: Lambda can connect to SomeSecurityGroup - expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupEgress', { GroupId: { 'Fn::GetAtt': ['LambdaSecurityGroupE74659A1', 'GroupId'] }, IpProtocol: 'tcp', Description: 'Lambda can call connectable', @@ -128,7 +128,7 @@ describe('lambda + vpc', () => { }); // THEN: SomeSecurityGroup accepts connections from Lambda - expect(stack).toHaveResource('AWS::EC2::SecurityGroupIngress', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroupIngress', { IpProtocol: 'tcp', Description: 'Lambda can call connectable', FromPort: 0, @@ -148,7 +148,7 @@ describe('lambda + vpc', () => { somethingConnectable.connections.allowFrom(fn.connections, ec2.Port.allTcp(), 'Lambda can call connectable'); // THEN: SomeSecurityGroup accepts connections from Lambda - expect(stack2).toHaveResource('AWS::EC2::SecurityGroupEgress', { + Template.fromStack(stack2).hasResourceProperties('AWS::EC2::SecurityGroupEgress', { GroupId: { 'Fn::ImportValue': 'stack:ExportsOutputFnGetAttLambdaSecurityGroupE74659A1GroupId8F3EC6F1', }, @@ -165,7 +165,7 @@ describe('lambda + vpc', () => { }); // THEN: Lambda can connect to SomeSecurityGroup - expect(stack2).toHaveResource('AWS::EC2::SecurityGroupIngress', { + Template.fromStack(stack2).hasResourceProperties('AWS::EC2::SecurityGroupIngress', { IpProtocol: 'tcp', Description: 'Lambda can call connectable', FromPort: 0, @@ -214,7 +214,7 @@ describe('lambda + vpc', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { VpcConfig: { SecurityGroupIds: [ { 'Fn::GetAtt': ['PublicLambdaSecurityGroup61D896FD', 'GroupId'] }, @@ -243,7 +243,7 @@ describe('lambda + vpc', () => { // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { VpcConfig: { SecurityGroupIds: [ { 'Fn::GetAtt': ['PrivateLambdaSecurityGroupF53C8342', 'GroupId'] }, @@ -279,7 +279,7 @@ describe('lambda + vpc', () => { // THEN - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { VpcConfig: { SecurityGroupIds: [ { 'Fn::GetAtt': ['IsolatedLambdaSecurityGroupCE25B6A9', 'GroupId'] }, From c7644706d6714734d6c1b66369531008c4668820 Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Tue, 18 Jan 2022 15:25:04 -0500 Subject: [PATCH 6/9] chore(lambda-layer-node-proxy-agent): migrate tests to assertions --- packages/@aws-cdk/lambda-layer-node-proxy-agent/package.json | 2 +- .../test/proxy-agent-layer.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/lambda-layer-node-proxy-agent/package.json b/packages/@aws-cdk/lambda-layer-node-proxy-agent/package.json index 010c9e517040f..b4e0211270c66 100644 --- a/packages/@aws-cdk/lambda-layer-node-proxy-agent/package.json +++ b/packages/@aws-cdk/lambda-layer-node-proxy-agent/package.json @@ -66,7 +66,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/pkglint": "0.0.0", diff --git a/packages/@aws-cdk/lambda-layer-node-proxy-agent/test/proxy-agent-layer.test.ts b/packages/@aws-cdk/lambda-layer-node-proxy-agent/test/proxy-agent-layer.test.ts index 14264a8d080dc..72b1b1f85d4a0 100644 --- a/packages/@aws-cdk/lambda-layer-node-proxy-agent/test/proxy-agent-layer.test.ts +++ b/packages/@aws-cdk/lambda-layer-node-proxy-agent/test/proxy-agent-layer.test.ts @@ -1,6 +1,6 @@ +import { Template } from '@aws-cdk/assertions'; import { Stack } from '@aws-cdk/core'; import { NodeProxyAgentLayer } from '../lib'; -import '@aws-cdk/assert-internal/jest'; test('synthesized to a layer version', () => { //GIVEN @@ -10,7 +10,7 @@ test('synthesized to a layer version', () => { new NodeProxyAgentLayer(stack, 'MyLayer'); // THEN - expect(stack).toHaveResource('AWS::Lambda::LayerVersion', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', { Description: '/opt/nodejs/node_modules/proxy-agent', }); }); From 617b1b00d75d9a5e5dac984875839f3c7659ec6d Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Tue, 18 Jan 2022 15:26:44 -0500 Subject: [PATCH 7/9] chore(lambda-layer-kubectl): make examples compile --- packages/@aws-cdk/lambda-layer-kubectl/package.json | 2 +- .../@aws-cdk/lambda-layer-kubectl/test/kubectl-layer.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/lambda-layer-kubectl/package.json b/packages/@aws-cdk/lambda-layer-kubectl/package.json index af4a3ca611c2e..88b6a6748cd6f 100644 --- a/packages/@aws-cdk/lambda-layer-kubectl/package.json +++ b/packages/@aws-cdk/lambda-layer-kubectl/package.json @@ -73,7 +73,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/pkglint": "0.0.0", diff --git a/packages/@aws-cdk/lambda-layer-kubectl/test/kubectl-layer.test.ts b/packages/@aws-cdk/lambda-layer-kubectl/test/kubectl-layer.test.ts index c7591af7b3c2b..68374424b0085 100644 --- a/packages/@aws-cdk/lambda-layer-kubectl/test/kubectl-layer.test.ts +++ b/packages/@aws-cdk/lambda-layer-kubectl/test/kubectl-layer.test.ts @@ -1,6 +1,6 @@ import { Stack } from '@aws-cdk/core'; import { KubectlLayer } from '../lib'; -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; test('synthesized to a layer version', () => { //GIVEN @@ -10,7 +10,7 @@ test('synthesized to a layer version', () => { new KubectlLayer(stack, 'MyLayer'); // THEN - expect(stack).toHaveResource('AWS::Lambda::LayerVersion', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', { Description: '/opt/kubectl/kubectl and /opt/helm/helm', }); }); From 3013695231adb1cacf2f407563ecd97c18e3f54c Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Tue, 18 Jan 2022 15:36:19 -0500 Subject: [PATCH 8/9] chore(ecr-assets): migrate tests to assertions --- packages/@aws-cdk/aws-ecr-assets/package.json | 2 +- .../aws-ecr-assets/test/image-asset.test.ts | 18 +++--------------- .../aws-ecr-assets/test/tarball-asset.test.ts | 8 ++++---- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/packages/@aws-cdk/aws-ecr-assets/package.json b/packages/@aws-cdk/aws-ecr-assets/package.json index e3e138fe64c21..38d1459a9a713 100644 --- a/packages/@aws-cdk/aws-ecr-assets/package.json +++ b/packages/@aws-cdk/aws-ecr-assets/package.json @@ -72,7 +72,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/cloud-assembly-schema": "0.0.0", diff --git a/packages/@aws-cdk/aws-ecr-assets/test/image-asset.test.ts b/packages/@aws-cdk/aws-ecr-assets/test/image-asset.test.ts index a42fd2451d8e3..6c02f5acbed8e 100644 --- a/packages/@aws-cdk/aws-ecr-assets/test/image-asset.test.ts +++ b/packages/@aws-cdk/aws-ecr-assets/test/image-asset.test.ts @@ -1,6 +1,6 @@ import * as fs from 'fs'; import * as path from 'path'; -import { expect as ourExpect, haveResource } from '@aws-cdk/assert-internal'; +import { Template } from '@aws-cdk/assertions'; import * as iam from '@aws-cdk/aws-iam'; import { describeDeprecated, testDeprecated, testFutureBehavior } from '@aws-cdk/cdk-build-tools'; import * as cxschema from '@aws-cdk/cloud-assembly-schema'; @@ -159,7 +159,7 @@ describe('image asset', () => { asset.repository.grantPull(user); // THEN - ourExpect(stack).to(haveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { 'Statement': [ { @@ -204,9 +204,7 @@ describe('image asset', () => { 'Ref': 'MyUserDC45028B', }, ], - })); - - + }); }); test('fails if the directory does not exist', () => { @@ -291,8 +289,6 @@ describe('image asset', () => { expect(!fs.existsSync(path.join(session.directory, `asset.${image.assetHash}`, 'node_modules', 'one'))).toBeDefined(); expect(!fs.existsSync(path.join(session.directory, `asset.${image.assetHash}`, 'node_modules', 'some_dep'))).toBeDefined(); expect(!fs.existsSync(path.join(session.directory, `asset.${image.assetHash}`, 'node_modules', 'some_dep', 'file'))).toBeDefined(); - - }); testFutureBehavior('docker directory is staged without files specified in exclude option', flags, App, (app) => { @@ -319,8 +315,6 @@ describe('image asset', () => { directory: path.join(__dirname, 'demo-image'), buildArgs: { key: token }, })).toThrow(expected); - - }); testDeprecated('fails if using token as repositoryName', () => { @@ -333,8 +327,6 @@ describe('image asset', () => { directory: path.join(__dirname, 'demo-image'), repositoryName: token, })).toThrow(/Cannot use Token as value of 'repositoryName'/); - - }); testFutureBehavior('docker build options are included in the asset id', flags, App, (app) => { @@ -386,8 +378,6 @@ function testDockerDirectoryIsStagedWithoutFilesSpecifiedInDockerignore(app: App expect(!fs.existsSync(path.join(session.directory, `asset.${image.assetHash}`, 'foobar.txt'))).toBeDefined(); expect(fs.existsSync(path.join(session.directory, `asset.${image.assetHash}`, 'subdirectory'))).toBeDefined(); expect(fs.existsSync(path.join(session.directory, `asset.${image.assetHash}`, 'subdirectory', 'baz.txt'))).toBeDefined(); - - } function testDockerDirectoryIsStagedWithoutFilesSpecifiedInExcludeOption(app: App, ignoreMode?: IgnoreMode) { @@ -406,8 +396,6 @@ function testDockerDirectoryIsStagedWithoutFilesSpecifiedInExcludeOption(app: Ap expect(!fs.existsSync(path.join(session.directory, `asset.${image.assetHash}`, 'foobar.txt'))).toBeDefined(); expect(!fs.existsSync(path.join(session.directory, `asset.${image.assetHash}`, 'subdirectory'))).toBeDefined(); expect(!fs.existsSync(path.join(session.directory, `asset.${image.assetHash}`, 'subdirectory', 'baz.txt'))).toBeDefined(); - - } testFutureBehavior('nested assemblies share assets: legacy synth edition', flags, App, (app) => { diff --git a/packages/@aws-cdk/aws-ecr-assets/test/tarball-asset.test.ts b/packages/@aws-cdk/aws-ecr-assets/test/tarball-asset.test.ts index 77e22f20dca9d..dec618738fc5a 100644 --- a/packages/@aws-cdk/aws-ecr-assets/test/tarball-asset.test.ts +++ b/packages/@aws-cdk/aws-ecr-assets/test/tarball-asset.test.ts @@ -1,11 +1,11 @@ import * as fs from 'fs'; import * as path from 'path'; -import { expect as ourExpect, haveResource } from '@aws-cdk/assert-internal'; +import { Template } from '@aws-cdk/assertions'; import * as iam from '@aws-cdk/aws-iam'; +import { testFutureBehavior } from '@aws-cdk/cdk-build-tools/lib/feature-flag'; import * as cxschema from '@aws-cdk/cloud-assembly-schema'; import { App, Stack } from '@aws-cdk/core'; import * as cxapi from '@aws-cdk/cx-api'; -import { testFutureBehavior } from '@aws-cdk/cdk-build-tools/lib/feature-flag'; import { TarballImageAsset } from '../lib'; /* eslint-disable quote-props */ @@ -64,7 +64,7 @@ describe('image asset', () => { asset.repository.grantPull(user); // THEN - ourExpect(stack).to(haveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { 'Statement': [ { @@ -112,7 +112,7 @@ describe('image asset', () => { 'Ref': 'MyUserDC45028B', }, ], - })); + }); }); testFutureBehavior('docker directory is staged if asset staging is enabled', flags, App, (app) => { From 1d259cb40f6e2a05065ea99d1e789ab1c9bfd5b0 Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Tue, 18 Jan 2022 15:40:56 -0500 Subject: [PATCH 9/9] chore(lambda-destinations): migrate tests to assertions --- .../aws-lambda-destinations/package.json | 2 +- .../test/destinations.test.ts | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-destinations/package.json b/packages/@aws-cdk/aws-lambda-destinations/package.json index 96380582772ce..7f945078ba7e1 100644 --- a/packages/@aws-cdk/aws-lambda-destinations/package.json +++ b/packages/@aws-cdk/aws-lambda-destinations/package.json @@ -71,7 +71,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", diff --git a/packages/@aws-cdk/aws-lambda-destinations/test/destinations.test.ts b/packages/@aws-cdk/aws-lambda-destinations/test/destinations.test.ts index 3be1f3d94f37f..d30d292c7e510 100644 --- a/packages/@aws-cdk/aws-lambda-destinations/test/destinations.test.ts +++ b/packages/@aws-cdk/aws-lambda-destinations/test/destinations.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as events from '@aws-cdk/aws-events'; import * as lambda from '@aws-cdk/aws-lambda'; import * as sns from '@aws-cdk/aws-sns'; @@ -28,7 +28,7 @@ test('event bus as destination', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::EventInvokeConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventInvokeConfig', { DestinationConfig: { OnSuccess: { Destination: { @@ -41,7 +41,7 @@ test('event bus as destination', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -71,7 +71,7 @@ test('lambda as destination', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::EventInvokeConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventInvokeConfig', { DestinationConfig: { OnSuccess: { Destination: { @@ -84,7 +84,7 @@ test('lambda as destination', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -116,7 +116,7 @@ test('lambda payload as destination', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::EventInvokeConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventInvokeConfig', { DestinationConfig: { OnSuccess: { Destination: { @@ -165,7 +165,7 @@ test('lambda payload as destination', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -197,7 +197,7 @@ test('lambda payload as destination', () => { }, }); - expect(stack).toHaveResource('AWS::Events::Rule', { + Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', { EventPattern: { 'detail-type': [ 'Lambda Function Invocation Result - Success', @@ -236,7 +236,7 @@ test('lambda payload as destination', () => { ], }); - expect(stack).toHaveResource('AWS::Events::Rule', { + Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', { EventPattern: { 'detail-type': [ 'Lambda Function Invocation Result - Failure', @@ -287,7 +287,7 @@ test('sns as destination', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::EventInvokeConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventInvokeConfig', { DestinationConfig: { OnSuccess: { Destination: { @@ -297,7 +297,7 @@ test('sns as destination', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -324,7 +324,7 @@ test('sqs as destination', () => { }); // THEN - expect(stack).toHaveResource('AWS::Lambda::EventInvokeConfig', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventInvokeConfig', { DestinationConfig: { OnSuccess: { Destination: { @@ -337,7 +337,7 @@ test('sqs as destination', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ {