From c27373ddbb7cab15381002f61fc1bd86c59aeb5b Mon Sep 17 00:00:00 2001 From: biffgaut <78155736+biffgaut@users.noreply.github.com> Date: Tue, 21 Mar 2023 10:22:24 -0400 Subject: [PATCH 1/4] chore(core): migrate to assertions (#929) * First two test updates * chore(core): migrate to assertions * Remove old lib, final few modules --- .../core/package.json | 1 - .../core/test/alb-helper.test.ts | 81 ++++++---- .../core/test/apigateway-helper.test.ts | 83 ++++++---- ...nt-distribution-api-gateway-helper.test.ts | 10 +- ...ont-distribution-mediastore-helper.test.ts | 20 +-- .../cloudfront-distribution-s3-helper.test.ts | 25 ++- .../test/cloudwatch-log-group-helper.test.ts | 11 +- .../core/test/congnito-helper.test.ts | 15 +- .../core/test/dynamo-table.test.ts | 84 +++++----- .../core/test/elasticache-defaults.test.ts | 1 - .../core/test/elasticache-helper.test.ts | 6 +- .../core/test/elasticsearch-helper.test.ts | 16 +- .../core/test/eventbridge-helper.test.ts | 8 +- .../core/test/events-rule.test.ts | 6 +- .../core/test/fargate-helper.test.ts | 40 ++--- .../core/test/glue-job-helper.test.ts | 32 ++-- .../core/test/glue-table-helper.test.ts | 17 +- .../core/test/iot-rule.test.ts | 6 +- .../core/test/kinesis-analytics.test.ts | 6 +- .../test/kinesis-firehose-s3-defaults.test.ts | 4 +- .../test/kinesis-streams-defaults.test.ts | 4 +- .../core/test/kinesis-streams-helper.test.ts | 14 +- .../core/test/kms-helper.test.ts | 11 +- .../core/test/lambda-event-source.test.ts | 4 +- .../core/test/lambda-helper.test.ts | 26 +-- .../core/test/mediastore-helper.test.ts | 4 +- .../core/test/opensearch-helper.test.ts | 16 +- .../test/override-warning-service.test.ts | 1 - .../core/test/s3-bucket-helper.test.ts | 150 ++++++++++-------- .../core/test/s3-bucket.test.ts | 23 +-- .../core/test/sagemaker-helper.test.ts | 6 +- .../core/test/secretsmanager-helper.test.ts | 11 +- .../core/test/security-group-helper.test.ts | 10 +- .../core/test/sns-helper.test.ts | 38 +++-- .../core/test/sqs-helper.test.ts | 26 +-- .../test/ssm-string-parameter-helper.test.ts | 4 +- .../core/test/step-function-helper.test.ts | 23 +-- .../core/test/test-helper.ts | 7 +- .../core/test/vpc-helper.test.ts | 36 +++-- .../core/test/waf-helper.test.ts | 12 +- 40 files changed, 484 insertions(+), 414 deletions(-) diff --git a/source/patterns/@aws-solutions-constructs/core/package.json b/source/patterns/@aws-solutions-constructs/core/package.json index aae093975..af8148840 100644 --- a/source/patterns/@aws-solutions-constructs/core/package.json +++ b/source/patterns/@aws-solutions-constructs/core/package.json @@ -96,7 +96,6 @@ "devDependencies": { "@types/deep-diff": "^1.0.0", "@types/npmlog": "^4.1.2", - "@aws-cdk/assert": "0.0.0", "@types/prettier": "2.6.0", "@types/jest": "^27.4.0", "@types/node": "^10.3.0" diff --git a/source/patterns/@aws-solutions-constructs/core/test/alb-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/alb-helper.test.ts index b57f6bb93..c31771855 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/alb-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/alb-helper.test.ts @@ -17,7 +17,7 @@ import * as lambda from "aws-cdk-lib/aws-lambda"; import * as defaults from '../index'; import * as ec2 from 'aws-cdk-lib/aws-ec2'; import * as ecs from 'aws-cdk-lib/aws-ecs'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; test('Test ObtainAlb with existing ALB', () => { const stack = new Stack(); @@ -33,7 +33,10 @@ test('Test ObtainAlb with existing ALB', () => { }); defaults.ObtainAlb(stack, 'test', vpc, true, existingLoadBalancer); - expect(stack).toHaveResourceLike('AWS::ElasticLoadBalancingV2::LoadBalancer', { + + const template = Template.fromStack(stack); + + template.hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', { Name: "unique-name", }); }); @@ -52,7 +55,10 @@ test('Test ObtainAlb for new ALB with provided props', () => { vpc, internetFacing: true }); - expect(stack).toHaveResourceLike('AWS::ElasticLoadBalancingV2::LoadBalancer', { + + const template = Template.fromStack(stack); + + template.hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', { Name: "new-loadbalancer", Scheme: "internet-facing", }); @@ -68,7 +74,10 @@ test('Test ObtainAlb for new ALB with default props', () => { }); defaults.ObtainAlb(stack, 'test', vpc, false); - expect(stack).toHaveResourceLike('AWS::ElasticLoadBalancingV2::LoadBalancer', { + + const template = Template.fromStack(stack); + + template.hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', { Scheme: "internal", }); }); @@ -87,7 +96,10 @@ test('Test with custom logging bucket props', () => { const testName = 'test-name'; defaults.ObtainAlb(stack, 'test', vpc, false, undefined, undefined, true, { bucketName: testName }); - expect(stack).toHaveResourceLike('AWS::S3::Bucket', { + + const template = Template.fromStack(stack); + + template.hasResourceProperties('AWS::S3::Bucket', { BucketName: testName }); }); @@ -100,7 +112,10 @@ test('Test with no logging', () => { }); defaults.ObtainAlb(stack, 'test', vpc, false, undefined, undefined, false); - expect(stack).not.toHaveResourceLike('AWS::S3::Bucket', {}); + + const template = Template.fromStack(stack); + + template.resourceCountIs('AWS::S3::Bucket', 0); }); test('Test add single lambda target group with no customization', () => { @@ -120,7 +135,9 @@ test('Test add single lambda target group with no customization', () => { testFunction, ); - expect(stack).toHaveResourceLike('AWS::ElasticLoadBalancingV2::Listener', { + const template = Template.fromStack(stack); + + template.hasResourceProperties('AWS::ElasticLoadBalancingV2::Listener', { DefaultActions: [ { TargetGroupArn: { @@ -130,7 +147,7 @@ test('Test add single lambda target group with no customization', () => { } ], }); - expect(stack).toHaveResourceLike('AWS::ElasticLoadBalancingV2::TargetGroup', { + template.hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', { TargetType: "lambda", }); @@ -156,7 +173,9 @@ test('Test add single lambda target group with target group props', () => { { targetGroupName }, ); - expect(stack).toHaveResourceLike('AWS::ElasticLoadBalancingV2::TargetGroup', { + const template = Template.fromStack(stack); + + template.hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', { TargetType: "lambda", Name: targetGroupName, }); @@ -197,8 +216,10 @@ test('Test add rule props for second lambda target group', () => { { targetGroupName }, ); - expect(stack).toCountResources('AWS::ElasticLoadBalancingV2::TargetGroup', 2); - expect(stack).toHaveResourceLike('AWS::ElasticLoadBalancingV2::ListenerRule', { + const template = Template.fromStack(stack); + + template.resourceCountIs('AWS::ElasticLoadBalancingV2::TargetGroup', 2); + template.hasResourceProperties('AWS::ElasticLoadBalancingV2::ListenerRule', { Conditions: [ { Field: "path-pattern", @@ -235,7 +256,9 @@ test('Test add single fargate target with no customization', () => { } ); - expect(stack).toHaveResourceLike('AWS::ElasticLoadBalancingV2::Listener', { + const template = Template.fromStack(stack); + + template.hasResourceProperties('AWS::ElasticLoadBalancingV2::Listener', { DefaultActions: [ { TargetGroupArn: { @@ -245,7 +268,7 @@ test('Test add single fargate target with no customization', () => { } ], }); - expect(stack).toHaveResourceLike('AWS::ElasticLoadBalancingV2::TargetGroup', { + template.hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', { TargetType: "ip", }); @@ -290,8 +313,10 @@ test('Test add two fargate targets with rules', () => { } ); - expect(stack).toCountResources('AWS::ElasticLoadBalancingV2::TargetGroup', 2); - expect(stack).toHaveResourceLike('AWS::ElasticLoadBalancingV2::ListenerRule', { + const template = Template.fromStack(stack); + + template.resourceCountIs('AWS::ElasticLoadBalancingV2::TargetGroup', 2); + template.hasResourceProperties('AWS::ElasticLoadBalancingV2::ListenerRule', { Conditions: [ { Field: "path-pattern", @@ -318,12 +343,14 @@ test('Test adding a listener with defaults', () => { // Need to add a target because a listener is not allowed to exist without a target or action defaults.AddLambdaTarget(stack, 'dummy-target', listener, CreateTestFunction(stack, 'dummy-function')); + const template = Template.fromStack(stack); + // This should create 2 listeners, HTTPS plus redirect of HTTP - expect(stack).toHaveResourceLike('AWS::ElasticLoadBalancingV2::Listener', { + template.hasResourceProperties('AWS::ElasticLoadBalancingV2::Listener', { Protocol: 'HTTPS', }); - expect(stack).toHaveResourceLike('AWS::ElasticLoadBalancingV2::Listener', { + template.hasResourceProperties('AWS::ElasticLoadBalancingV2::Listener', { Protocol: 'HTTP', }); }); @@ -369,24 +396,12 @@ test('Test adding a HTTP listener', () => { // Need to add a target because a listener is not allowed to exist without a target or action defaults.AddLambdaTarget(stack, 'dummy-target', listener, CreateTestFunction(stack, 'dummy-function')); - expect(stack).toHaveResourceLike('AWS::ElasticLoadBalancingV2::Listener', { + const template = Template.fromStack(stack); + + template.hasResourceProperties('AWS::ElasticLoadBalancingV2::Listener', { Protocol: 'HTTP', }); - expect(stack).toCountResources('AWS::ElasticLoadBalancingV2::Listener', 1); -}); - -test('Test sending custom logging bucket props', () => { - const stack = new Stack(); - - // Set up test framework independent of our code for unit testing - const testVpc = defaults.getTestVpc(stack); - const testAlb = CreateTestLoadBalancer(stack, testVpc); - - const listener = defaults.AddListener(stack, 'test', testAlb, { protocol: 'HTTP' }); - - // Need to add a target because a listener is not allowed to exist without a target or action - defaults.AddLambdaTarget(stack, 'dummy-target', listener, CreateTestFunction(stack, 'dummy-function')); - + template.resourceCountIs('AWS::ElasticLoadBalancingV2::Listener', 1); }); test('Test GetActiveListener with 0 listeners', () => { diff --git a/source/patterns/@aws-solutions-constructs/core/test/apigateway-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/apigateway-helper.test.ts index f3f9311eb..544061793 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/apigateway-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/apigateway-helper.test.ts @@ -11,13 +11,12 @@ * and limitations under the License. */ -import { ResourcePart } from '@aws-cdk/assert'; import { Stack } from 'aws-cdk-lib'; import * as lambda from 'aws-cdk-lib/aws-lambda'; import * as api from 'aws-cdk-lib/aws-apigateway'; import * as iam from 'aws-cdk-lib/aws-iam'; import * as defaults from '../index'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; function deployRegionalApiGateway(stack: Stack) { const lambdaFunctionProps: lambda.FunctionProps = { @@ -103,7 +102,8 @@ test('Test override for RegionalApiGateway', () => { description: 'Hello World' }); - expect(stack).toHaveResource('AWS::ApiGateway::RestApi', { + const template = Template.fromStack(stack); + template.hasResource('AWS::ApiGateway::RestApi', { Type: "AWS::ApiGateway::RestApi", Properties: { Description: "Hello World", @@ -114,7 +114,7 @@ test('Test override for RegionalApiGateway', () => { }, Name: "LambdaRestApi" } - }, ResourcePart.CompleteDefinition); + }); }); test('Test override for GlobalApiGateway', () => { @@ -133,7 +133,8 @@ test('Test override for GlobalApiGateway', () => { restApiName: "HelloWorld" }); - expect(stack).toHaveResource('AWS::ApiGateway::RestApi', { + const template = Template.fromStack(stack); + template.hasResource('AWS::ApiGateway::RestApi', { Type: "AWS::ApiGateway::RestApi", Properties: { EndpointConfiguration: { @@ -143,7 +144,7 @@ test('Test override for GlobalApiGateway', () => { }, Name: "HelloWorld" } - }, ResourcePart.CompleteDefinition); + }); }); test('Test ApiGateway::Account resource for RegionalApiGateway', () => { @@ -158,7 +159,8 @@ test('Test ApiGateway::Account resource for RegionalApiGateway', () => { defaults.RegionalLambdaRestApi(stack, fn); - expect(stack).toHaveResource('AWS::ApiGateway::Account', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::ApiGateway::Account', { CloudWatchRoleArn: { "Fn::GetAtt": [ "LambdaRestApiCloudWatchRoleF339D4E6", @@ -180,7 +182,8 @@ test('Test ApiGateway::Account resource for GlobalApiGateway', () => { defaults.GlobalLambdaRestApi(stack, fn); - expect(stack).toHaveResource('AWS::ApiGateway::Account', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::ApiGateway::Account', { CloudWatchRoleArn: { "Fn::GetAtt": [ "LambdaRestApiCloudWatchRoleF339D4E6", @@ -196,7 +199,8 @@ test('Test default RestApi deployment w/ ApiGatewayProps', () => { restApiName: "customRestApi" }); - expect(stack).toHaveResource('AWS::ApiGateway::RestApi', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::ApiGateway::RestApi', { Name: "customRestApi" }); }); @@ -207,19 +211,21 @@ test('Test default RestApi deployment w/ cloudWatchRole set to false', () => { cloudWatchRole: false }); - expect(stack).not.toHaveResourceLike("AWS::ApiGateway::Account", {}); + const template = Template.fromStack(stack); + template.resourceCountIs("AWS::ApiGateway::Account", 0); }); test('Test default RestApi deployment for Cloudwatch loggroup', () => { const stack = new Stack(); deployRegionalApiGateway(stack); - expect(stack).toHaveResource('AWS::Logs::LogGroup', { + const template = Template.fromStack(stack); + template.hasResource('AWS::Logs::LogGroup', { UpdateReplacePolicy: "Retain", DeletionPolicy: "Retain" - }, ResourcePart.CompleteDefinition); + }); - expect(stack).toHaveResource('AWS::ApiGateway::Stage', { + template.hasResourceProperties('AWS::ApiGateway::Stage', { AccessLogSetting: { DestinationArn: { "Fn::GetAtt": [ @@ -308,12 +314,13 @@ test('Test default RestApi w/ request model and validator', () => { requestModel: { "application/json": api.Model.EMPTY_MODEL } }); - expect(stack).toHaveResource('AWS::ApiGateway::RequestValidator', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::ApiGateway::RequestValidator', { Name: "default-validator", ValidateRequestBody: true }); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + template.hasResourceProperties('AWS::ApiGateway::Method', { RequestModels: { "application/json": "Empty" } }); }); @@ -345,7 +352,8 @@ test('Test for RegionalRestApiGateway', () => { requestTemplate: "$input.json('$')" }); - expect(stack).toHaveResource('AWS::ApiGateway::RestApi', { + const template = Template.fromStack(stack); + template.hasResource('AWS::ApiGateway::RestApi', { Type: "AWS::ApiGateway::RestApi", Properties: { EndpointConfiguration: { @@ -355,7 +363,7 @@ test('Test for RegionalRestApiGateway', () => { }, Name: "HelloWorld-RegionalApi" } - }, ResourcePart.CompleteDefinition); + }); }); // ----------------------------------------------------------------------- @@ -410,12 +418,12 @@ test('Test for Integration Request Props Override', () => { // Setup the API Gateway resource const apiGatewayResource = regionalRestApiResponse.api.root.addResource('hello'); - const integReqParams = {'integration.request.path.topic-level-1': "'method.request.path.topic-level-1'"}; + const integReqParams = { 'integration.request.path.topic-level-1': "'method.request.path.topic-level-1'" }; const integResp: api.IntegrationResponse[] = [ { statusCode: "200", selectionPattern: "2\\d{2}", - responseTemplates : { + responseTemplates: { "application/json": "$input.json('$')" } }]; @@ -439,7 +447,8 @@ test('Test for Integration Request Props Override', () => { awsIntegrationProps: integrationReqProps }); - expect(stack).toHaveResourceLike("AWS::ApiGateway::Method", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::ApiGateway::Method", { HttpMethod: "POST", AuthorizationType: "AWS_IAM", Integration: { @@ -485,6 +494,12 @@ test('Test for Integration Request Props Override', () => { ResponseParameters: { "method.response.header.Content-Type": true } + }, + { + StatusCode: "500", + ResponseParameters: { + "method.response.header.Content-Type": true + } } ] }); @@ -505,7 +520,7 @@ test('Test for Method Request Props Override', () => { // Setup the API Gateway resource const apiGatewayResource = globalRestApiResponse.api.root.addResource('hello'); - const methodReqParams = {'method.request.path.topic-level-1': true}; + const methodReqParams = { 'method.request.path.topic-level-1': true }; const methodResp: api.MethodResponse[] = [ { statusCode: "403" @@ -526,7 +541,8 @@ test('Test for Method Request Props Override', () => { methodOptions: resourceMethodOptions }); - expect(stack).toHaveResourceLike("AWS::ApiGateway::Method", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::ApiGateway::Method", { HttpMethod: "POST", AuthorizationType: "AWS_IAM", Integration: { @@ -607,15 +623,16 @@ test('Test for ApiKey creation using restApiProps', () => { apiResource: apiGatewayResource, requestTemplate: "$input.json('$')" }); + const template = Template.fromStack(stack); // Assertion to check for ApiKey - expect(stack).toHaveResourceLike("AWS::ApiGateway::Method", { + template.hasResourceProperties("AWS::ApiGateway::Method", { ApiKeyRequired: true }); - expect(stack).toHaveResourceLike("AWS::ApiGateway::ApiKey", { + template.hasResourceProperties("AWS::ApiGateway::ApiKey", { Enabled: true }); // Assertion to check for UsagePlan Api Key Mapping - expect(stack).toHaveResourceLike("AWS::ApiGateway::UsagePlanKey", { + template.hasResourceProperties("AWS::ApiGateway::UsagePlanKey", { KeyType: "API_KEY" }); }); @@ -639,15 +656,16 @@ test('Test for ApiKey creation using lambdaApiProps', () => { } }); + const template = Template.fromStack(stack); // Assertion to check for ApiKey - expect(stack).toHaveResourceLike("AWS::ApiGateway::Method", { + template.hasResourceProperties("AWS::ApiGateway::Method", { ApiKeyRequired: true }); - expect(stack).toHaveResourceLike("AWS::ApiGateway::ApiKey", { + template.hasResourceProperties("AWS::ApiGateway::ApiKey", { Enabled: true }); // Assertion to check for UsagePlan Api Key Mapping - expect(stack).toHaveResourceLike("AWS::ApiGateway::UsagePlanKey", { + template.hasResourceProperties("AWS::ApiGateway::UsagePlanKey", { KeyType: "API_KEY" }); }); @@ -679,7 +697,8 @@ test('Additional request templates can be specified on addMethodToApiResource me additionalRequestTemplates }); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'GET', Integration: { RequestTemplates: { @@ -712,7 +731,8 @@ test('Default integration responses are used on addMethodToApiResource method', requestTemplate: '{}', }); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'GET', Integration: { IntegrationResponses: [ @@ -761,7 +781,8 @@ test('Can override integration responses on addMethodToApiResource method', () = ] }); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'GET', Integration: { IntegrationResponses: [ diff --git a/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-api-gateway-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-api-gateway-helper.test.ts index 54d0a38e5..c2151516b 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-api-gateway-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-api-gateway-helper.test.ts @@ -18,9 +18,9 @@ import * as lambda from 'aws-cdk-lib/aws-lambda'; import * as defaults from '../index'; import * as s3 from 'aws-cdk-lib/aws-s3'; import { CloudFrontDistributionForApiGateway } from '../lib/cloudfront-distribution-helper'; -import '@aws-cdk/assert/jest'; import * as origins from 'aws-cdk-lib/aws-cloudfront-origins'; import { LambdaEdgeEventType } from 'aws-cdk-lib/aws-cloudfront'; +import { Template } from 'aws-cdk-lib/assertions'; test('test cloudfront for Api Gateway with user provided logging bucket', () => { const stack = new Stack(); @@ -45,7 +45,7 @@ test('test cloudfront for Api Gateway with user provided logging bucket', () => }); CloudFrontDistributionForApiGateway(stack, _api, cfdProps); - expect(stack).toHaveResourceLike("AWS::CloudFront::Distribution", { + Template.fromStack(stack).hasResourceProperties("AWS::CloudFront::Distribution", { DistributionConfig: { DefaultCacheBehavior: { CachePolicyId: "658327ea-f89d-4fab-a63d-7e88639e58f6", @@ -169,7 +169,7 @@ test('test cloudfront for Api Gateway override properties', () => { CloudFrontDistributionForApiGateway(stack, _api, props); - expect(stack).toHaveResourceLike("AWS::CloudFront::Distribution", { + Template.fromStack(stack).hasResourceProperties("AWS::CloudFront::Distribution", { DistributionConfig: { DefaultCacheBehavior: { AllowedMethods: [ @@ -280,7 +280,7 @@ test('test override cloudfront add custom cloudfront function', () => { } }); - expect(stack).toHaveResource("AWS::CloudFront::Distribution", { + Template.fromStack(stack).hasResourceProperties("AWS::CloudFront::Distribution", { DistributionConfig: { DefaultCacheBehavior: { CachePolicyId: "658327ea-f89d-4fab-a63d-7e88639e58f6", @@ -419,7 +419,7 @@ test('test override cloudfront replace custom lambda@edge', () => { }, false); - expect(stack).toHaveResource("AWS::CloudFront::Distribution", { + Template.fromStack(stack).hasResourceProperties("AWS::CloudFront::Distribution", { DistributionConfig: { DefaultCacheBehavior: { CachePolicyId: "658327ea-f89d-4fab-a63d-7e88639e58f6", diff --git a/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-mediastore-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-mediastore-helper.test.ts index c1e5d97e1..5fc07dfe4 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-mediastore-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-mediastore-helper.test.ts @@ -11,7 +11,7 @@ * and limitations under the License. */ -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import { Stack } from 'aws-cdk-lib'; import * as s3 from 'aws-cdk-lib/aws-s3'; import * as mediastore from 'aws-cdk-lib/aws-mediastore'; @@ -32,7 +32,7 @@ test('CloudFront distribution for MediaStore with user provided log bucket', () }; CloudFrontDistributionForMediaStore(stack, mediaStoreContainer, cfProps); - expect(stack).toHaveResourceLike('AWS::CloudFront::Distribution', { + Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Distribution', { DistributionConfig: { DefaultCacheBehavior: { AllowedMethods: [ @@ -138,7 +138,8 @@ test('CloudFront distribution for MediaStore with user provided origin request p }; CloudFrontDistributionForMediaStore(stack, mediaStoreContainer, cfProps); - expect(stack).toHaveResourceLike('AWS::CloudFront::Distribution', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::CloudFront::Distribution', { DistributionConfig: { DefaultCacheBehavior: { AllowedMethods: [ @@ -217,7 +218,7 @@ test('CloudFront distribution for MediaStore with user provided origin request p ] } }); - expect(stack).toHaveResourceLike('AWS::CloudFront::OriginRequestPolicy', { + template.hasResourceProperties('AWS::CloudFront::OriginRequestPolicy', { OriginRequestPolicyConfig: { CookiesConfig: { CookieBehavior: 'all' @@ -247,7 +248,8 @@ test('CloudFront distribution for MediaStore with user provided custom headers w }; CloudFrontDistributionForMediaStore(stack, mediaStoreContainer, cfProps); - expect(stack).toHaveResourceLike('AWS::CloudFront::Distribution', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::CloudFront::Distribution', { DistributionConfig: { DefaultCacheBehavior: { AllowedMethods: [ @@ -334,7 +336,7 @@ test('CloudFront distribution for MediaStore with user provided custom headers w ] } }); - expect(stack).toHaveResourceLike('AWS::CloudFront::CloudFrontOriginAccessIdentity', { + template.hasResourceProperties('AWS::CloudFront::CloudFrontOriginAccessIdentity', { CloudFrontOriginAccessIdentityConfig: { Comment: { 'Fn::Join': [ @@ -363,7 +365,7 @@ test('CloudFront distribution without HTTP security headers for MediaStore', () const mediaStoreContainer = new mediastore.CfnContainer(stack, 'MediaStoreContainer', mediaStoreContainerProps); CloudFrontDistributionForMediaStore(stack, mediaStoreContainer, {}, false); - expect(stack).toHaveResourceLike('AWS::CloudFront::Distribution', { + Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Distribution', { DistributionConfig: { DefaultCacheBehavior: { AllowedMethods: [ @@ -451,7 +453,7 @@ test('CloudFront distribution for MediaStore override params', () => { }; CloudFrontDistributionForMediaStore(stack, mediaStoreContainer, cfProps); - expect(stack).toHaveResourceLike('AWS::CloudFront::Distribution', { + Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Distribution', { DistributionConfig: { DefaultCacheBehavior: { AllowedMethods: [ @@ -527,7 +529,7 @@ test('test override cloudfront with custom cloudfront function', () => { } }); - expect(stack).toHaveResource("AWS::CloudFront::Distribution", { + Template.fromStack(stack).hasResourceProperties("AWS::CloudFront::Distribution", { DistributionConfig: { DefaultCacheBehavior: { AllowedMethods: [ diff --git a/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-s3-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-s3-helper.test.ts index 0a5d02f82..bea808984 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-s3-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-s3-helper.test.ts @@ -11,13 +11,12 @@ * and limitations under the License. */ -import { ResourcePart } from '@aws-cdk/assert'; +import { Template } from 'aws-cdk-lib/assertions'; import { Stack } from 'aws-cdk-lib'; import * as cloudfront from 'aws-cdk-lib/aws-cloudfront'; import * as lambda from 'aws-cdk-lib/aws-lambda'; import { CloudFrontDistributionForS3 } from '../lib/cloudfront-distribution-helper'; import { buildS3Bucket } from '../lib/s3-bucket-helper'; -import '@aws-cdk/assert/jest'; import { Bucket } from 'aws-cdk-lib/aws-s3'; import * as origins from 'aws-cdk-lib/aws-cloudfront-origins'; import { LambdaEdgeEventType } from 'aws-cdk-lib/aws-cloudfront'; @@ -27,7 +26,7 @@ test('check bucket policy metadata', () => { const stack = new Stack(); const buildS3BucketResponse = buildS3Bucket(stack, {}); CloudFrontDistributionForS3(stack, buildS3BucketResponse.bucket); - expect(stack).toHaveResource('AWS::S3::BucketPolicy', { + Template.fromStack(stack).hasResource('AWS::S3::BucketPolicy', { Metadata: { cfn_nag: { rules_to_suppress: [ @@ -38,14 +37,14 @@ test('check bucket policy metadata', () => { ] } } - }, ResourcePart.CompleteDefinition); + }); }); test('check bucket metadata', () => { const stack = new Stack(); const buildS3BucketResponse = buildS3Bucket(stack, {}); CloudFrontDistributionForS3(stack, buildS3BucketResponse.bucket); - expect(stack).toHaveResource('AWS::S3::Bucket', { + Template.fromStack(stack).hasResource('AWS::S3::Bucket', { Metadata: { cfn_nag: { rules_to_suppress: [ @@ -56,7 +55,7 @@ test('check bucket metadata', () => { ] } } - }, ResourcePart.CompleteDefinition); + }); }); test('test cloudfront check bucket policy', () => { @@ -64,7 +63,7 @@ test('test cloudfront check bucket policy', () => { const buildS3BucketResponse = buildS3Bucket(stack, {}); CloudFrontDistributionForS3(stack, buildS3BucketResponse.bucket); - expect(stack).toHaveResourceLike("AWS::S3::BucketPolicy", { + Template.fromStack(stack).hasResourceProperties("AWS::S3::BucketPolicy", { PolicyDocument: { Statement: [ { @@ -139,7 +138,7 @@ test('test cloudfront with no security headers ', () => { CloudFrontDistributionForS3(stack, buildS3BucketResponse.bucket, {}, false); - expect(stack).toHaveResourceLike("AWS::CloudFront::Distribution", { + Template.fromStack(stack).hasResourceProperties("AWS::CloudFront::Distribution", { DistributionConfig: { DefaultCacheBehavior: { CachePolicyId: "658327ea-f89d-4fab-a63d-7e88639e58f6", @@ -199,7 +198,7 @@ test('test cloudfront override cloudfront logging bucket ', () => { CloudFrontDistributionForS3(stack, buildS3BucketResponse.bucket, myprops); - expect(stack).toHaveResourceLike("AWS::CloudFront::Distribution", { + Template.fromStack(stack).hasResourceProperties("AWS::CloudFront::Distribution", { DistributionConfig: { DefaultCacheBehavior: { CachePolicyId: "658327ea-f89d-4fab-a63d-7e88639e58f6", @@ -272,7 +271,7 @@ test('test cloudfront override properties', () => { CloudFrontDistributionForS3(stack, buildS3BucketResponse.bucket, props); - expect(stack).toHaveResourceLike("AWS::CloudFront::Distribution", { + Template.fromStack(stack).hasResourceProperties("AWS::CloudFront::Distribution", { DistributionConfig: { DefaultCacheBehavior: { AllowedMethods: [ @@ -366,7 +365,7 @@ test('test override cloudfront with custom cloudfront function', () => { } }); - expect(stack).toHaveResource("AWS::CloudFront::Distribution", { + Template.fromStack(stack).hasResourceProperties("AWS::CloudFront::Distribution", { DistributionConfig: { DefaultCacheBehavior: { CachePolicyId: "658327ea-f89d-4fab-a63d-7e88639e58f6", @@ -454,7 +453,7 @@ test('test override cloudfront replace custom lambda@edge', () => { }, false); - expect(stack).toHaveResource("AWS::CloudFront::Distribution", { + Template.fromStack(stack).hasResourceProperties("AWS::CloudFront::Distribution", { DistributionConfig: { DefaultCacheBehavior: { CachePolicyId: "658327ea-f89d-4fab-a63d-7e88639e58f6", @@ -523,7 +522,7 @@ test('test cloudfront override cloudfront custom domain names ', () => { CloudFrontDistributionForS3(stack, buildS3BucketResponse.bucket, myprops); - expect(stack).toHaveResourceLike("AWS::CloudFront::Distribution", { + Template.fromStack(stack).hasResourceProperties("AWS::CloudFront::Distribution", { DistributionConfig: { Aliases: [ "mydomains" diff --git a/source/patterns/@aws-solutions-constructs/core/test/cloudwatch-log-group-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/cloudwatch-log-group-helper.test.ts index fb720dad4..506baf08c 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/cloudwatch-log-group-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/cloudwatch-log-group-helper.test.ts @@ -11,9 +11,8 @@ * and limitations under the License. */ -import { ResourcePart } from '@aws-cdk/assert'; +import { Template } from 'aws-cdk-lib/assertions'; import { Stack } from 'aws-cdk-lib'; -import '@aws-cdk/assert/jest'; import * as logs from 'aws-cdk-lib/aws-logs'; import { buildLogGroup } from '../lib/cloudwatch-log-group-helper'; import * as kms from 'aws-cdk-lib/aws-kms'; @@ -27,7 +26,7 @@ test('override cw log group props with encryptionKey only', () => { encryptionKey: key }); - expect(stack).toHaveResource('AWS::Logs::LogGroup', { + Template.fromStack(stack).hasResource('AWS::Logs::LogGroup', { Metadata: { cfn_nag: { rules_to_suppress: [ @@ -38,7 +37,7 @@ test('override cw log group props with encryptionKey only', () => { ] } } - }, ResourcePart.CompleteDefinition); + }); }); test('override cw log group props with retention period only', () => { @@ -48,7 +47,7 @@ test('override cw log group props with retention period only', () => { retention: logs.RetentionDays.FIVE_DAYS }); - expect(stack).toHaveResource('AWS::Logs::LogGroup', { + Template.fromStack(stack).hasResource('AWS::Logs::LogGroup', { Metadata: { cfn_nag: { rules_to_suppress: [ @@ -59,5 +58,5 @@ test('override cw log group props with retention period only', () => { ] } } - }, ResourcePart.CompleteDefinition); + }); }); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/core/test/congnito-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/congnito-helper.test.ts index 96971a70e..c7b820d47 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/congnito-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/congnito-helper.test.ts @@ -14,7 +14,7 @@ import { Stack } from 'aws-cdk-lib'; import * as cognito from 'aws-cdk-lib/aws-cognito'; import * as defaults from '../index'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; test('Test override for buildUserPool', () => { const stack = new Stack(); @@ -26,7 +26,7 @@ test('Test override for buildUserPool', () => { defaults.buildUserPool(stack, userpoolProps); - expect(stack).toHaveResource('AWS::Cognito::UserPool', { + Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { UsernameAttributes: [ "email", "phone_number" @@ -50,7 +50,7 @@ test('Test override for buildUserPoolClient', () => { defaults.buildUserPoolClient(stack, userpool, userpoolclientProps); - expect(stack).toHaveResource('AWS::Cognito::UserPoolClient', { + Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { UserPoolId: { Ref: "CognitoUserPool53E37E69" }, @@ -70,7 +70,7 @@ test('Test override for buildIdentityPool', () => { allowUnauthenticatedIdentities: true }); - expect(stack).toHaveResource('AWS::Cognito::IdentityPool', { + Template.fromStack(stack).hasResourceProperties('AWS::Cognito::IdentityPool', { AllowUnauthenticatedIdentities: true, CognitoIdentityProviders: [ { @@ -105,11 +105,12 @@ test('Test setupCognitoForSearchService', () => { identitypool }); - expect(stack).toHaveResource('AWS::Cognito::UserPoolDomain', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::Cognito::UserPoolDomain', { Domain: "test-domain" }); - expect(stack).toHaveResource('AWS::Cognito::IdentityPoolRoleAttachment', { + template.hasResourceProperties('AWS::Cognito::IdentityPoolRoleAttachment', { IdentityPoolId: { Ref: "CognitoIdentityPool" }, @@ -123,7 +124,7 @@ test('Test setupCognitoForSearchService', () => { } }); - expect(stack).toHaveResource('AWS::IAM::Role', { + template.hasResourceProperties('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: [ { diff --git a/source/patterns/@aws-solutions-constructs/core/test/dynamo-table.test.ts b/source/patterns/@aws-solutions-constructs/core/test/dynamo-table.test.ts index 9b172f1d7..b0da47f05 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/dynamo-table.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/dynamo-table.test.ts @@ -11,12 +11,11 @@ * and limitations under the License. */ -import { expect as expectCDK, haveResource } from '@aws-cdk/assert'; import { Stack } from 'aws-cdk-lib'; import * as dynamodb from 'aws-cdk-lib/aws-dynamodb'; import * as defaults from '../index'; import { overrideProps } from '../lib/utils'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import { getPartitionKeyNameFromTable } from '../lib/dynamodb-table-helper'; test('test TableProps change billing mode', () => { @@ -37,7 +36,7 @@ test('test TableProps change billing mode', () => { const outProps = overrideProps(defaultProps, inProps); new dynamodb.Table(stack, 'test-dynamo-override', outProps); - expect(stack).toHaveResource("AWS::DynamoDB::Table", { + Template.fromStack(stack).hasResourceProperties("AWS::DynamoDB::Table", { KeySchema: [ { AttributeName: "id", @@ -79,7 +78,7 @@ test('test TableProps override add sort key', () => { const outProps = overrideProps(defaultProps, inProps); new dynamodb.Table(stack, 'test-dynamo-override', outProps); - expect(stack).toHaveResource("AWS::DynamoDB::Table", { + Template.fromStack(stack).hasResourceProperties("AWS::DynamoDB::Table", { KeySchema: [ { AttributeName: "id", @@ -123,7 +122,7 @@ test('test TableWithStreamProps override stream view type', () => { const outProps = overrideProps(defaultProps, inProps); new dynamodb.Table(stack, 'test-dynamo-override', outProps); - expect(stack).toHaveResource("AWS::DynamoDB::Table", { + Template.fromStack(stack).hasResourceProperties("AWS::DynamoDB::Table", { KeySchema: [ { AttributeName: "id", @@ -166,21 +165,22 @@ test('test buildDynamoDBTable with existingTableObj', () => { expect(buildDynamoDBTableResponse.tableInterface).toBeDefined(); expect(buildDynamoDBTableResponse.tableObject).toBeDefined(); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::DynamoDB::Table', { KeySchema: [ { AttributeName: "table_id", KeyType: "HASH" } ] - })); + }); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + template.hasResourceProperties('AWS::DynamoDB::Table', { ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 } - })); + }); }); test('test buildDynamoDBTable without any arguments', () => { @@ -191,24 +191,25 @@ test('test buildDynamoDBTable without any arguments', () => { expect(buildDynamoDBTableResponse.tableInterface).toBeDefined(); expect(buildDynamoDBTableResponse.tableObject).toBeDefined(); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::DynamoDB::Table', { KeySchema: [ { AttributeName: "id", KeyType: "HASH" } ] - })); + }); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + template.hasResourceProperties('AWS::DynamoDB::Table', { BillingMode: "PAY_PER_REQUEST" - })); + }); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + template.hasResourceProperties('AWS::DynamoDB::Table', { SSESpecification: { SSEEnabled: true } - })); + }); }); test('test buildDynamoDBTable with TableProps', () => { @@ -229,21 +230,22 @@ test('test buildDynamoDBTable with TableProps', () => { expect(buildDynamoDBTableResponse.tableInterface).toBeDefined(); expect(buildDynamoDBTableResponse.tableObject).toBeDefined(); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::DynamoDB::Table', { KeySchema: [ { AttributeName: "table_id", KeyType: "HASH" } ] - })); + }); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + template.hasResourceProperties('AWS::DynamoDB::Table', { ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 } - })); + }); }); test('test buildDynamoDBTableWithStream with TableProps', () => { @@ -264,20 +266,21 @@ test('test buildDynamoDBTableWithStream with TableProps', () => { expect(response.tableInterface).toBeDefined(); expect(response.tableObject).toBeDefined(); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::DynamoDB::Table', { KeySchema: [ { AttributeName: "table_id", KeyType: "HASH" } ] - })); + }); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + template.hasResourceProperties('AWS::DynamoDB::Table', { StreamSpecification: { StreamViewType: "NEW_IMAGE" } - })); + }); }); test('test buildDynamoDBTableWithStream without any arguments', () => { @@ -288,30 +291,31 @@ test('test buildDynamoDBTableWithStream without any arguments', () => { expect(response.tableInterface).toBeDefined(); expect(response.tableObject).toBeDefined(); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::DynamoDB::Table', { KeySchema: [ { AttributeName: "id", KeyType: "HASH" } ] - })); + }); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + template.hasResourceProperties('AWS::DynamoDB::Table', { BillingMode: "PAY_PER_REQUEST" - })); + }); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + template.hasResourceProperties('AWS::DynamoDB::Table', { SSESpecification: { SSEEnabled: true } - })); + }); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + template.hasResourceProperties('AWS::DynamoDB::Table', { StreamSpecification: { StreamViewType: "NEW_AND_OLD_IMAGES" } - })); + }); }); test('test buildDynamoDBTableWithStream with existingTableObj', () => { @@ -334,20 +338,21 @@ test('test buildDynamoDBTableWithStream with existingTableObj', () => { expect(response.tableInterface).toBeDefined(); expect(response.tableObject).not.toBeDefined(); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::DynamoDB::Table', { KeySchema: [ { AttributeName: "table_id", KeyType: "HASH" } ] - })); + }); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + template.hasResourceProperties('AWS::DynamoDB::Table', { StreamSpecification: { StreamViewType: "NEW_IMAGE" } - })); + }); }); test('test buildDynamoDBTable with existingTableInterface', () => { @@ -370,20 +375,21 @@ test('test buildDynamoDBTable with existingTableInterface', () => { expect(buildDynamoDBTableResponse.tableInterface).toBeDefined(); expect(buildDynamoDBTableResponse.tableObject).not.toBeDefined(); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::DynamoDB::Table', { KeySchema: [ { AttributeName: "table_id", KeyType: "HASH" } ] - })); + }); - expectCDK(stack).to(haveResource('AWS::DynamoDB::Table', { + template.hasResourceProperties('AWS::DynamoDB::Table', { StreamSpecification: { StreamViewType: "NEW_IMAGE" } - })); + }); }); test('test getPartitionKeyNameFromTable()', () => { diff --git a/source/patterns/@aws-solutions-constructs/core/test/elasticache-defaults.test.ts b/source/patterns/@aws-solutions-constructs/core/test/elasticache-defaults.test.ts index d9dbf414e..a7cb87f71 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/elasticache-defaults.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/elasticache-defaults.test.ts @@ -11,7 +11,6 @@ * and limitations under the License. */ -import "@aws-cdk/assert/jest"; import { GetDefaultCachePort, GetMemcachedDefaults } from "../lib/elasticache-defaults"; test("Test GetDefaultCachePort()", () => { diff --git a/source/patterns/@aws-solutions-constructs/core/test/elasticache-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/elasticache-helper.test.ts index 766a7dbd0..19a896936 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/elasticache-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/elasticache-helper.test.ts @@ -11,7 +11,7 @@ * and limitations under the License. */ -import "@aws-cdk/assert/jest"; +import { Template } from 'aws-cdk-lib/assertions'; import { CreateTestCache, getTestVpc } from "./test-helper"; import * as cdk from 'aws-cdk-lib'; import * as ec2 from 'aws-cdk-lib/aws-ec2'; @@ -49,7 +49,7 @@ test("Test create cache with no client props", () => { cachePort: 11111, }); - expect(stack).toHaveResourceLike("AWS::ElastiCache::CacheCluster", { + Template.fromStack(stack).hasResourceProperties("AWS::ElastiCache::CacheCluster", { Port: 11111, AZMode: 'cross-az', Engine: 'memcached', @@ -74,7 +74,7 @@ test("Test create cache with client props", () => { } }); - expect(stack).toHaveResourceLike("AWS::ElastiCache::CacheCluster", { + Template.fromStack(stack).hasResourceProperties("AWS::ElastiCache::CacheCluster", { Port: 12321, AZMode: 'single-az', Engine: 'memcached', diff --git a/source/patterns/@aws-solutions-constructs/core/test/elasticsearch-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/elasticsearch-helper.test.ts index 22d9ea139..905bb41cc 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/elasticsearch-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/elasticsearch-helper.test.ts @@ -14,7 +14,7 @@ import { Stack } from 'aws-cdk-lib'; import * as elasticsearch from 'aws-cdk-lib/aws-elasticsearch'; import * as defaults from '../index'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import * as ec2 from 'aws-cdk-lib/aws-ec2'; function deployES(stack: Stack, domainName: string, clientDomainProps?: elasticsearch.CfnDomainProps, @@ -68,7 +68,7 @@ test('Test override SnapshotOptions for buildElasticSearch', () => { expect(buildElasticSearchResponse.domain).toBeDefined(); expect(buildElasticSearchResponse.role).toBeDefined(); - expect(stack).toHaveResource('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { AccessPolicies: { Statement: [ { @@ -163,7 +163,7 @@ test('Test VPC with 1 AZ, Zone Awareness Disabled', () => { expect(buildElasticSearchResponse.domain).toBeDefined(); expect(buildElasticSearchResponse.role).toBeDefined(); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { DomainName: "test-domain", ElasticsearchClusterConfig: { DedicatedMasterCount: 3, @@ -186,7 +186,7 @@ test('Test VPC with 2 AZ, Zone Awareness Enabled', () => { expect(buildElasticSearchResponse.domain).toBeDefined(); expect(buildElasticSearchResponse.role).toBeDefined(); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { DomainName: "test-domain", ElasticsearchClusterConfig: { DedicatedMasterCount: 3, @@ -211,7 +211,7 @@ test('Test VPC with 3 AZ, Zone Awareness Enabled', () => { expect(buildElasticSearchResponse.domain).toBeDefined(); expect(buildElasticSearchResponse.role).toBeDefined(); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { DomainName: "test-domain", ElasticsearchClusterConfig: { DedicatedMasterCount: 3, @@ -248,7 +248,7 @@ test('Test deployment with an existing private VPC', () => { expect(buildElasticSearchResponse.domain).toBeDefined(); expect(buildElasticSearchResponse.role).toBeDefined(); - expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { DomainName: "test-domain", ElasticsearchClusterConfig: { DedicatedMasterCount: 3, @@ -295,7 +295,7 @@ test('Test override ES version for buildElasticSearch', () => { expect(response.domain).toBeDefined(); expect(response.role).toBeDefined(); - expect(stack).toHaveResource('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { AccessPolicies: { Statement: [ { @@ -382,7 +382,7 @@ test('Test ES with lambdaRoleARN', () => { expect(buildElasticSearchResponse.domain).toBeDefined(); expect(buildElasticSearchResponse.role).toBeDefined(); - expect(stack).toHaveResource('AWS::Elasticsearch::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::Elasticsearch::Domain', { AccessPolicies: { Statement: [ { diff --git a/source/patterns/@aws-solutions-constructs/core/test/eventbridge-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/eventbridge-helper.test.ts index f6c73f448..b20b05ff4 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/eventbridge-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/eventbridge-helper.test.ts @@ -14,7 +14,7 @@ import { Stack } from 'aws-cdk-lib'; import * as events from 'aws-cdk-lib/aws-events'; import * as defaults from '../index'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; // -------------------------------------------------------------- // Test deployment with no properties @@ -29,7 +29,7 @@ test('Test deployment with no properties', () => { } }); - expect(stack).not.toHaveResource("AWS::EventBridge::EventBus"); + Template.fromStack(stack).resourceCountIs("AWS::EventBridge::EventBus", 0); }); // -------------------------------------------------------------- @@ -43,7 +43,7 @@ test('Test deployment with existing EventBus', () => { existingEventBusInterface: new events.EventBus(stack, `existing-event-bus`, { eventBusName: 'test-bus' }) }); - expect(stack).toHaveResource('AWS::Events::EventBus'); + Template.fromStack(stack).resourceCountIs('AWS::Events::EventBus', 1); }); // -------------------------------------------------------------- @@ -59,7 +59,7 @@ test('Test deployment with new EventBus with props', () => { } }); - expect(stack).toHaveResource('AWS::Events::EventBus', { + Template.fromStack(stack).hasResourceProperties('AWS::Events::EventBus', { Name: 'testneweventbus' }); }); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/core/test/events-rule.test.ts b/source/patterns/@aws-solutions-constructs/core/test/events-rule.test.ts index eca54ded6..3662b8b1a 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/events-rule.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/events-rule.test.ts @@ -14,7 +14,7 @@ import { Stack } from 'aws-cdk-lib'; import * as events from 'aws-cdk-lib/aws-events'; import * as defaults from '../index'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import { Schedule } from 'aws-cdk-lib/aws-events'; import { Duration } from 'aws-cdk-lib'; import { overrideProps } from '../lib/utils'; @@ -38,7 +38,7 @@ test('test EventsRuleProps override ruleName and description', () => { new events.Rule(stack, 'Events', eventsRuleProps); - expect(stack).toHaveResource('AWS::Events::Rule', { + Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', { Description: "hello world", Name: "test", ScheduleExpression: "rate(5 minutes)", @@ -78,7 +78,7 @@ test('test EventsRuleProps add more event targets', () => { new events.Rule(stack, 'Events', eventsRuleProps); - expect(stack).toHaveResource('AWS::Events::Rule', { + Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', { ScheduleExpression: "rate(5 minutes)", State: "ENABLED", Targets: [ diff --git a/source/patterns/@aws-solutions-constructs/core/test/fargate-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/fargate-helper.test.ts index 3c60635ae..da623d247 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/fargate-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/fargate-helper.test.ts @@ -17,7 +17,8 @@ import { CreateFargateService } from ".."; import * as ec2 from "aws-cdk-lib/aws-ec2"; import * as ecs from "aws-cdk-lib/aws-ecs"; import * as ecr from "aws-cdk-lib/aws-ecr"; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; +import { expectNonexistence } from './test-helper'; test('Test with all defaults', () => { const stack = new Stack(); @@ -32,7 +33,8 @@ test('Test with all defaults', () => { expect(createFargateServiceResponse.containerDefinition).toBeDefined(); expect(createFargateServiceResponse.service).toBeDefined(); - expect(stack).toHaveResource("AWS::ECS::Service", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::ECS::Service", { Cluster: { Ref: "testclusterDF8B0D19" }, @@ -69,7 +71,7 @@ test('Test with all defaults', () => { Ref: "testtaskdefF924AD58" } }); - expect(stack).toHaveResourceLike("AWS::ECS::TaskDefinition", { + template.hasResourceProperties("AWS::ECS::TaskDefinition", { ContainerDefinitions: [ { Image: { @@ -87,15 +89,15 @@ test('Test with all defaults', () => { } ], }); - expect(stack).toHaveResourceLike("AWS::EC2::SecurityGroup", { + template.hasResourceProperties("AWS::EC2::SecurityGroup", { GroupDescription: 'Construct created security group' }); - expect(stack).toCountResources("AWS::EC2::VPCEndpoint", 3); - expect(stack).toHaveResource("AWS::EC2::VPCEndpoint", { + template.resourceCountIs("AWS::EC2::VPCEndpoint", 3); + template.hasResourceProperties("AWS::EC2::VPCEndpoint", { VpcEndpointType: "Interface", }); - expect(stack).toHaveResource("AWS::EC2::VPCEndpoint", { + template.hasResourceProperties("AWS::EC2::VPCEndpoint", { VpcEndpointType: "Gateway", }); @@ -111,7 +113,8 @@ test('Test with all defaults in isolated VPC', () => { undefined, defaults.fakeEcrRepoArn); - expect(stack).toHaveResource("AWS::ECS::Service", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::ECS::Service", { Cluster: { Ref: "testclusterDF8B0D19" }, @@ -148,7 +151,7 @@ test('Test with all defaults in isolated VPC', () => { Ref: "testtaskdefF924AD58" } }); - expect(stack).toHaveResourceLike("AWS::ECS::TaskDefinition", { + template.hasResourceProperties("AWS::ECS::TaskDefinition", { ContainerDefinitions: [ { Image: { @@ -167,11 +170,11 @@ test('Test with all defaults in isolated VPC', () => { ], }); - expect(stack).toCountResources("AWS::EC2::VPCEndpoint", 3); - expect(stack).toHaveResource("AWS::EC2::VPCEndpoint", { + template.resourceCountIs("AWS::EC2::VPCEndpoint", 3); + template.hasResourceProperties("AWS::EC2::VPCEndpoint", { VpcEndpointType: "Interface", }); - expect(stack).toHaveResource("AWS::EC2::VPCEndpoint", { + template.hasResourceProperties("AWS::EC2::VPCEndpoint", { VpcEndpointType: "Gateway", }); @@ -193,7 +196,7 @@ test('Test with custom task definition', () => { } ); - expect(stack).toHaveResourceLike("AWS::ECS::TaskDefinition", { + Template.fromStack(stack).hasResourceProperties("AWS::ECS::TaskDefinition", { ContainerDefinitions: [ { Image: { @@ -226,7 +229,7 @@ test('Test with custom container definition', () => { { cpu: 256, memoryLimitMiB: 512 } ); - expect(stack).toHaveResourceLike("AWS::ECS::TaskDefinition", { + Template.fromStack(stack).hasResourceProperties("AWS::ECS::TaskDefinition", { Cpu: '256', Memory: '512' }); @@ -245,7 +248,7 @@ test('Test with custom cluster props', () => { undefined, ); - expect(stack).toHaveResourceLike("AWS::ECS::Cluster", { + Template.fromStack(stack).hasResourceProperties("AWS::ECS::Cluster", { ClusterName: clusterName, }); }); @@ -266,7 +269,7 @@ test('Test with custom Fargate Service props', () => { { serviceName } ); - expect(stack).toHaveResourceLike("AWS::ECS::Service", { + Template.fromStack(stack).hasResourceProperties("AWS::ECS::Service", { ServiceName: serviceName, }); }); @@ -295,10 +298,11 @@ test('Test with custom security group', () => { { securityGroups: [ customSg ] } ); - expect(stack).toHaveResource("AWS::EC2::SecurityGroup", { + Template.fromStack(stack).hasResourceProperties("AWS::EC2::SecurityGroup", { GroupDescription: groupDescription, }); - expect(stack).not.toHaveResource("AWS::EC2::SecurityGroup", { + + expectNonexistence(stack, "AWS::EC2::SecurityGroup", { GroupDescription: 'Construct created security group', }); }); diff --git a/source/patterns/@aws-solutions-constructs/core/test/glue-job-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/glue-job-helper.test.ts index 5e8c0a15e..171811669 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/glue-job-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/glue-job-helper.test.ts @@ -12,8 +12,7 @@ */ // Imports -import { ResourcePart } from '@aws-cdk/assert'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import { CfnJob, CfnJobProps } from 'aws-cdk-lib/aws-glue'; import { Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; import { Bucket, BucketEncryption } from 'aws-cdk-lib/aws-s3'; @@ -54,7 +53,7 @@ test('Test deployment with role creation', () => { expect(glueJob.bucket).toBeDefined(); expect(glueJob.bucket).toBeInstanceOf(Bucket); - expect(stack).toHaveResourceLike('AWS::Glue::Job', { + Template.fromStack(stack).hasResource('AWS::Glue::Job', { Type: "AWS::Glue::Job", Properties: { Command: { @@ -73,7 +72,7 @@ test('Test deployment with role creation', () => { SecurityConfiguration: "testETLJob", WorkerType: "G.1X" } - }, ResourcePart.CompleteDefinition); + }); }); // -------------------------------------------------------------- @@ -116,7 +115,7 @@ test('Create a Glue Job outside the construct', () => { expect(glueJob.bucket).not.toBeDefined(); expect(glueJob.loggingBucket).not.toBeDefined(); - expect(stack).toHaveResourceLike('AWS::Glue::Job', { + Template.fromStack(stack).hasResource('AWS::Glue::Job', { Type: "AWS::Glue::Job", Properties: { AllocatedCapacity: 2, @@ -136,7 +135,7 @@ test('Create a Glue Job outside the construct', () => { }, WorkerType: "Standard", } - }, ResourcePart.CompleteDefinition); + }); }); // -------------------------------------------------------------- @@ -177,8 +176,9 @@ test('Test custom deployment properties', () => { }], 'kinesis', {STREAM_NAME: 'testStream'}) }); + const template = Template.fromStack(stack); // check if Glue Job Resource was created correctly - expect(stack).toHaveResourceLike('AWS::Glue::Job', { + template.hasResource('AWS::Glue::Job', { Properties: { Command: { Name: "glueetl", @@ -197,10 +197,10 @@ test('Test custom deployment properties', () => { WorkerType: "Standard", }, Type: "AWS::Glue::Job" - }, ResourcePart.CompleteDefinition); + }); // check if the role is created - expect(stack).toHaveResourceLike('AWS::IAM::Role', { + template.hasResource('AWS::IAM::Role', { Type: "AWS::IAM::Role", Properties: { AssumeRolePolicyDocument: { @@ -217,10 +217,10 @@ test('Test custom deployment properties', () => { }, Description: "Existing role" } - }, ResourcePart.CompleteDefinition); + }); // check if the security config is created - expect(stack).toHaveResourceLike('AWS::Glue::SecurityConfiguration', { + template.hasResource('AWS::Glue::SecurityConfiguration', { Properties: { EncryptionConfiguration: { JobBookmarksEncryption: { @@ -249,7 +249,7 @@ test('Test custom deployment properties', () => { Name: "ETLJobSecurityConfig", }, Type: "AWS::Glue::SecurityConfiguration", - }, ResourcePart.CompleteDefinition); + }); }); // -------------------------------------------------------------- @@ -305,7 +305,7 @@ test('Test deployment with role creation', () => { comment: "" }], 'kinesis', {STREAM_NAME: 'testStream'}) }); - expect(stack).toHaveResourceLike('AWS::IAM::Role', { + Template.fromStack(stack).hasResource('AWS::IAM::Role', { Type: "AWS::IAM::Role", Properties: { AssumeRolePolicyDocument: { @@ -320,7 +320,7 @@ test('Test deployment with role creation', () => { }, Description: "Service role that Glue custom ETL jobs will assume for exeuction" } - }, ResourcePart.CompleteDefinition); + }); }); // -------------------------------------------------------------- @@ -359,7 +359,7 @@ test('Test deployment with role creation', () => { comment: "" }], 'kinesis', {STREAM_NAME: 'testStream'}) }); - expect(stack).toHaveResourceLike('AWS::S3::Bucket', { + Template.fromStack(stack).hasResource('AWS::S3::Bucket', { Type: 'AWS::S3::Bucket', Properties: { BucketEncryption: { @@ -373,7 +373,7 @@ test('Test deployment with role creation', () => { }, UpdateReplacePolicy: "Delete", DeletionPolicy: "Delete" - }, ResourcePart.CompleteDefinition); + }); }); // -------------------------------------------------------------- diff --git a/source/patterns/@aws-solutions-constructs/core/test/glue-table-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/glue-table-helper.test.ts index 4a399c7e3..2876782f7 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/glue-table-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/glue-table-helper.test.ts @@ -11,8 +11,7 @@ * and limitations under the License. */ -import { ResourcePart } from '@aws-cdk/assert'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import { Aws, Stack } from 'aws-cdk-lib'; import * as defaults from '..'; @@ -56,7 +55,7 @@ test('create default CfnTable with default props', () => { } }); - expect(stack).toHaveResourceLike('AWS::Glue::Table', { + Template.fromStack(stack).hasResource('AWS::Glue::Table', { Type: "AWS::Glue::Table", Properties: { CatalogId: "fakecatalogfortest", @@ -85,7 +84,7 @@ test('create default CfnTable with default props', () => { } } } - }, ResourcePart.CompleteDefinition); + }); }); // -------------------------------------------------------------- @@ -96,7 +95,9 @@ test('Create table', () => { defaults.createGlueTable(stack, defaults.createGlueDatabase(stack), undefined, _fieldSchema, 'kinesis', { STREAM_NAME: 'testStream' }); - expect(stack).toHaveResourceLike('AWS::Glue::Database', { + + const template = Template.fromStack(stack); + template.hasResource('AWS::Glue::Database', { Type: "AWS::Glue::Database", Properties: { CatalogId: { @@ -106,9 +107,9 @@ test('Create table', () => { Description: "An AWS Glue database generated by AWS Solutions Construct" } } - }, ResourcePart.CompleteDefinition); + }); - expect(stack).toHaveResourceLike('AWS::Glue::Table', { + template.hasResource('AWS::Glue::Table', { Properties: { CatalogId: { Ref: "AWS::AccountId" @@ -174,7 +175,7 @@ test('Create table', () => { TableType: "EXTERNAL_TABLE" } } - }, ResourcePart.CompleteDefinition); + }); }); // -------------------------------------------------------------- diff --git a/source/patterns/@aws-solutions-constructs/core/test/iot-rule.test.ts b/source/patterns/@aws-solutions-constructs/core/test/iot-rule.test.ts index 6f7dcbf18..eef853ffc 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/iot-rule.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/iot-rule.test.ts @@ -15,7 +15,7 @@ import { Stack } from 'aws-cdk-lib'; import * as iot from 'aws-cdk-lib/aws-iot'; import * as defaults from '../index'; import { overrideProps } from '../lib/utils'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; test('test TopicRuleProps override sql and description', () => { const stack = new Stack(); @@ -41,7 +41,7 @@ test('test TopicRuleProps override sql and description', () => { new iot.CfnTopicRule(stack, 'IotTopic', outProps); - expect(stack).toHaveResource('AWS::IoT::TopicRule', { + Template.fromStack(stack).hasResourceProperties('AWS::IoT::TopicRule', { TopicRulePayload: { Actions: [ { @@ -80,7 +80,7 @@ test('test TopicRuleProps override actions', () => { new iot.CfnTopicRule(stack, 'IotTopic', outProps); - expect(stack).toHaveResource('AWS::IoT::TopicRule', { + Template.fromStack(stack).hasResourceProperties('AWS::IoT::TopicRule', { TopicRulePayload: { Actions: [ { diff --git a/source/patterns/@aws-solutions-constructs/core/test/kinesis-analytics.test.ts b/source/patterns/@aws-solutions-constructs/core/test/kinesis-analytics.test.ts index 7d32cb247..9a36a8699 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/kinesis-analytics.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/kinesis-analytics.test.ts @@ -20,7 +20,7 @@ import * as kms from "aws-cdk-lib/aws-kms"; import * as logs from "aws-cdk-lib/aws-logs"; import * as defaults from "../index"; import { overrideProps } from "../lib/utils"; -import "@aws-cdk/assert/jest"; +import { Template } from 'aws-cdk-lib/assertions'; test("test kinesisanalytics override inputProperty", () => { const stack = new Stack(); @@ -44,7 +44,7 @@ test("test kinesisanalytics override inputProperty", () => { new kinesisanalytics.CfnApplication(stack, "KinesisAnalytics", outProps); - expect(stack).toHaveResource("AWS::KinesisAnalytics::Application", { + Template.fromStack(stack).hasResourceProperties("AWS::KinesisAnalytics::Application", { Inputs: [ { InputSchema: { @@ -94,7 +94,7 @@ test("Test default implementation", () => { defaults.buildKinesisAnalyticsApp(stack, kinesisProps); - expect(stack).toHaveResourceLike("AWS::KinesisAnalytics::Application", { + Template.fromStack(stack).hasResourceProperties("AWS::KinesisAnalytics::Application", { Inputs: [{ InputSchema: { RecordColumns: [{ diff --git a/source/patterns/@aws-solutions-constructs/core/test/kinesis-firehose-s3-defaults.test.ts b/source/patterns/@aws-solutions-constructs/core/test/kinesis-firehose-s3-defaults.test.ts index 26b77f07f..18ee8f2da 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/kinesis-firehose-s3-defaults.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/kinesis-firehose-s3-defaults.test.ts @@ -15,7 +15,7 @@ import { Stack } from 'aws-cdk-lib'; import * as kinesisfirehose from 'aws-cdk-lib/aws-kinesisfirehose'; import * as defaults from '../index'; import { overrideProps } from '../lib/utils'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import * as kms from 'aws-cdk-lib/aws-kms'; test('test kinesisanalytics override buffer conditions', () => { @@ -37,7 +37,7 @@ test('test kinesisanalytics override buffer conditions', () => { new kinesisfirehose.CfnDeliveryStream(stack, 'KinesisFirehose', outProps); - expect(stack).toHaveResource("AWS::KinesisFirehose::DeliveryStream", { + Template.fromStack(stack).hasResourceProperties("AWS::KinesisFirehose::DeliveryStream", { ExtendedS3DestinationConfiguration: { BucketARN: "bucket_arn", BufferingHints: { diff --git a/source/patterns/@aws-solutions-constructs/core/test/kinesis-streams-defaults.test.ts b/source/patterns/@aws-solutions-constructs/core/test/kinesis-streams-defaults.test.ts index e1d839087..f948cbbef 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/kinesis-streams-defaults.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/kinesis-streams-defaults.test.ts @@ -15,7 +15,7 @@ import { Stack, Duration } from 'aws-cdk-lib'; import * as kinesis from 'aws-cdk-lib/aws-kinesis'; import * as defaults from '../index'; import { overrideProps } from '../lib/utils'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; test('test kinesisstream override RetentionPeriodHours', () => { const stack = new Stack(); @@ -30,7 +30,7 @@ test('test kinesisstream override RetentionPeriodHours', () => { new kinesis.Stream(stack, 'KinesisStream', outProps); - expect(stack).toHaveResource("AWS::Kinesis::Stream", { + Template.fromStack(stack).hasResourceProperties("AWS::Kinesis::Stream", { RetentionPeriodHours: 48 }); }); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/core/test/kinesis-streams-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/kinesis-streams-helper.test.ts index d20800cd1..485c3430b 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/kinesis-streams-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/kinesis-streams-helper.test.ts @@ -15,8 +15,7 @@ import { Stack, Duration } from "aws-cdk-lib"; import * as defaults from '../'; import * as kinesis from 'aws-cdk-lib/aws-kinesis'; -import { ResourcePart } from '@aws-cdk/assert'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; // -------------------------------------------------------------- // Test minimal deployment with no properties @@ -27,14 +26,14 @@ test('Test minimal deployment with no properties', () => { // Helper declaration defaults.buildKinesisStream(stack, {}); - expect(stack).toHaveResourceLike('AWS::Kinesis::Stream', { + Template.fromStack(stack).hasResource('AWS::Kinesis::Stream', { Type: "AWS::Kinesis::Stream", Properties: { StreamEncryption: { EncryptionType: "KMS" } } - }, ResourcePart.CompleteDefinition); + }); }); // -------------------------------------------------------------- @@ -54,11 +53,12 @@ test('Test deployment w/ custom properties', () => { } }); - expect(stack).toHaveResource('AWS::Kinesis::Stream', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::Kinesis::Stream', { Name: 'myCustomKinesisStream' }); // Assertion 3 - expect(stack).toHaveResource('AWS::KMS::Key', { + template.hasResourceProperties('AWS::KMS::Key', { EnableKeyRotation: true }); }); @@ -85,7 +85,7 @@ test('Test deployment w/ existing stream', () => { } }); - expect(stack).toHaveResource('AWS::Kinesis::Stream', { + Template.fromStack(stack).hasResourceProperties('AWS::Kinesis::Stream', { ShardCount: 2, RetentionPeriodHours: 72 }); diff --git a/source/patterns/@aws-solutions-constructs/core/test/kms-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/kms-helper.test.ts index 39ad66320..a9d3bb156 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/kms-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/kms-helper.test.ts @@ -14,8 +14,7 @@ // Imports import { Stack } from "aws-cdk-lib"; import * as defaults from '../'; -import { ResourcePart } from '@aws-cdk/assert'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; // -------------------------------------------------------------- // Test minimal deployment with no properties @@ -26,12 +25,12 @@ test('Test minimal deployment with no properties', () => { // Helper declaration defaults.buildEncryptionKey(stack); - expect(stack).toHaveResourceLike('AWS::KMS::Key', { + Template.fromStack(stack).hasResource('AWS::KMS::Key', { Type: "AWS::KMS::Key", Properties: { EnableKeyRotation: true } - }, ResourcePart.CompleteDefinition); + }); }); // -------------------------------------------------------------- @@ -45,10 +44,10 @@ test('Test minimal deployment with custom properties', () => { enableKeyRotation: false }); - expect(stack).toHaveResourceLike('AWS::KMS::Key', { + Template.fromStack(stack).hasResource('AWS::KMS::Key', { Type: "AWS::KMS::Key", Properties: { EnableKeyRotation: false } - }, ResourcePart.CompleteDefinition); + }); }); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/core/test/lambda-event-source.test.ts b/source/patterns/@aws-solutions-constructs/core/test/lambda-event-source.test.ts index 2bbfcdc77..4c9061b5f 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/lambda-event-source.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/lambda-event-source.test.ts @@ -15,7 +15,7 @@ import * as defaults from '../index'; import { DynamoEventSourceProps, KinesisEventSourceProps, SqsDlq } from 'aws-cdk-lib/aws-lambda-event-sources'; import * as lambda from 'aws-cdk-lib/aws-lambda'; import * as s3 from 'aws-cdk-lib/aws-s3'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import { Duration, Stack } from 'aws-cdk-lib'; test('test DynamoEventSourceProps with defaults', () => { @@ -141,7 +141,7 @@ test('test sqsDlqQueueProps override', () => { } }); - expect(stack).toHaveResource("AWS::SQS::Queue", { + Template.fromStack(stack).hasResourceProperties("AWS::SQS::Queue", { QueueName: "hello-world", VisibilityTimeout: 50 }); diff --git a/source/patterns/@aws-solutions-constructs/core/test/lambda-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/lambda-helper.test.ts index 090aa0695..61c9a5cff 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/lambda-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/lambda-helper.test.ts @@ -15,7 +15,7 @@ import { Stack } from "aws-cdk-lib"; import * as ec2 from "aws-cdk-lib/aws-ec2"; import * as lambda from "aws-cdk-lib/aws-lambda"; import * as defaults from "../index"; -import "@aws-cdk/assert/jest"; +import { Template } from 'aws-cdk-lib/assertions'; import { Duration } from "aws-cdk-lib"; import * as iam from 'aws-cdk-lib/aws-iam'; @@ -30,7 +30,7 @@ test("test FunctionProps override code and runtime", () => { defaults.deployLambdaFunction(stack, inProps); - expect(stack).toHaveResource("AWS::Lambda::Function", { + Template.fromStack(stack).hasResourceProperties("AWS::Lambda::Function", { Handler: "index.handler", Role: { "Fn::GetAtt": ["LambdaFunctionServiceRole0C4CDE0B", "Arn"], @@ -51,7 +51,7 @@ test("test FunctionProps override timeout", () => { defaults.deployLambdaFunction(stack, inProps); - expect(stack).toHaveResource("AWS::Lambda::Function", { + Template.fromStack(stack).hasResourceProperties("AWS::Lambda::Function", { Handler: "index.handler", Role: { "Fn::GetAtt": ["LambdaFunctionServiceRole0C4CDE0B", "Arn"], @@ -72,7 +72,7 @@ test("test FunctionProps for environment variable when runtime = NODEJS", () => defaults.deployLambdaFunction(stack, inProps); - expect(stack).toHaveResource("AWS::Lambda::Function", { + Template.fromStack(stack).hasResourceProperties("AWS::Lambda::Function", { Handler: "index.handler", Role: { "Fn::GetAtt": ["LambdaFunctionServiceRole0C4CDE0B", "Arn"], @@ -97,7 +97,7 @@ test("test FunctionProps when runtime = PYTHON", () => { defaults.deployLambdaFunction(stack, inProps); - expect(stack).toHaveResource( + Template.fromStack(stack).hasResourceProperties( "AWS::Lambda::Function", { Handler: "index.handler", @@ -125,7 +125,7 @@ test("test buildLambdaFunction with deploy = true", () => { lambdaFunctionProps: inProps, }); - expect(stack).toHaveResource("AWS::Lambda::Function", { + Template.fromStack(stack).hasResourceProperties("AWS::Lambda::Function", { Handler: "index.handler", Role: { "Fn::GetAtt": ["LambdaFunctionServiceRole0C4CDE0B", "Arn"], @@ -164,7 +164,7 @@ test("test buildLambdaFunction with FunctionProps", () => { defaults.deployLambdaFunction(stack, inProps); - expect(stack).toHaveResource("AWS::Lambda::Function", { + Template.fromStack(stack).hasResourceProperties("AWS::Lambda::Function", { Handler: "index.handler", Role: { "Fn::GetAtt": ["LambdaFunctionServiceRole0C4CDE0B", "Arn"], @@ -195,7 +195,7 @@ test("test buildLambdaFunction with Tracing Disabled", () => { defaults.deployLambdaFunction(stack, inProps); - expect(stack).toHaveResource("AWS::Lambda::Function", { + Template.fromStack(stack).hasResourceProperties("AWS::Lambda::Function", { Handler: "index.handler", Role: { "Fn::GetAtt": ["LambdaFunctionServiceRole0C4CDE0B", "Arn"], @@ -218,7 +218,7 @@ test("test buildLambdaFunction when Lambda properties includes a VPC", () => { defaults.deployLambdaFunction(stack, lambdaFunctionProps); - expect(stack).toHaveResource("AWS::IAM::Policy", { + Template.fromStack(stack).hasResourceProperties("AWS::IAM::Policy", { PolicyDocument: { Statement: [ { @@ -379,7 +379,7 @@ test('Test environment variable for NodeJS 14.x', () => { defaults.deployLambdaFunction(stack, inProps); // Assertion - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Handler: 'index.handler', Role: { 'Fn::GetAtt': ['LambdaFunctionServiceRole0C4CDE0B', 'Arn'] @@ -406,7 +406,7 @@ test('Test minimum deployment with an existing VPC as a vpc parameter in deployL defaults.deployLambdaFunction(stack, inProps, undefined, fakeVpc); // Assertion - expect(stack).toHaveResourceLike('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { VpcConfig: { SecurityGroupIds: [ { @@ -460,7 +460,7 @@ test('test buildLambdaFunction with lambdaFunctionProps default id', () => { } }); - expect(stack).toHaveResourceLike('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Role: { 'Fn::GetAtt': ['LambdaFunctionServiceRole0C4CDE0B', 'Arn'], }, @@ -479,7 +479,7 @@ test('test buildLambdaFunction with lambdaFunctionProps custom id', () => { } }); - expect(stack).toHaveResourceLike('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Role: { 'Fn::GetAtt': ['MyTestFunctionServiceRole37517223', 'Arn'], }, diff --git a/source/patterns/@aws-solutions-constructs/core/test/mediastore-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/mediastore-helper.test.ts index 54343a274..b2c2e295c 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/mediastore-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/mediastore-helper.test.ts @@ -11,7 +11,7 @@ * and limitations under the License. */ -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import { Stack } from 'aws-cdk-lib'; import * as mediastore from 'aws-cdk-lib/aws-mediastore'; import { MediaStoreContainer } from '../lib/mediastore-helper'; @@ -28,7 +28,7 @@ test('MediaStore container override params', () => { }; MediaStoreContainer(stack, mediaStoreContainerProps); - expect(stack).toHaveResourceLike('AWS::MediaStore::Container', { + Template.fromStack(stack).hasResourceProperties('AWS::MediaStore::Container', { AccessLoggingEnabled: true, CorsPolicy: [ { diff --git a/source/patterns/@aws-solutions-constructs/core/test/opensearch-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/opensearch-helper.test.ts index 0a3c3bb5a..a279045fe 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/opensearch-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/opensearch-helper.test.ts @@ -14,7 +14,7 @@ import { Stack } from 'aws-cdk-lib'; import * as opensearch from 'aws-cdk-lib/aws-opensearchservice'; import * as defaults from '../index'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import * as ec2 from 'aws-cdk-lib/aws-ec2'; import { BuildOpenSearchResponse } from '../index'; @@ -61,7 +61,7 @@ test('Test override SnapshotOptions for buildOpenSearch', () => { expect(buildOpenSearchResponse.domain).toBeDefined(); expect(buildOpenSearchResponse.role).toBeDefined(); - expect(stack).toHaveResource('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { AccessPolicies: { Statement: [ { @@ -151,7 +151,7 @@ test('Test VPC with 1 AZ, Zone Awareness Disabled', () => { } }, undefined, vpc); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { DomainName: "test-domain", ClusterConfig: { DedicatedMasterCount: 3, @@ -173,7 +173,7 @@ test('Test VPC with 2 AZ, Zone Awareness Enabled', () => { expect(buildOpenSearchResponse.domain).toBeDefined(); expect(buildOpenSearchResponse.role).toBeDefined(); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { DomainName: "test-domain", ClusterConfig: { DedicatedMasterCount: 3, @@ -193,7 +193,7 @@ test('Test VPC with 3 AZ, Zone Awareness Enabled', () => { buildTestOpenSearchDomain(stack, 'test-domain', {}, undefined, vpc); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { DomainName: "test-domain", ClusterConfig: { DedicatedMasterCount: 3, @@ -225,7 +225,7 @@ test('Test deployment with an existing private VPC', () => { buildTestOpenSearchDomain(stack, 'test-domain', {}, undefined, vpc); - expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { DomainName: "test-domain", ClusterConfig: { DedicatedMasterCount: 3, @@ -265,7 +265,7 @@ test('Test engine version override for buildOpenSearch', () => { engineVersion: 'OpenSearch_1.0' }); - expect(stack).toHaveResource('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { AccessPolicies: { Statement: [ { @@ -349,7 +349,7 @@ test('Test deployment with lambdaRoleARN', () => { expect(buildOpenSearchResponse.domain).toBeDefined(); expect(buildOpenSearchResponse.role).toBeDefined(); - expect(stack).toHaveResource('AWS::OpenSearchService::Domain', { + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { AccessPolicies: { Statement: [ { diff --git a/source/patterns/@aws-solutions-constructs/core/test/override-warning-service.test.ts b/source/patterns/@aws-solutions-constructs/core/test/override-warning-service.test.ts index 03145253b..7edad5996 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/override-warning-service.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/override-warning-service.test.ts @@ -11,7 +11,6 @@ * and limitations under the License. */ -import '@aws-cdk/assert/jest'; import * as log from 'npmlog'; import * as process from 'process'; import { flagOverriddenDefaults } from '../lib/override-warning-service'; diff --git a/source/patterns/@aws-solutions-constructs/core/test/s3-bucket-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/s3-bucket-helper.test.ts index 1e158f5cd..43987768d 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/s3-bucket-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/s3-bucket-helper.test.ts @@ -11,13 +11,13 @@ * and limitations under the License. */ -import { expect as expectCDK, haveResource, ResourcePart } from '@aws-cdk/assert'; import { Duration, Stack, RemovalPolicy } from 'aws-cdk-lib'; import * as s3 from 'aws-cdk-lib/aws-s3'; import * as s3n from 'aws-cdk-lib/aws-s3-notifications'; import * as defaults from '../index'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import { Bucket, StorageClass } from 'aws-cdk-lib/aws-s3'; +import { expectNonexistence } from "./test-helper"; test('check exception for Missing existingBucketObj from props for deploy = false', () => { const stack = new Stack(); @@ -37,13 +37,14 @@ test('s3 bucket with bucketId', () => { expect(buildS3BucketResponse.bucket).toBeDefined(); expect(buildS3BucketResponse.loggingBucket).toBeDefined(); - expectCDK(stack).to(haveResource("AWS::S3::Bucket", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::S3::Bucket", { LoggingConfiguration: { DestinationBucketName: { Ref: "myS3LoggingBucketDE461344" } }, - })); + }); }); test('s3 bucket with bucketProps', () => { @@ -58,9 +59,10 @@ test('s3 bucket with bucketProps', () => { expect(buildS3BucketResponse.bucket).toBeDefined(); expect(buildS3BucketResponse.loggingBucket).toBeDefined(); - expectCDK(stack).to(haveResource("AWS::S3::Bucket", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::S3::Bucket", { BucketName: "mybucket" - })); + }); }); test('s3 bucket with default props', () => { @@ -71,7 +73,8 @@ test('s3 bucket with default props', () => { expect(buildS3BucketResponse.bucket).toBeDefined(); expect(buildS3BucketResponse.loggingBucket).toBeDefined(); - expectCDK(stack).to(haveResource("AWS::S3::Bucket", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::S3::Bucket", { BucketEncryption: { ServerSideEncryptionConfiguration: [ { @@ -90,7 +93,7 @@ test('s3 bucket with default props', () => { VersioningConfiguration: { Status: "Enabled" } - })); + }); }); test('s3 bucket with life cycle policy', () => { @@ -114,7 +117,8 @@ test('s3 bucket with life cycle policy', () => { expect(buildS3BucketResponse.bucket).toBeDefined(); expect(buildS3BucketResponse.loggingBucket).toBeDefined(); - expectCDK(stack).to(haveResource("AWS::S3::Bucket", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::S3::Bucket", { LifecycleConfiguration: { Rules: [ { @@ -133,7 +137,7 @@ test('s3 bucket with life cycle policy', () => { } ] } - })); + }); }); test('s3 bucket with access logging configured', () => { @@ -152,62 +156,62 @@ test('s3 bucket with access logging configured', () => { // This value should be populated, entered Issue 907 // expect(response.loggingBucket).toBeDefined(); - expectCDK(stack).to(haveResource("AWS::S3::Bucket", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::S3::Bucket", { LoggingConfiguration: { DestinationBucketName: { Ref: "mybucket160F8132" } }, - })); + }); }); test('Check S3 Bucket policy', () => { const stack = new Stack(); defaults.buildS3Bucket(stack, {}); - expectCDK(stack).to( - haveResource("AWS::S3::BucketPolicy", { - PolicyDocument: { - Statement: [ - { - Action: "s3:*", - Condition: { - Bool: { - "aws:SecureTransport": "false", - }, + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::S3::BucketPolicy", { + PolicyDocument: { + Statement: [ + { + Action: "s3:*", + Condition: { + Bool: { + "aws:SecureTransport": "false", }, - Effect: "Deny", - Principal: { - AWS: "*" + }, + Effect: "Deny", + Principal: { + AWS: "*" + }, + Resource: [ + { + "Fn::GetAtt": [ + "S3Bucket07682993", + "Arn" + ] }, - Resource: [ - { - "Fn::GetAtt": [ - "S3Bucket07682993", - "Arn" - ] - }, - { - "Fn::Join": [ - "", - [ - { - "Fn::GetAtt": [ - "S3Bucket07682993", - "Arn" - ] - }, - "/*" - ] + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "S3Bucket07682993", + "Arn" + ] + }, + "/*" ] - } - ] - } - ], - Version: "2012-10-17", - }, - }) - ); + ] + } + ] + } + ], + Version: "2012-10-17", + }, + }); }); test('s3 bucket with LoggingBucket and versioning turned off', () => { @@ -228,7 +232,8 @@ test('s3 bucket with LoggingBucket and versioning turned off', () => { // The line below fails, this appears to be a bug. Entered Issue 906 // expect(response.loggingBucket).toBeDefined(); - expectCDK(stack).to(haveResource("AWS::S3::Bucket", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::S3::Bucket", { BucketEncryption: { ServerSideEncryptionConfiguration: [ { @@ -250,7 +255,7 @@ test('s3 bucket with LoggingBucket and versioning turned off', () => { IgnorePublicAcls: true, RestrictPublicBuckets: true } - })); + }); }); test('s3 bucket versioning turned off', () => { @@ -266,7 +271,8 @@ test('s3 bucket versioning turned off', () => { expect(buildS3BucketResponse.bucket).toBeDefined(); expect(buildS3BucketResponse.loggingBucket).toBeDefined(); - expectCDK(stack).to(haveResource("AWS::S3::Bucket", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::S3::Bucket", { BucketEncryption: { ServerSideEncryptionConfiguration: [ { @@ -288,7 +294,7 @@ test('s3 bucket versioning turned off', () => { IgnorePublicAcls: true, RestrictPublicBuckets: true } - })); + }); }); test('s3 bucket with LoggingBucket and auto delete objects', () => { @@ -304,11 +310,12 @@ test('s3 bucket with LoggingBucket and auto delete objects', () => { expect(buildS3BucketResponse.bucket).toBeDefined(); expect(buildS3BucketResponse.loggingBucket).toBeDefined(); - expectCDK(stack).to(haveResource("AWS::S3::Bucket", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::S3::Bucket", { AccessControl: "LogDeliveryWrite" - })); + }); - expectCDK(stack).to(haveResource("Custom::S3AutoDeleteObjects", { + template.hasResourceProperties("Custom::S3AutoDeleteObjects", { ServiceToken: { "Fn::GetAtt": [ "CustomS3AutoDeleteObjectsCustomResourceProviderHandler9D90184F", @@ -318,7 +325,7 @@ test('s3 bucket with LoggingBucket and auto delete objects', () => { BucketName: { Ref: "S3LoggingBucket800A2B27" } - })); + }); }); test('s3 bucket versioning turned on', () => { @@ -333,7 +340,9 @@ test('s3 bucket versioning turned on', () => { expect(buildS3BucketResponse.bucket).toBeDefined(); expect(buildS3BucketResponse.loggingBucket).toBeDefined(); - expectCDK(stack).to(haveResource("AWS::S3::Bucket", { + const template = Template.fromStack(stack); + + template.hasResourceProperties("AWS::S3::Bucket", { BucketEncryption: { ServerSideEncryptionConfiguration: [ { @@ -371,7 +380,7 @@ test('s3 bucket versioning turned on', () => { VersioningConfiguration: { Status: "Enabled" } - })); + }); }); test('Suppress cfn-nag warning for s3 bucket notification', () => { @@ -381,7 +390,8 @@ test('Suppress cfn-nag warning for s3 bucket notification', () => { buildS3BucketResponse.bucket.addEventNotification(s3.EventType.OBJECT_CREATED, new s3n.SqsDestination(buildQueueResponse.queue)); defaults.addCfnNagS3BucketNotificationRulesToSuppress(stack, "BucketNotificationsHandler050a0587b7544547bf325f094a3db834"); - expectCDK(stack).to(haveResource("AWS::Lambda::Function", { + const template = Template.fromStack(stack); + template.hasResource("AWS::Lambda::Function", { Metadata: { cfn_nag: { rules_to_suppress: [ @@ -400,9 +410,9 @@ test('Suppress cfn-nag warning for s3 bucket notification', () => { ] } } - }, ResourcePart.CompleteDefinition)); + }); - expectCDK(stack).to(haveResource("AWS::IAM::Policy", { + template.hasResource("AWS::IAM::Policy", { Metadata: { cfn_nag: { rules_to_suppress: [ @@ -413,7 +423,7 @@ test('Suppress cfn-nag warning for s3 bucket notification', () => { ] } } - }, ResourcePart.CompleteDefinition)); + }); }); test('test s3Bucket removalPolicy override', () => { @@ -425,14 +435,14 @@ test('test s3Bucket removalPolicy override', () => { }, }, 'test-bucket'); - expect(stack).toHaveResourceLike("AWS::S3::Bucket", { + Template.fromStack(stack).hasResource("AWS::S3::Bucket", { Type: 'AWS::S3::Bucket', Properties: { AccessControl: "LogDeliveryWrite" }, UpdateReplacePolicy: "Delete", DeletionPolicy: "Delete" - }, ResourcePart.CompleteDefinition); + }); }); test('s3 bucket with logging turned off', () => { @@ -445,8 +455,8 @@ test('s3 bucket with logging turned off', () => { expect(respbuildS3BucketResponsense.bucket).toBeDefined(); expect(respbuildS3BucketResponsense.loggingBucket).not.toBeDefined(); - expect(stack).not.toHaveResourceLike("AWS::S3::Bucket", { + expectNonexistence(stack, "AWS::S3::Bucket", { LoggingConfiguration: { - }, + } }); }); diff --git a/source/patterns/@aws-solutions-constructs/core/test/s3-bucket.test.ts b/source/patterns/@aws-solutions-constructs/core/test/s3-bucket.test.ts index 90267be16..b3e5b0176 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/s3-bucket.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/s3-bucket.test.ts @@ -16,7 +16,8 @@ import * as s3 from 'aws-cdk-lib/aws-s3'; import * as kms from 'aws-cdk-lib/aws-kms'; import * as defaults from '../index'; import { overrideProps } from '../lib/utils'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; +import { expectNonexistence } from "./test-helper"; test('test s3Bucket override versioningConfiguration', () => { const stack = new Stack(); @@ -29,7 +30,7 @@ test('test s3Bucket override versioningConfiguration', () => { const outProps = overrideProps(defaultProps, inProps); new s3.Bucket(stack, 'test-s3-verioning', outProps); - expect(stack).toHaveResource("AWS::S3::Bucket", { + Template.fromStack(stack).hasResourceProperties("AWS::S3::Bucket", { BucketEncryption: { ServerSideEncryptionConfiguration: [ { @@ -60,7 +61,7 @@ test('test s3Bucket override bucketEncryption', () => { const outProps = overrideProps(defaultProps, inProps); new s3.Bucket(stack, 'test-s3-encryption', outProps); - expect(stack).toHaveResource("AWS::S3::Bucket", { + Template.fromStack(stack).hasResourceProperties("AWS::S3::Bucket", { BucketEncryption: { ServerSideEncryptionConfiguration: [ { @@ -90,7 +91,7 @@ test('test s3Bucket override publicAccessBlockConfiguration', () => { const outProps = overrideProps(defaultProps, inProps); new s3.Bucket(stack, 'test-s3-publicAccessBlock', outProps); - expect(stack).toHaveResource("AWS::S3::Bucket", { + Template.fromStack(stack).hasResourceProperties("AWS::S3::Bucket", { PublicAccessBlockConfiguration: { BlockPublicAcls: true, IgnorePublicAcls: true @@ -111,7 +112,7 @@ test('test s3Bucket add lifecycleConfiguration', () => { const outProps = overrideProps(defaultProps, inProps); new s3.Bucket(stack, 'test-s3-lifecycle', outProps); - expect(stack).toHaveResource("AWS::S3::Bucket", { + Template.fromStack(stack).hasResourceProperties("AWS::S3::Bucket", { LifecycleConfiguration: { Rules: [ { @@ -134,7 +135,7 @@ test('test s3Bucket override serverAccessLogsBucket', () => { bucketProps: myS3Props }); - expect(stack).toHaveResource("AWS::S3::Bucket", { + Template.fromStack(stack).hasResourceProperties("AWS::S3::Bucket", { LoggingConfiguration: { DestinationBucketName: { Ref: "MyS3LoggingBucket119BE896" @@ -150,7 +151,7 @@ test('test createAlbLoggingBucket()', () => { bucketName: 'test-name' }); - expect(stack).toHaveResource("AWS::S3::Bucket", { + Template.fromStack(stack).hasResourceProperties("AWS::S3::Bucket", { BucketName: 'test-name' }); }); @@ -164,7 +165,7 @@ test('Test bucket policy that only accepts SSL requests only', () => { } }, 'test-bucket'); - expect(stack).toHaveResource("AWS::S3::BucketPolicy", { + Template.fromStack(stack).hasResourceProperties("AWS::S3::BucketPolicy", { PolicyDocument: { Statement: [ { @@ -216,7 +217,7 @@ test('Test bucket policy that accepts any requests', () => { } }, 'test-bucket'); - expect(stack).not.toHaveResource("AWS::S3::BucketPolicy", { + expectNonexistence(stack, "AWS::S3::BucketPolicy", { PolicyDocument: { Statement: [ { @@ -264,7 +265,7 @@ test('Test enforcing SSL when bucketProps is not provided', () => { defaults.buildS3Bucket(stack, {}, 'test-bucket'); - expect(stack).toHaveResource("AWS::S3::BucketPolicy", { + Template.fromStack(stack).hasResourceProperties("AWS::S3::BucketPolicy", { PolicyDocument: { Statement: [ { @@ -317,7 +318,7 @@ test('Test enforcing SSL when bucketProps is provided and enforceSSL is not set' } }, 'test-bucket'); - expect(stack).toHaveResource("AWS::S3::BucketPolicy", { + Template.fromStack(stack).hasResourceProperties("AWS::S3::BucketPolicy", { PolicyDocument: { Statement: [ { diff --git a/source/patterns/@aws-solutions-constructs/core/test/sagemaker-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/sagemaker-helper.test.ts index 146c642f6..ac6e09bc8 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/sagemaker-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/sagemaker-helper.test.ts @@ -16,7 +16,7 @@ import * as iam from 'aws-cdk-lib/aws-iam'; import * as kms from 'aws-cdk-lib/aws-kms'; import * as ec2 from 'aws-cdk-lib/aws-ec2'; import * as defaults from '../'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; test('Test deployment with VPC', () => { // Stack @@ -74,7 +74,7 @@ test('Test deployment w/ existing VPC', () => { expect(buildSagemakerNotebookResponse.vpc).not.toBeDefined(); expect(buildSagemakerNotebookResponse.securityGroup).not.toBeDefined(); - expect(stack).toHaveResource('AWS::SageMaker::NotebookInstance', { + Template.fromStack(stack).hasResourceProperties('AWS::SageMaker::NotebookInstance', { DirectInternetAccess: 'Disabled', SecurityGroupIds: ['sg-deadbeef'], SubnetId: 'subnet-deadbeef', @@ -96,7 +96,7 @@ test('Test deployment w/ override', () => { kmsKeyId: key.keyArn, }, }); - expect(stack).toHaveResource('AWS::SageMaker::NotebookInstance', { + Template.fromStack(stack).hasResourceProperties('AWS::SageMaker::NotebookInstance', { DirectInternetAccess: 'Disabled', InstanceType: 'ml.c4.2xlarge', KmsKeyId: { diff --git a/source/patterns/@aws-solutions-constructs/core/test/secretsmanager-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/secretsmanager-helper.test.ts index 1988c34d4..b6b1717c1 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/secretsmanager-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/secretsmanager-helper.test.ts @@ -13,8 +13,7 @@ import {RemovalPolicy, Stack} from 'aws-cdk-lib'; import * as defaults from '../'; -import {ResourcePart} from '@aws-cdk/assert'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; const DESCRIPTION = 'test secret description'; const SECRET_NAME = 'test secret name'; @@ -28,11 +27,11 @@ test('Test minimal deployment with no properties', () => { // Helper declaration defaults.buildSecretsManagerSecret(stack, 'secret', {}); - expect(stack).toHaveResourceLike('AWS::SecretsManager::Secret', { + Template.fromStack(stack).hasResource('AWS::SecretsManager::Secret', { Type: 'AWS::SecretsManager::Secret', UpdateReplacePolicy: 'Retain', DeletionPolicy: 'Retain' - }, ResourcePart.CompleteDefinition); + }); }); // -------------------------------------------------------------- @@ -48,7 +47,7 @@ test('Test deployment with custom properties', () => { removalPolicy: RemovalPolicy.DESTROY, }); // Assertion 1 - expect(stack).toHaveResourceLike('AWS::SecretsManager::Secret', { + Template.fromStack(stack).hasResource('AWS::SecretsManager::Secret', { Type: 'AWS::SecretsManager::Secret', UpdateReplacePolicy: 'Delete', DeletionPolicy: 'Delete', @@ -56,5 +55,5 @@ test('Test deployment with custom properties', () => { Name: SECRET_NAME, Description: DESCRIPTION } - }, ResourcePart.CompleteDefinition); + }); }); diff --git a/source/patterns/@aws-solutions-constructs/core/test/security-group-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/security-group-helper.test.ts index 1c8ad0ea1..a32035402 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/security-group-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/security-group-helper.test.ts @@ -13,7 +13,7 @@ import { Stack } from "aws-cdk-lib"; import * as defaults from "../"; -import "@aws-cdk/assert/jest"; +import { Template } from 'aws-cdk-lib/assertions'; import * as ec2 from "aws-cdk-lib/aws-ec2"; // -------------------------------------------------------------- @@ -37,7 +37,7 @@ test("Test minimal deployment with no properties", () => { [] ); - expect(stack).toHaveResource("AWS::EC2::SecurityGroup", { + Template.fromStack(stack).hasResourceProperties("AWS::EC2::SecurityGroup", { SecurityGroupEgress: [ { CidrIp: "0.0.0.0/0", @@ -66,7 +66,7 @@ test("Test deployment with ingress rules", () => { [] ); - expect(stack).toHaveResource("AWS::EC2::SecurityGroup", { + Template.fromStack(stack).hasResourceProperties("AWS::EC2::SecurityGroup", { SecurityGroupIngress: [ { CidrIp: "1.1.1.1/16", @@ -100,7 +100,7 @@ test("Test deployment with egress rule", () => { ] ); - expect(stack).toHaveResource("AWS::EC2::SecurityGroup", { + Template.fromStack(stack).hasResourceProperties("AWS::EC2::SecurityGroup", { SecurityGroupEgress: [ { CidrIp: "1.1.1.1/16", @@ -135,7 +135,7 @@ test("Test self referencing security group", () => { testPort, ); - expect(stack).toHaveResourceLike("AWS::EC2::SecurityGroupIngress", { + Template.fromStack(stack).hasResourceProperties("AWS::EC2::SecurityGroupIngress", { IpProtocol: "TCP", FromPort: testPort, ToPort: testPort, diff --git a/source/patterns/@aws-solutions-constructs/core/test/sns-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/sns-helper.test.ts index b1b1e9407..225b15abe 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/sns-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/sns-helper.test.ts @@ -14,8 +14,7 @@ // Imports import { Stack } from "aws-cdk-lib"; import * as defaults from '../'; -import { expect as expectCDK, haveResource } from '@aws-cdk/assert'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import * as kms from 'aws-cdk-lib/aws-kms'; import * as sns from 'aws-cdk-lib/aws-sns'; import { expectKmsKeyAttachedToCorrectResource } from "../"; @@ -31,7 +30,7 @@ test('Test deployment with no properties using AWS Managed KMS Key', () => { expect(buildTopicResponse.topic).toBeDefined(); expect(buildTopicResponse.key).toBeDefined(); - expect(stack).toHaveResource("AWS::SNS::Topic", { + Template.fromStack(stack).hasResourceProperties("AWS::SNS::Topic", { KmsMasterKeyId: { "Fn::Join": [ "", @@ -69,11 +68,12 @@ test('Test deployment without imported encryption key', () => { enableEncryptionWithCustomerManagedKey: true }); - expect(stack).toHaveResource("AWS::SNS::Topic", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::SNS::Topic", { TopicName: "custom-topic" }); // Assertion 3 - expect(stack).toHaveResource("AWS::KMS::Key", { + template.hasResourceProperties("AWS::KMS::Key", { EnableKeyRotation: true }); }); @@ -98,7 +98,7 @@ test('Test deployment w/ imported encryption key', () => { expect(buildTopicResponse.topic).toBeDefined(); expect(buildTopicResponse.key).toBeDefined(); - expect(stack).toHaveResource("AWS::SNS::Topic", { + Template.fromStack(stack).hasResourceProperties("AWS::SNS::Topic", { KmsMasterKeyId: { "Fn::GetAtt": [ "EncryptionKey1B843E66", @@ -116,7 +116,7 @@ test('enableEncryptionWithCustomerManagedKey flag is ignored when encryptionKey encryptionKey: defaults.buildEncryptionKey(stack) }); - expect(stack).toHaveResource("AWS::SNS::Topic", { + Template.fromStack(stack).hasResourceProperties("AWS::SNS::Topic", { KmsMasterKeyId: { "Fn::GetAtt": [ "EncryptionKey1B843E66", @@ -135,7 +135,7 @@ test('enableEncryptionWithCustomerManagedKey flag is ignored when topicProps.mas } }); - expect(stack).toHaveResource("AWS::SNS::Topic", { + Template.fromStack(stack).hasResourceProperties("AWS::SNS::Topic", { KmsMasterKeyId: { "Fn::GetAtt": [ "EncryptionKey1B843E66", @@ -155,7 +155,8 @@ test('enableEncryptionWithCustomerManagedKey flag is ignored when encryptionKeyP }, }); - expect(stack).toHaveResource("AWS::SNS::Topic", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::SNS::Topic", { KmsMasterKeyId: { "Fn::GetAtt": [ "EncryptionKey1B843E66", @@ -164,7 +165,7 @@ test('enableEncryptionWithCustomerManagedKey flag is ignored when encryptionKeyP } }); - expect(stack).toHaveResource("AWS::KMS::Key", { + template.hasResourceProperties("AWS::KMS::Key", { Description: description }); }); @@ -178,7 +179,7 @@ test('encryptionProps are set correctly on the SNS Topic', () => { } }); - expect(stack).toHaveResource("AWS::KMS::Key", { + Template.fromStack(stack).hasResourceProperties("AWS::KMS::Key", { Description: description }); }); @@ -187,7 +188,8 @@ test('Check SNS Topic policy', () => { const stack = new Stack(); defaults.buildTopic(stack, {}); - expectCDK(stack).to(haveResource("AWS::SNS::TopicPolicy", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::SNS::TopicPolicy", { PolicyDocument: { Statement: [ { @@ -262,7 +264,7 @@ test('Check SNS Topic policy', () => { ], Version: "2012-10-17" }, - })); + }); }); test('existing topic encrypted with CMK is not overridden by defaults', () => { @@ -284,8 +286,9 @@ test('existing topic encrypted with CMK is not overridden by defaults', () => { expectKmsKeyAttachedToCorrectResource(stack, 'AWS::SNS::Topic', 'new-key-description'); // Make sure the construct did not create any other topics or keys created - expect(stack).toCountResources('AWS::KMS::Key', 1); - expect(stack).toCountResources('AWS::SNS::Topic', 1); + const template = Template.fromStack(stack); + template.resourceCountIs('AWS::KMS::Key', 1); + template.resourceCountIs('AWS::SNS::Topic', 1); }); test('existing unencrypted topic is not overridden with defaults', () => { @@ -300,6 +303,7 @@ test('existing unencrypted topic is not overridden with defaults', () => { expect(buildBuildTopicResponse.topic).toBeDefined(); expect(buildBuildTopicResponse.key).not.toBeDefined(); // Make sure the construct did not create any other topics and that no keys exist - expect(stack).toCountResources('AWS::KMS::Key', 0); - expect(stack).toCountResources('AWS::SNS::Topic', 1); + const template = Template.fromStack(stack); + template.resourceCountIs('AWS::KMS::Key', 0); + template.resourceCountIs('AWS::SNS::Topic', 1); }); diff --git a/source/patterns/@aws-solutions-constructs/core/test/sqs-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/sqs-helper.test.ts index e995e16ad..44ce77d05 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/sqs-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/sqs-helper.test.ts @@ -15,7 +15,7 @@ import { Stack } from "aws-cdk-lib"; import * as sqs from 'aws-cdk-lib/aws-sqs'; import * as defaults from '../'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import { buildDeadLetterQueue, buildQueue } from "../lib/sqs-helper"; import * as kms from 'aws-cdk-lib/aws-kms'; import { expectKmsKeyAttachedToCorrectResource } from "../"; @@ -48,10 +48,11 @@ test('Test deployment w/ imported encryption key', () => { encryptionKey: defaults.buildEncryptionKey(stack) }); - expect(stack).toHaveResource("AWS::SQS::Queue", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::SQS::Queue", { QueueName: "existing-queue" }); - expect(stack).toHaveResource("AWS::KMS::Key", { + template.hasResourceProperties("AWS::KMS::Key", { EnableKeyRotation: true }); }); @@ -66,7 +67,7 @@ test('Test deployment without imported encryption key', () => { } }); - expect(stack).toHaveResource("AWS::SQS::Queue", { + Template.fromStack(stack).hasResourceProperties("AWS::SQS::Queue", { QueueName: "existing-queue", KmsMasterKeyId: "alias/aws/sqs" }); @@ -83,10 +84,11 @@ test('Test deployment w/ construct created encryption key', () => { enableEncryptionWithCustomerManagedKey: true, }); - expect(stack).toHaveResource("AWS::SQS::Queue", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::SQS::Queue", { QueueName: "existing-queue" }); - expect(stack).toHaveResource("AWS::KMS::Key", { + template.hasResourceProperties("AWS::KMS::Key", { EnableKeyRotation: true }); expect(buildQueueResponse.queue).toBeDefined(); @@ -104,14 +106,14 @@ test('Test DLQ when existing Queue Provided', () => { const returnedQueue = defaults.buildDeadLetterQueue(stack, buildDlqProps); expect(returnedQueue).toBeUndefined(); - expect(stack).toCountResources("AWS::SQS::Queue", 1); + Template.fromStack(stack).resourceCountIs("AWS::SQS::Queue", 1); }); test('Test DLQ with all defaults', () => { const stack = new Stack(); buildDeadLetterQueue(stack, {}); - expect(stack).toHaveResourceLike("AWS::SQS::Queue", { + Template.fromStack(stack).hasResourceProperties("AWS::SQS::Queue", { KmsMasterKeyId: "alias/aws/sqs" }); }); @@ -125,7 +127,7 @@ test("Test DLQ with a provided properties", () => { queueName: testQueueName, }, }); - expect(stack).toHaveResourceLike("AWS::SQS::Queue", { + Template.fromStack(stack).hasResourceProperties("AWS::SQS::Queue", { QueueName: testQueueName, }); expect(returnedQueue).toBeDefined(); @@ -153,7 +155,7 @@ test('Test returning an existing Queue', () => { existingQueueObj: existingQueue }); - expect(stack).toHaveResourceLike("AWS::SQS::Queue", { + Template.fromStack(stack).hasResourceProperties("AWS::SQS::Queue", { QueueName: testQueueName, }); expect(existingQueue.queueName).toEqual(buildQueueResponse.queue.queueName); @@ -169,7 +171,7 @@ test('Test creating a queue with a DLQ', () => { deadLetterQueue: dlqInterface }); - expect(stack).toCountResources("AWS::SQS::Queue", 2); + Template.fromStack(stack).resourceCountIs("AWS::SQS::Queue", 2); expect(buildQueueResponse.queue).toBeDefined(); expect(buildQueueResponse.queue.deadLetterQueue).toBeDefined(); }); @@ -183,7 +185,7 @@ test('Test creating a FIFO queue', () => { } }); - expect(stack).toHaveResourceLike("AWS::SQS::Queue", { + Template.fromStack(stack).hasResourceProperties("AWS::SQS::Queue", { FifoQueue: true }); expect(buildQueueResponse.queue.fifo).toBe(true); diff --git a/source/patterns/@aws-solutions-constructs/core/test/ssm-string-parameter-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/ssm-string-parameter-helper.test.ts index 1837c1a3d..6f9e56b09 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/ssm-string-parameter-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/ssm-string-parameter-helper.test.ts @@ -13,7 +13,7 @@ import {Stack} from 'aws-cdk-lib'; import * as defaults from '../'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; // -------------------------------------------------------------- // Test minimal deployment with no properties @@ -25,7 +25,7 @@ test('Test minimal deployment with required properties', () => { const parameterValue = "test-val"; defaults.buildSsmStringParameter(stack, 'parameterName', {stringValue: parameterValue}); - expect(stack).toHaveResourceLike('AWS::SSM::Parameter', { + Template.fromStack(stack).hasResourceProperties('AWS::SSM::Parameter', { Type: 'String', Value: parameterValue }); diff --git a/source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts index 9911c83c8..4de810912 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts @@ -14,7 +14,6 @@ // Imports import { Stack, Aws } from "aws-cdk-lib"; import * as defaults from '../'; -import '@aws-cdk/assert/jest'; import * as sfn from 'aws-cdk-lib/aws-stepfunctions'; import { buildLogGroup } from '../lib/cloudwatch-log-group-helper'; import * as iam from 'aws-cdk-lib/aws-iam'; @@ -32,9 +31,10 @@ test('Test deployment w/ custom properties', () => { }); // Assertion expect(buildStateMachineResponse.stateMachine).toBeDefined(); - expect(stack).toCountResources("AWS::Logs::LogGroup", 1); + const template = Template.fromStack(stack); + template.resourceCountIs("AWS::Logs::LogGroup", 1); - expect(stack).toHaveResource("AWS::StepFunctions::StateMachine", { + template.hasResourceProperties("AWS::StepFunctions::StateMachine", { StateMachineName: "myStateMachine" }); }); @@ -57,11 +57,12 @@ test('Test deployment w/ logging enabled', () => { } }); // Assertion - expect(stack).toCountResources("AWS::Logs::LogGroup", 1); + const template = Template.fromStack(stack); + template.resourceCountIs("AWS::Logs::LogGroup", 1); expect(buildStateMachineResponse.stateMachine).toBeDefined(); expect(buildStateMachineResponse.stateMachine).toBeDefined(); - expect(stack).toHaveResource("AWS::StepFunctions::StateMachine", { + template.hasResourceProperties("AWS::StepFunctions::StateMachine", { LoggingConfiguration: { Destinations: [{ CloudWatchLogsLogGroup: { @@ -90,7 +91,7 @@ test('Check default Cloudwatch permissions', () => { // Assertion expect(buildStateMachineResponse.stateMachine).toBeDefined(); expect(buildStateMachineResponse.stateMachine).toBeDefined(); - expect(stack).toHaveResource("AWS::IAM::Policy", { + Template.fromStack(stack).hasResourceProperties("AWS::IAM::Policy", { PolicyDocument: { Statement: [ { @@ -182,10 +183,11 @@ test('Test deployment with custom role', () => { }); // Assertion - expect(stack).toCountResources("AWS::IAM::Role", 1); + const template = Template.fromStack(stack); + template.resourceCountIs("AWS::IAM::Role", 1); expect(buildStateMachineResponse.stateMachine).toBeDefined(); - expect(stack).toHaveResource("AWS::IAM::Role", { + template.hasResourceProperties("AWS::IAM::Role", { Description: descriptionText }); }); @@ -203,7 +205,8 @@ test('Confirm format of name', () => { // Assertion expect(buildStateMachineResponse.stateMachine).toBeDefined(); - expect(stack).toHaveResource("AWS::StepFunctions::StateMachine", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::StepFunctions::StateMachine", { StateMachineName: "myStateMachine" }); @@ -211,7 +214,7 @@ test('Confirm format of name', () => { const expectedPrefix = '/aws/vendedlogs/states/constructs/'; const lengthOfDatetimeSuffix = 13; - const LogGroup = Template.fromStack(stack).findResources("AWS::Logs::LogGroup"); + const LogGroup = template.findResources("AWS::Logs::LogGroup"); const logName = LogGroup.StateMachineLogGroup15B91BCB.Properties.LogGroupName; const suffix = logName.slice(-lengthOfDatetimeSuffix); diff --git a/source/patterns/@aws-solutions-constructs/core/test/test-helper.ts b/source/patterns/@aws-solutions-constructs/core/test/test-helper.ts index c2bf30045..056e94de5 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/test-helper.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/test-helper.ts @@ -164,7 +164,7 @@ export function expectKmsKeyAttachedToCorrectResource(stack: Stack, parentResour }); const [ logicalId ] = Object.keys(resource); - expect(stack).toHaveResource(parentResourceType, { + Template.fromStack(stack).hasResourceProperties(parentResourceType, { KmsMasterKeyId: { "Fn::GetAtt": [ logicalId, @@ -173,3 +173,8 @@ export function expectKmsKeyAttachedToCorrectResource(stack: Stack, parentResour } }); } + +export function expectNonexistence(stack: Stack, type: string, props: object) { + const shouldFindNothing = Template.fromStack(stack).findResources(type, props); + expect(Object.keys(shouldFindNothing).length).toEqual(0); +} diff --git a/source/patterns/@aws-solutions-constructs/core/test/vpc-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/vpc-helper.test.ts index b781dd4cd..73c0b3322 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/vpc-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/vpc-helper.test.ts @@ -14,8 +14,7 @@ import { Stack } from 'aws-cdk-lib'; import * as defaults from '../'; import * as ec2 from 'aws-cdk-lib/aws-ec2'; -import { SynthUtils } from '@aws-cdk/assert'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import { AddAwsServiceEndpoint, ServiceEndpointTypes } from '../lib/vpc-helper'; import { DefaultPublicPrivateVpcProps, DefaultIsolatedVpcProps } from '../lib/vpc-defaults'; @@ -30,13 +29,14 @@ test("Test minimal deployment with no properties", () => { defaultVpcProps: DefaultIsolatedVpcProps(), }); - expect(SynthUtils.toCloudFormation(stack)).toHaveResource('AWS::EC2::VPC', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::EC2::VPC', { EnableDnsHostnames: true, EnableDnsSupport: true, }); - expect(SynthUtils.toCloudFormation(stack)).toCountResources('AWS::EC2::Subnet', 2); - expect(SynthUtils.toCloudFormation(stack)).toCountResources('AWS::EC2::InternetGateway', 0); + template.resourceCountIs('AWS::EC2::Subnet', 2); + template.resourceCountIs('AWS::EC2::InternetGateway', 0); }); // -------------------------------------------------------------- @@ -54,7 +54,7 @@ test('Test deployment w/ user provided custom properties', () => { ipAddresses: ec2.IpAddresses.cidr('172.168.0.0/19'), }, }); - expect(stack).toHaveResource('AWS::EC2::VPC', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::VPC', { CidrBlock: '172.168.0.0/19', EnableDnsHostnames: false, EnableDnsSupport: false, @@ -76,7 +76,7 @@ test('Test deployment w/ construct provided custom properties', () => { ipAddresses: ec2.IpAddresses.cidr('172.168.0.0/19'), }, }); - expect(stack).toHaveResource('AWS::EC2::VPC', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::VPC', { CidrBlock: '172.168.0.0/19', EnableDnsHostnames: true, EnableDnsSupport: true, @@ -103,7 +103,7 @@ test('Test deployment w/ construct and user provided custom properties', () => { ipAddresses: ec2.IpAddresses.cidr('172.168.0.0/19'), }, }); - expect(stack).toHaveResource('AWS::EC2::VPC', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::VPC', { CidrBlock: '172.168.0.0/19', EnableDnsHostnames: false, EnableDnsSupport: false, @@ -140,8 +140,9 @@ test('Test deployment w/ construct and user provided custom properties', () => { AddAwsServiceEndpoint(stack, v, defaults.ServiceEndpointTypes.SQS); // Expect 2 isolated subnets (usual error condition is 2 public/2 private) - expect(stack).toCountResources('AWS::EC2::Subnet', 2); - expect(stack).toCountResources('AWS::EC2::InternetGateway', 0); + const template = Template.fromStack(stack); + template.resourceCountIs('AWS::EC2::Subnet', 2); + template.resourceCountIs('AWS::EC2::InternetGateway', 0); }); // -------------------------------------------------------------- @@ -177,13 +178,14 @@ test('Test adding Gateway Endpoint', () => { AddAwsServiceEndpoint(stack, testVpc, ServiceEndpointTypes.SNS); // Assertion - expect(stack).toHaveResource('AWS::EC2::VPCEndpoint', { + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::EC2::VPCEndpoint', { VpcEndpointType: 'Gateway', }); - expect(stack).toHaveResource('AWS::EC2::VPCEndpoint', { + template.hasResourceProperties('AWS::EC2::VPCEndpoint', { VpcEndpointType: 'Interface', }); - expect(stack).toCountResources('AWS::EC2::VPCEndpoint', 3); + template.resourceCountIs('AWS::EC2::VPCEndpoint', 3); }); // -------------------------------------------------------------- @@ -200,7 +202,7 @@ test('Test adding Interface Endpoint', () => { AddAwsServiceEndpoint(stack, testVpc, ServiceEndpointTypes.SNS); // Assertion - expect(stack).toHaveResource('AWS::EC2::VPCEndpoint', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::VPCEndpoint', { VpcEndpointType: 'Interface', }); }); @@ -219,7 +221,7 @@ test('Test adding SAGEMAKER_RUNTIME Interface Endpoint', () => { AddAwsServiceEndpoint(stack, testVpc, ServiceEndpointTypes.SAGEMAKER_RUNTIME); // Assertion - expect(stack).toHaveResource('AWS::EC2::VPCEndpoint', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::VPCEndpoint', { VpcEndpointType: 'Interface', }); }); @@ -239,7 +241,7 @@ test('Test adding a second Endpoint of same service', () => { AddAwsServiceEndpoint(stack, testVpc, ServiceEndpointTypes.SNS); // Assertion - expect(stack).toCountResources('AWS::EC2::VPCEndpoint', 1); + Template.fromStack(stack).resourceCountIs('AWS::EC2::VPCEndpoint', 1); }); // -------------------------------------------------------------- @@ -274,7 +276,7 @@ test('Test adding Events Interface Endpoint', () => { AddAwsServiceEndpoint(stack, testVpc, ServiceEndpointTypes.EVENTS); // Assertion - expect(stack).toHaveResource('AWS::EC2::VPCEndpoint', { + Template.fromStack(stack).hasResourceProperties('AWS::EC2::VPCEndpoint', { VpcEndpointType: 'Interface', }); }); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/core/test/waf-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/waf-helper.test.ts index a54ccf4a7..a99f442fc 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/waf-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/waf-helper.test.ts @@ -14,8 +14,7 @@ import { Stack } from 'aws-cdk-lib'; import * as waf from "aws-cdk-lib/aws-wafv2"; import * as defaults from '..'; -import { SynthUtils } from '@aws-cdk/assert'; -import '@aws-cdk/assert/jest'; +import { Template } from 'aws-cdk-lib/assertions'; import { buildWebacl } from '..'; // -------------------------------------------------------------- @@ -27,7 +26,8 @@ test('Test construct with default props', () => { // Build WAF web ACL defaults.buildWebacl(stack, 'REGIONAL', {}); - expect(stack).toHaveResource("AWS::WAFv2::WebACL", { + const template = Template.fromStack(stack); + template.hasResourceProperties("AWS::WAFv2::WebACL", { Scope: "REGIONAL", VisibilityConfig: { CloudWatchMetricsEnabled: true, @@ -164,8 +164,8 @@ test('Test construct with default props', () => { ] }); - expect(SynthUtils.toCloudFormation(stack)).toCountResources('AWS::WAFv2::WebACL', 1); - expect(SynthUtils.toCloudFormation(stack)).toCountResources('AWS::WAFv2::WebACLAssociation', 0); + template.resourceCountIs('AWS::WAFv2::WebACL', 1); + template.resourceCountIs('AWS::WAFv2::WebACLAssociation', 0); }); // -------------------------------------------------------------- @@ -196,7 +196,7 @@ test('Test deployment w/ user provided custom properties', () => { webaclProps: props }); - expect(stack).toHaveResource("AWS::WAFv2::WebACL", { + Template.fromStack(stack).hasResourceProperties("AWS::WAFv2::WebACL", { Scope: "CLOUDFRONT", VisibilityConfig: { CloudWatchMetricsEnabled: false, From 751ae27f6c74f08dad11dab4a47cc2db92d9b79a Mon Sep 17 00:00:00 2001 From: George Bearden Date: Wed, 22 Mar 2023 13:11:17 -0400 Subject: [PATCH 2/4] Update the cloudfront-to-s3 construct to correctly set the logging bucket property. (#930) --- .../aws-cloudfront-s3/lib/index.ts | 1 + .../test/test.cloudfront-s3.test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/lib/index.ts index 2758e3987..cbbfc3b54 100644 --- a/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/lib/index.ts @@ -117,6 +117,7 @@ export class CloudFrontToS3 extends Construct { logS3AccessLogs: props.logS3AccessLogs }); this.s3Bucket = buildS3BucketResponse.bucket; + this.s3LoggingBucket = buildS3BucketResponse.loggingBucket; bucket = this.s3Bucket; } else { bucket = props.existingBucketObj; diff --git a/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/test.cloudfront-s3.test.ts b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/test.cloudfront-s3.test.ts index 2f190e204..3e02ae0da 100644 --- a/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/test.cloudfront-s3.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/test.cloudfront-s3.test.ts @@ -28,6 +28,18 @@ function deploy(stack: cdk.Stack, props?: CloudFrontToS3Props) { }); } +test('construct defaults set properties correctly', () => { + const stack = new cdk.Stack(); + const construct = new CloudFrontToS3(stack, 'test-cloudfront-s3', {}); + + expect(construct.cloudFrontWebDistribution).toBeDefined(); + expect(construct.cloudFrontFunction).toBeDefined(); + expect(construct.cloudFrontLoggingBucket).toBeDefined(); + expect(construct.s3Bucket).toBeDefined(); + expect(construct.s3LoggingBucket).toBeDefined(); + expect(construct.s3BucketInterface).toBeDefined(); +}); + test('check s3Bucket default encryption', () => { const stack = new cdk.Stack(); deploy(stack); From b2f8253007b1923909d179bb0352ccbbcba779ee Mon Sep 17 00:00:00 2001 From: AWS Solutions Constructs Automation Date: Thu, 23 Mar 2023 16:20:05 +0000 Subject: [PATCH 3/4] chore(release): 2.35.0 --- CHANGELOG.md | 2 ++ source/lerna.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a433614f..b07c70933 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [2.35.0](https://github.com/awslabs/aws-solutions-constructs/compare/v2.34.0...v2.35.0) (2023-03-23) + ## [2.34.0](https://github.com/awslabs/aws-solutions-constructs/compare/v2.33.0...v2.34.0) (2023-03-18) Built on CDK v2.68.0 diff --git a/source/lerna.json b/source/lerna.json index b30d182a0..74ef14d6b 100644 --- a/source/lerna.json +++ b/source/lerna.json @@ -6,5 +6,5 @@ "./patterns/@aws-solutions-constructs/*" ], "rejectCycles": "true", - "version": "2.34.0" + "version": "2.35.0" } From 29b3cd96b289b43964e567bf99d6d327c5edf5ce Mon Sep 17 00:00:00 2001 From: biffgaut Date: Thu, 23 Mar 2023 12:24:41 -0400 Subject: [PATCH 4/4] chore(changelog): Updated CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b07c70933..2423d6a7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. See [standa ## [2.35.0](https://github.com/awslabs/aws-solutions-constructs/compare/v2.34.0...v2.35.0) (2023-03-23) +Built on CDK v2.68.0 + +### Bug Fixes + +* **aws-cloudfront-s3** Set s3LoggingBucket property ([#930](https://github.com/awslabs/aws-solutions-constructs/pull/930)) + ## [2.34.0](https://github.com/awslabs/aws-solutions-constructs/compare/v2.33.0...v2.34.0) (2023-03-18) Built on CDK v2.68.0