diff --git a/packages/@aws-cdk/aws-dynamodb/package.json b/packages/@aws-cdk/aws-dynamodb/package.json index a4953cd3fb355..146ec9cc2d741 100644 --- a/packages/@aws-cdk/aws-dynamodb/package.json +++ b/packages/@aws-cdk/aws-dynamodb/package.json @@ -79,7 +79,7 @@ }, "license": "Apache-2.0", "devDependencies": { - "@aws-cdk/assert-internal": "0.0.0", + "@aws-cdk/assertions": "0.0.0", "@aws-cdk/cdk-build-tools": "0.0.0", "@aws-cdk/cdk-integ-tools": "0.0.0", "@aws-cdk/cfn2ts": "0.0.0", diff --git a/packages/@aws-cdk/aws-dynamodb/test/dynamodb.test.ts b/packages/@aws-cdk/aws-dynamodb/test/dynamodb.test.ts index 3c125c1bc0061..448aa7119eee6 100644 --- a/packages/@aws-cdk/aws-dynamodb/test/dynamodb.test.ts +++ b/packages/@aws-cdk/aws-dynamodb/test/dynamodb.test.ts @@ -1,5 +1,4 @@ -import { arrayWith, ABSENT, ResourcePart, SynthUtils } from '@aws-cdk/assert-internal'; -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as appscaling from '@aws-cdk/aws-applicationautoscaling'; import * as iam from '@aws-cdk/aws-iam'; import * as kinesis from '@aws-cdk/aws-kinesis'; @@ -84,20 +83,20 @@ describe('default properties', () => { test('hash key only', () => { new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', { + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [{ AttributeName: 'hashKey', AttributeType: 'S' }], KeySchema: [{ AttributeName: 'hashKey', KeyType: 'HASH' }], ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', { DeletionPolicy: CfnDeletionPolicy.RETAIN }, ResourcePart.CompleteDefinition); + Template.fromStack(stack).hasResource('AWS::DynamoDB::Table', { DeletionPolicy: CfnDeletionPolicy.RETAIN }); }); test('removalPolicy is DESTROY', () => { new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, removalPolicy: RemovalPolicy.DESTROY }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', { DeletionPolicy: CfnDeletionPolicy.DELETE }, ResourcePart.CompleteDefinition); + Template.fromStack(stack).hasResource('AWS::DynamoDB::Table', { DeletionPolicy: CfnDeletionPolicy.DELETE }); }); @@ -107,7 +106,7 @@ describe('default properties', () => { sortKey: TABLE_SORT_KEY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', { + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, { AttributeName: 'sortKey', AttributeType: 'N' }, @@ -126,7 +125,7 @@ describe('default properties', () => { sortKey: TABLE_SORT_KEY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -146,7 +145,7 @@ describe('default properties', () => { sortKey: TABLE_SORT_KEY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -167,7 +166,7 @@ describe('default properties', () => { sortKey: TABLE_SORT_KEY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -188,7 +187,7 @@ describe('default properties', () => { sortKey: TABLE_SORT_KEY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -209,7 +208,7 @@ describe('default properties', () => { sortKey: TABLE_SORT_KEY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -234,7 +233,7 @@ describe('default properties', () => { sortKey: TABLE_SORT_KEY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -261,7 +260,7 @@ describe('default properties', () => { sortKey: TABLE_SORT_KEY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { KeySchema: [ { AttributeName: 'hashKey', KeyType: 'HASH' }, @@ -288,7 +287,7 @@ describe('default properties', () => { sortKey: TABLE_SORT_KEY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { KeySchema: [ { AttributeName: 'hashKey', KeyType: 'HASH' }, @@ -313,8 +312,8 @@ describe('default properties', () => { // since the resource has not been used in a cross-environment manner, // so the name should not be filled - expect(stack).toHaveResourceLike('AWS::DynamoDB::Table', { - TableName: ABSENT, + Template.fromStack(stack).hasResource('AWS::DynamoDB::Table', { + TableName: Match.absent(), }); }); }); @@ -338,7 +337,7 @@ testDeprecated('when specifying every property', () => { }); Tags.of(table).add('Environment', 'Production'); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -377,7 +376,7 @@ test('when specifying sse with customer managed CMK', () => { }); Tags.of(table).add('Environment', 'Production'); - expect(stack).toHaveResource('AWS::DynamoDB::Table', { + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { 'SSESpecification': { 'KMSMasterKeyId': { 'Fn::GetAtt': [ @@ -403,7 +402,7 @@ test('when specifying only encryptionKey', () => { }); Tags.of(table).add('Environment', 'Production'); - expect(stack).toHaveResource('AWS::DynamoDB::Table', { + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { 'SSESpecification': { 'KMSMasterKeyId': { 'Fn::GetAtt': [ @@ -430,7 +429,7 @@ test('when specifying sse with customer managed CMK with encryptionKey provided }); Tags.of(table).add('Environment', 'Production'); - expect(stack).toHaveResource('AWS::DynamoDB::Table', { + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { 'SSESpecification': { 'KMSMasterKeyId': { 'Fn::GetAtt': [ @@ -514,15 +513,15 @@ testLegacyBehavior('if an encryption key is included, encrypt/decrypt permission }); const user = new iam.User(stack, 'MyUser'); table.grantReadWriteData(user); - expect(stack).toMatchTemplate({ - 'Resources': { - 'TableAKey07CC09EC': { - 'Type': 'AWS::KMS::Key', - 'Properties': { - 'KeyPolicy': { - 'Statement': [ + Template.fromStack(stack).templateMatches({ + Resources: { + TableAKey07CC09EC: { + Type: 'AWS::KMS::Key', + Properties: { + KeyPolicy: { + Statement: [ { - 'Action': [ + Action: [ 'kms:Create*', 'kms:Describe*', 'kms:Enable*', @@ -539,99 +538,99 @@ testLegacyBehavior('if an encryption key is included, encrypt/decrypt permission 'kms:TagResource', 'kms:UntagResource', ], - 'Effect': 'Allow', - 'Principal': { - 'AWS': { + Effect: 'Allow', + Principal: { + AWS: { 'Fn::Join': [ '', [ 'arn:', { - 'Ref': 'AWS::Partition', + Ref: 'AWS::Partition', }, ':iam::', { - 'Ref': 'AWS::AccountId', + Ref: 'AWS::AccountId', }, ':root', ], ], }, }, - 'Resource': '*', + Resource: '*', }, { - 'Action': [ + Action: [ 'kms:Decrypt', 'kms:DescribeKey', 'kms:Encrypt', 'kms:ReEncrypt*', 'kms:GenerateDataKey*', ], - 'Effect': 'Allow', - 'Principal': { - 'AWS': { + Effect: 'Allow', + Principal: { + AWS: { 'Fn::GetAtt': [ 'MyUserDC45028B', 'Arn', ], }, }, - 'Resource': '*', + Resource: '*', }, ], - 'Version': '2012-10-17', + Version: '2012-10-17', }, - 'Description': 'Customer-managed key auto-created for encrypting DynamoDB table at Default/Table A', - 'EnableKeyRotation': true, + Description: 'Customer-managed key auto-created for encrypting DynamoDB table at Default/Table A', + EnableKeyRotation: true, }, - 'UpdateReplacePolicy': 'Retain', - 'DeletionPolicy': 'Retain', + UpdateReplacePolicy: 'Retain', + DeletionPolicy: 'Retain', }, - 'TableA3D7B5AFA': { - 'Type': 'AWS::DynamoDB::Table', - 'Properties': { - 'KeySchema': [ + TableA3D7B5AFA: { + Type: 'AWS::DynamoDB::Table', + Properties: { + KeySchema: [ { - 'AttributeName': 'hashKey', - 'KeyType': 'HASH', + AttributeName: 'hashKey', + KeyType: 'HASH', }, ], - 'AttributeDefinitions': [ + AttributeDefinitions: [ { - 'AttributeName': 'hashKey', - 'AttributeType': 'S', + AttributeName: 'hashKey', + AttributeType: 'S', }, ], - 'ProvisionedThroughput': { - 'ReadCapacityUnits': 5, - 'WriteCapacityUnits': 5, + ProvisionedThroughput: { + ReadCapacityUnits: 5, + WriteCapacityUnits: 5, }, - 'SSESpecification': { - 'KMSMasterKeyId': { + SSESpecification: { + KMSMasterKeyId: { 'Fn::GetAtt': [ 'TableAKey07CC09EC', 'Arn', ], }, - 'SSEEnabled': true, - 'SSEType': 'KMS', + SSEEnabled: true, + SSEType: 'KMS', }, - 'TableName': 'MyTable', + TableName: 'MyTable', }, - 'UpdateReplacePolicy': 'Retain', - 'DeletionPolicy': 'Retain', + UpdateReplacePolicy: 'Retain', + DeletionPolicy: 'Retain', }, - 'MyUserDC45028B': { - 'Type': 'AWS::IAM::User', + MyUserDC45028B: { + Type: 'AWS::IAM::User', }, - 'MyUserDefaultPolicy7B897426': { - 'Type': 'AWS::IAM::Policy', - 'Properties': { - 'PolicyDocument': { - 'Statement': [ + MyUserDefaultPolicy7B897426: { + Type: 'AWS::IAM::Policy', + Properties: { + PolicyDocument: { + Statement: [ { - 'Action': [ + Action: [ 'dynamodb:BatchGetItem', 'dynamodb:GetRecords', 'dynamodb:GetShardIterator', @@ -644,8 +643,8 @@ testLegacyBehavior('if an encryption key is included, encrypt/decrypt permission 'dynamodb:UpdateItem', 'dynamodb:DeleteItem', ], - 'Effect': 'Allow', - 'Resource': [ + Effect: 'Allow', + Resource: [ { 'Fn::GetAtt': [ 'TableA3D7B5AFA', @@ -653,20 +652,20 @@ testLegacyBehavior('if an encryption key is included, encrypt/decrypt permission ], }, { - 'Ref': 'AWS::NoValue', + Ref: 'AWS::NoValue', }, ], }, { - 'Action': [ + Action: [ 'kms:Decrypt', 'kms:DescribeKey', 'kms:Encrypt', 'kms:ReEncrypt*', 'kms:GenerateDataKey*', ], - 'Effect': 'Allow', - 'Resource': { + Effect: 'Allow', + Resource: { 'Fn::GetAtt': [ 'TableAKey07CC09EC', 'Arn', @@ -674,12 +673,12 @@ testLegacyBehavior('if an encryption key is included, encrypt/decrypt permission }, }, ], - 'Version': '2012-10-17', + Version: '2012-10-17', }, - 'PolicyName': 'MyUserDefaultPolicy7B897426', - 'Users': [ + PolicyName: 'MyUserDefaultPolicy7B897426', + Users: [ { - 'Ref': 'MyUserDC45028B', + Ref: 'MyUserDC45028B', }, ], }, @@ -698,24 +697,24 @@ test('if an encryption key is included, encrypt/decrypt permissions are added to const user = new iam.User(stack, 'MyUser'); table.grantReadWriteData(user); - expect(stack).toHaveResourceLike('AWS::IAM::Policy', { - 'PolicyDocument': { - 'Statement': arrayWith({ - 'Action': [ + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { + PolicyDocument: { + Statement: Match.arrayWith([{ + Action: [ 'kms:Decrypt', 'kms:DescribeKey', 'kms:Encrypt', 'kms:ReEncrypt*', 'kms:GenerateDataKey*', ], - 'Effect': 'Allow', - 'Resource': { + Effect: 'Allow', + Resource: { 'Fn::GetAtt': [ 'TableAKey07CC09EC', 'Arn', ], }, - }), + }]), }, }); }); @@ -728,7 +727,7 @@ test('when specifying PAY_PER_REQUEST billing mode', () => { partitionKey: TABLE_PARTITION_KEY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { KeySchema: [ { AttributeName: 'hashKey', KeyType: 'HASH' }, @@ -891,7 +890,7 @@ test('when adding a global secondary index with hash key only', () => { writeCapacity: 1337, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -933,7 +932,7 @@ test('when adding a global secondary index with hash + range key', () => { writeCapacity: 1337, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -975,7 +974,7 @@ test('when adding a global secondary index with projection type KEYS_ONLY', () = projectionType: ProjectionType.KEYS_ONLY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -1017,7 +1016,7 @@ test('when adding a global secondary index with projection type INCLUDE', () => writeCapacity: 1337, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -1056,7 +1055,7 @@ test('when adding a global secondary index on a table with PAY_PER_REQUEST billi partitionKey: GSI_PARTITION_KEY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -1171,7 +1170,7 @@ test('when adding multiple global secondary indexes', () => { table.addGlobalSecondaryIndex(gsiGenerator.next().value); } - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -1242,7 +1241,7 @@ test('when adding a global secondary index without specifying read and write cap partitionKey: GSI_PARTITION_KEY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -1277,7 +1276,7 @@ test('when adding a local secondary index with hash + range key', () => { sortKey: LSI_SORT_KEY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -1312,7 +1311,7 @@ test('when adding a local secondary index with projection type KEYS_ONLY', () => projectionType: ProjectionType.KEYS_ONLY, }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -1349,7 +1348,7 @@ test('when adding a local secondary index with projection type INCLUDE', () => { nonKeyAttributes: [lsiNonKeyAttributeGenerator.next().value, lsiNonKeyAttributeGenerator.next().value], }); - expect(stack).toHaveResource('AWS::DynamoDB::Table', + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', { AttributeDefinitions: [ { AttributeName: 'hashKey', AttributeType: 'S' }, @@ -1426,13 +1425,13 @@ test('can enable Read AutoScaling', () => { table.autoScaleReadCapacity({ minCapacity: 50, maxCapacity: 500 }).scaleOnUtilization({ targetUtilizationPercent: 75 }); // THEN - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', { MaxCapacity: 500, MinCapacity: 50, ScalableDimension: 'dynamodb:table:ReadCapacityUnits', ServiceNamespace: 'dynamodb', }); - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', { PolicyType: 'TargetTrackingScaling', TargetTrackingScalingPolicyConfiguration: { PredefinedMetricSpecification: { PredefinedMetricType: 'DynamoDBReadCapacityUtilization' }, @@ -1450,13 +1449,13 @@ test('can enable Write AutoScaling', () => { table.autoScaleWriteCapacity({ minCapacity: 50, maxCapacity: 500 }).scaleOnUtilization({ targetUtilizationPercent: 75 }); // THEN - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', { MaxCapacity: 500, MinCapacity: 50, ScalableDimension: 'dynamodb:table:WriteCapacityUnits', ServiceNamespace: 'dynamodb', }); - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', { PolicyType: 'TargetTrackingScaling', TargetTrackingScalingPolicyConfiguration: { PredefinedMetricSpecification: { PredefinedMetricType: 'DynamoDBWriteCapacityUtilization' }, @@ -1537,7 +1536,7 @@ test('can autoscale on a schedule', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', { + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', { ScheduledActions: [ { ScalableTargetAction: { 'MaxCapacity': 10 }, @@ -1806,7 +1805,7 @@ describe('grants', () => { table.grant(user, 'dynamodb:action1', 'dynamodb:action2'); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -1874,7 +1873,7 @@ describe('grants', () => { Table.grantListStreams(user); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -1920,7 +1919,7 @@ describe('grants', () => { table.grantTableListStreams(user); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -1966,7 +1965,7 @@ describe('grants', () => { table.grantStreamRead(user); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -2007,7 +2006,7 @@ describe('grants', () => { table.grantReadData(user); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -2066,7 +2065,7 @@ describe('grants', () => { table.grant(user, 'dynamodb:*'); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2159,7 +2158,7 @@ describe('import', () => { table.grantReadData(role); // it is possible to obtain a permission statement for a ref - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -2201,7 +2200,7 @@ describe('import', () => { table.grantReadWriteData(role); // it is possible to obtain a permission statement for a ref - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -2284,7 +2283,7 @@ describe('import', () => { expect(table.grantTableListStreams(role)).toBeDefined(); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2312,7 +2311,7 @@ describe('import', () => { expect(table.grantStreamRead(role)).toBeDefined(); - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2347,7 +2346,7 @@ describe('import', () => { table.grantReadData(role); - expect(stack).toHaveResourceLike('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2410,7 +2409,7 @@ describe('global', () => { }); // THEN - expect(stack).toHaveResource('Custom::DynamoDBReplica', { + Template.fromStack(stack).hasResource('Custom::DynamoDBReplica', { Properties: { TableName: { Ref: 'TableCD117FA1', @@ -2418,9 +2417,9 @@ describe('global', () => { Region: 'eu-west-2', }, Condition: 'TableStackRegionNotEqualseuwest2A03859E7', - }, ResourcePart.CompleteDefinition); + }); - expect(stack).toHaveResource('Custom::DynamoDBReplica', { + Template.fromStack(stack).hasResource('Custom::DynamoDBReplica', { Properties: { TableName: { Ref: 'TableCD117FA1', @@ -2428,19 +2427,18 @@ describe('global', () => { Region: 'eu-central-1', }, Condition: 'TableStackRegionNotEqualseucentral199D46FC0', - }, ResourcePart.CompleteDefinition); + }); - expect(SynthUtils.toCloudFormation(stack).Conditions).toEqual({ - TableStackRegionNotEqualseuwest2A03859E7: { - 'Fn::Not': [ - { 'Fn::Equals': ['eu-west-2', { Ref: 'AWS::Region' }] }, - ], - }, - TableStackRegionNotEqualseucentral199D46FC0: { - 'Fn::Not': [ - { 'Fn::Equals': ['eu-central-1', { Ref: 'AWS::Region' }] }, - ], - }, + Template.fromStack(stack).hasCondition('TableStackRegionNotEqualseuwest2A03859E7', { + 'Fn::Not': [ + { 'Fn::Equals': ['eu-west-2', { Ref: 'AWS::Region' }] }, + ], + }); + + Template.fromStack(stack).hasCondition('TableStackRegionNotEqualseucentral199D46FC0', { + 'Fn::Not': [ + { 'Fn::Equals': ['eu-central-1', { Ref: 'AWS::Region' }] }, + ], }); }); @@ -2462,7 +2460,7 @@ describe('global', () => { }); // THEN - expect(stack).toHaveResource('Custom::DynamoDBReplica', { + Template.fromStack(stack).hasResource('Custom::DynamoDBReplica', { Properties: { TableName: { Ref: 'TableCD117FA1', @@ -2471,9 +2469,9 @@ describe('global', () => { SkipReplicationCompletedWait: 'true', }, Condition: 'TableStackRegionNotEqualseuwest2A03859E7', - }, ResourcePart.CompleteDefinition); + }); - expect(stack).toHaveResource('Custom::DynamoDBReplica', { + Template.fromStack(stack).hasResource('Custom::DynamoDBReplica', { Properties: { TableName: { Ref: 'TableCD117FA1', @@ -2482,19 +2480,18 @@ describe('global', () => { SkipReplicationCompletedWait: 'true', }, Condition: 'TableStackRegionNotEqualseucentral199D46FC0', - }, ResourcePart.CompleteDefinition); + }); - expect(SynthUtils.toCloudFormation(stack).Conditions).toEqual({ - TableStackRegionNotEqualseuwest2A03859E7: { - 'Fn::Not': [ - { 'Fn::Equals': ['eu-west-2', { Ref: 'AWS::Region' }] }, - ], - }, - TableStackRegionNotEqualseucentral199D46FC0: { - 'Fn::Not': [ - { 'Fn::Equals': ['eu-central-1', { Ref: 'AWS::Region' }] }, - ], - }, + Template.fromStack(stack).hasCondition('TableStackRegionNotEqualseuwest2A03859E7', { + 'Fn::Not': [ + { 'Fn::Equals': ['eu-west-2', { Ref: 'AWS::Region' }] }, + ], + }); + + Template.fromStack(stack).hasCondition('TableStackRegionNotEqualseucentral199D46FC0', { + 'Fn::Not': [ + { 'Fn::Equals': ['eu-central-1', { Ref: 'AWS::Region' }] }, + ], }); }); @@ -2523,7 +2520,7 @@ describe('global', () => { table.grantReadData(user); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2677,7 +2674,7 @@ describe('global', () => { table.grantReadData(user); // THEN - expect(stack2).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack2).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2822,7 +2819,7 @@ describe('global', () => { table.grantTableListStreams(user); // THEN - expect(stack2).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack2).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2855,7 +2852,7 @@ describe('global', () => { // THEN expect(() => { - SynthUtils.synthesize(stack); + Template.fromStack(stack); }).toThrow(/A global Table that uses PROVISIONED as the billing mode needs auto-scaled write capacity/); }); @@ -2882,7 +2879,7 @@ describe('global', () => { // THEN expect(() => { - SynthUtils.synthesize(stack); + Template.fromStack(stack); }).toThrow(/A global Table that uses PROVISIONED as the billing mode needs auto-scaled write capacity with a policy/); }); @@ -2907,8 +2904,8 @@ describe('global', () => { maxCapacity: 10, }).scaleOnUtilization({ targetUtilizationPercent: 75 }); - expect(stack).toHaveResourceLike('AWS::DynamoDB::Table', { - BillingMode: ABSENT, // PROVISIONED is the default + Template.fromStack(stack).hasResource('AWS::DynamoDB::Table', { + BillingMode: Match.absent(), // PROVISIONED is the default }); }); @@ -2971,7 +2968,8 @@ describe('global', () => { }); // THEN - expect(SynthUtils.toCloudFormation(stack).Conditions).toBeUndefined(); + const conditions = Template.fromStack(stack).findConditions('*'); + expect(Object.keys(conditions).length).toEqual(0); }); test('can configure timeout', () => { @@ -3014,7 +3012,7 @@ test('L1 inside L2 expects removalpolicy to have been set', () => { new FakeTableL2(stack, 'Table'); expect(() => { - SynthUtils.toCloudFormation(stack); + Template.fromStack(stack); }).toThrow(/is a stateful resource type/); }); @@ -3029,7 +3027,7 @@ function testGrant(expectedActions: string[], invocation: (user: iam.IPrincipal, // THEN const action = expectedActions.length > 1 ? expectedActions.map(a => `dynamodb:${a}`) : `dynamodb:${expectedActions[0]}`; - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ {