diff --git a/packages/@aws-cdk/aws-logs/package.json b/packages/@aws-cdk/aws-logs/package.json index 1bee0d473345d..a2c39272e68d1 100644 --- a/packages/@aws-cdk/aws-logs/package.json +++ b/packages/@aws-cdk/aws-logs/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-logs/test/destination.test.ts b/packages/@aws-cdk/aws-logs/test/destination.test.ts index 05f482441d265..096addb02a885 100644 --- a/packages/@aws-cdk/aws-logs/test/destination.test.ts +++ b/packages/@aws-cdk/aws-logs/test/destination.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template, Match } from '@aws-cdk/assertions'; import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; import { CrossAccountDestination } from '../lib'; @@ -19,13 +19,11 @@ describe('destination', () => { }); // THEN - expect(stack).toHaveResource('AWS::Logs::Destination', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::Destination', { DestinationName: 'MyDestination', RoleArn: { 'Fn::GetAtt': ['Role1ABCC5F0', 'Arn'] }, TargetArn: 'arn:bogus', }); - - }); test('add policy to destination', () => { @@ -47,12 +45,24 @@ describe('destination', () => { })); // THEN - expect(stack).toHaveResource('AWS::Logs::Destination', (props: any) => { - const pol = JSON.parse(props.DestinationPolicy); - - return pol.Statement[0].Action === 'logs:TalkToMe'; + Template.fromStack(stack).hasResourceProperties('AWS::Logs::Destination', { + DestinationName: 'MyDestination', + DestinationPolicy: Match.serializedJson({ + Statement: [ + { + Action: 'logs:TalkToMe', + Effect: 'Allow', + }, + ], + Version: '2012-10-17', + }), + RoleArn: { + 'Fn::GetAtt': [ + 'Role1ABCC5F0', + 'Arn', + ], + }, + TargetArn: 'arn:bogus', }); - - }); }); diff --git a/packages/@aws-cdk/aws-logs/test/log-retention.test.ts b/packages/@aws-cdk/aws-logs/test/log-retention.test.ts index 7fd7d6b8532bf..5902f7de8dd86 100644 --- a/packages/@aws-cdk/aws-logs/test/log-retention.test.ts +++ b/packages/@aws-cdk/aws-logs/test/log-retention.test.ts @@ -1,6 +1,5 @@ import * as path from 'path'; -import '@aws-cdk/assert-internal/jest'; -import { ABSENT, ResourcePart } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; import * as cxapi from '@aws-cdk/cx-api'; @@ -20,7 +19,7 @@ describe('log retention', () => { }); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -42,12 +41,12 @@ describe('log retention', () => { ], }); - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Handler: 'index.handler', Runtime: 'nodejs14.x', }); - expect(stack).toHaveResource('Custom::LogRetention', { + Template.fromStack(stack).hasResourceProperties('Custom::LogRetention', { 'ServiceToken': { 'Fn::GetAtt': [ 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aFD4BFC8A', @@ -57,8 +56,6 @@ describe('log retention', () => { 'LogGroupName': 'group', 'RetentionInDays': 30, }); - - }); test('with imported role', () => { @@ -74,7 +71,7 @@ describe('log retention', () => { }); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -94,9 +91,7 @@ describe('log retention', () => { ], }); - expect(stack).toCountResources('AWS::IAM::Role', 0); - - + Template.fromStack(stack).resourceCountIs('AWS::IAM::Role', 0); }); test('with RetentionPeriod set to Infinity', () => { @@ -107,11 +102,9 @@ describe('log retention', () => { retention: RetentionDays.INFINITE, }); - expect(stack).toHaveResource('Custom::LogRetention', { - RetentionInDays: ABSENT, + Template.fromStack(stack).hasResourceProperties('Custom::LogRetention', { + RetentionInDays: Match.absent(), }); - - }); test('with LogGroupRegion specified', () => { @@ -122,11 +115,9 @@ describe('log retention', () => { retention: RetentionDays.INFINITE, }); - expect(stack).toHaveResource('Custom::LogRetention', { + Template.fromStack(stack).hasResourceProperties('Custom::LogRetention', { LogGroupRegion: 'us-east-1', }); - - }); test('log group ARN is well formed and conforms', () => { @@ -140,7 +131,6 @@ describe('log retention', () => { expect(logGroupArn.indexOf('logs')).toBeGreaterThan(-1); expect(logGroupArn.indexOf('log-group')).toBeGreaterThan(-1); expect(logGroupArn.endsWith(':*')).toEqual(true); - }); test('log group ARN is well formed and conforms when region is specified', () => { @@ -156,7 +146,6 @@ describe('log retention', () => { expect(logGroupArn.indexOf('logs')).toBeGreaterThan(-1); expect(logGroupArn.indexOf('log-group')).toBeGreaterThan(-1); expect(logGroupArn.endsWith(':*')).toEqual(true); - }); test('retention Lambda CfnResource receives propagated tags', () => { @@ -167,7 +156,7 @@ describe('log retention', () => { retention: RetentionDays.ONE_MONTH, }); - expect(stack).toHaveResourceLike('AWS::Lambda::Function', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { Tags: [ { Key: 'test-key', @@ -175,7 +164,6 @@ describe('log retention', () => { }, ], }); - }); test('asset metadata added to log retention construct lambda function', () => { @@ -193,13 +181,12 @@ describe('log retention', () => { }); // Then - expect(stack).toHaveResource('AWS::Lambda::Function', { + Template.fromStack(stack).hasResource('AWS::Lambda::Function', { Metadata: { 'aws:asset:path': assetLocation, 'aws:asset:is-bundled': false, 'aws:asset:property': 'Code', }, - }, ResourcePart.CompleteDefinition); - + }); }); }); diff --git a/packages/@aws-cdk/aws-logs/test/loggroup.test.ts b/packages/@aws-cdk/aws-logs/test/loggroup.test.ts index 7928de182d7ff..4fefc67272d5f 100644 --- a/packages/@aws-cdk/aws-logs/test/loggroup.test.ts +++ b/packages/@aws-cdk/aws-logs/test/loggroup.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as iam from '@aws-cdk/aws-iam'; import * as kms from '@aws-cdk/aws-kms'; import { CfnParameter, RemovalPolicy, Stack } from '@aws-cdk/core'; @@ -16,12 +16,9 @@ describe('log group', () => { }); // THEN - expect(stack).toHaveResource('AWS::Logs::LogGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', { KmsKeyId: { 'Fn::GetAtt': ['Key961B73FD', 'Arn'] }, - }); - - }); test('fixed retention', () => { @@ -34,11 +31,9 @@ describe('log group', () => { }); // THEN - expect(stack).toHaveResource('AWS::Logs::LogGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', { RetentionInDays: 7, }); - - }); test('default retention', () => { @@ -49,11 +44,9 @@ describe('log group', () => { new LogGroup(stack, 'LogGroup'); // THEN - expect(stack).toHaveResource('AWS::Logs::LogGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', { RetentionInDays: 731, }); - - }); test('infinite retention/dont delete log group by default', () => { @@ -66,7 +59,7 @@ describe('log group', () => { }); // THEN - expect(stack).toMatchTemplate({ + Template.fromStack(stack).templateMatches({ Resources: { LogGroupF5B46931: { Type: 'AWS::Logs::LogGroup', @@ -75,8 +68,6 @@ describe('log group', () => { }, }, }); - - }); test('infinite retention via legacy method', () => { @@ -92,7 +83,7 @@ describe('log group', () => { }); // THEN - expect(stack).toMatchTemplate({ + Template.fromStack(stack).templateMatches({ Resources: { LogGroupF5B46931: { Type: 'AWS::Logs::LogGroup', @@ -101,8 +92,6 @@ describe('log group', () => { }, }, }); - - }); test('unresolved retention', () => { @@ -116,13 +105,11 @@ describe('log group', () => { }); // THEN - expect(stack).toHaveResource('AWS::Logs::LogGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', { RetentionInDays: { Ref: 'RetentionInDays', }, }); - - }); test('will delete log group if asked to', () => { @@ -136,7 +123,7 @@ describe('log group', () => { }); // THEN - expect(stack).toMatchTemplate({ + Template.fromStack(stack).templateMatches({ Resources: { LogGroupF5B46931: { Type: 'AWS::Logs::LogGroup', @@ -145,8 +132,6 @@ describe('log group', () => { }, }, }); - - }); test('import from ARN, same region', () => { @@ -160,10 +145,9 @@ describe('log group', () => { // THEN expect(imported.logGroupName).toEqual('my-log-group'); expect(imported.logGroupArn).toEqual('arn:aws:logs:us-east-1:123456789012:log-group:my-log-group:*'); - expect(stack2).toHaveResource('AWS::Logs::LogStream', { + Template.fromStack(stack2).hasResourceProperties('AWS::Logs::LogStream', { LogGroupName: 'my-log-group', }); - }); test('import from ARN, different region', () => { @@ -182,10 +166,10 @@ describe('log group', () => { expect(imported.env.region).not.toEqual(stack.region); expect(imported.env.region).toEqual(importRegion); - expect(stack).toHaveResource('AWS::Logs::LogStream', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogStream', { LogGroupName: 'my-log-group', }); - expect(stack).toCountResources('AWS::Logs::LogGroup', 0); + Template.fromStack(stack).resourceCountIs('AWS::Logs::LogGroup', 0); }); test('import from name', () => { @@ -200,10 +184,9 @@ describe('log group', () => { expect(imported.logGroupName).toEqual('my-log-group'); expect(imported.logGroupArn).toMatch(/^arn:.+:logs:.+:.+:log-group:my-log-group:\*$/); - expect(stack).toHaveResource('AWS::Logs::LogStream', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogStream', { LogGroupName: 'my-log-group', }); - }); describe('loggroups imported by name have stream wildcard appended to grant ARN', () => void dataDrivenTests([ @@ -221,7 +204,7 @@ describe('log group', () => { imported.grantWrite(user); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Version: '2012-10-17', Statement: [ @@ -243,9 +226,8 @@ describe('log group', () => { ], }, }); - expect(imported.logGroupName).toEqual('my-log-group'); - + expect(imported.logGroupName).toEqual('my-log-group'); })); describe('loggroups imported by ARN have stream wildcard appended to grant ARN', () => void dataDrivenTests([ @@ -263,7 +245,7 @@ describe('log group', () => { imported.grantWrite(user); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Version: '2012-10-17', Statement: [ @@ -275,9 +257,8 @@ describe('log group', () => { ], }, }); - expect(imported.logGroupName).toEqual('my-log-group'); - + expect(imported.logGroupName).toEqual('my-log-group'); })); test('extractMetric', () => { @@ -289,7 +270,7 @@ describe('log group', () => { const metric = lg.extractMetric('$.myField', 'MyService', 'Field'); // THEN - expect(stack).toHaveResource('AWS::Logs::MetricFilter', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::MetricFilter', { FilterPattern: '{ $.myField = "*" }', LogGroupName: { Ref: 'LogGroupF5B46931' }, MetricTransformations: [ @@ -300,10 +281,9 @@ describe('log group', () => { }, ], }); + expect(metric.namespace).toEqual('MyService'); expect(metric.metricName).toEqual('Field'); - - }); test('extractMetric allows passing in namespaces with "/"', () => { @@ -315,7 +295,7 @@ describe('log group', () => { const metric = lg.extractMetric('$.myField', 'MyNamespace/MyService', 'Field'); // THEN - expect(stack).toHaveResource('AWS::Logs::MetricFilter', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::MetricFilter', { FilterPattern: '{ $.myField = "*" }', MetricTransformations: [ { @@ -325,10 +305,9 @@ describe('log group', () => { }, ], }); + expect(metric.namespace).toEqual('MyNamespace/MyService'); expect(metric.metricName).toEqual('Field'); - - }); test('grant', () => { @@ -341,7 +320,7 @@ describe('log group', () => { lg.grantWrite(user); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -353,8 +332,6 @@ describe('log group', () => { Version: '2012-10-17', }, }); - - }); test('grant to service principal', () => { @@ -367,7 +344,7 @@ describe('log group', () => { lg.grantWrite(sp); // THEN - expect(stack).toHaveResource('AWS::Logs::ResourcePolicy', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::ResourcePolicy', { PolicyDocument: { 'Fn::Join': [ '', @@ -385,10 +362,8 @@ describe('log group', () => { }, PolicyName: 'LogGroupPolicy643B329C', }); - }); - test('can add a policy to the log group', () => { // GIVEN const stack = new Stack(); @@ -402,7 +377,7 @@ describe('log group', () => { })); // THEN - expect(stack).toHaveResource('AWS::Logs::ResourcePolicy', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::ResourcePolicy', { PolicyDocument: '{"Statement":[{"Action":"logs:PutLogEvents","Effect":"Allow","Principal":{"AWS":"arn:aws:iam::123456789012:user/user-name"},"Resource":"*"}],"Version":"2012-10-17"}', PolicyName: 'LogGroupPolicy643B329C', }); @@ -419,11 +394,9 @@ describe('log group', () => { // THEN expect(logGroup.logGroupPhysicalName()).toEqual('my-log-group'); - expect(stack).toHaveResource('AWS::Logs::LogGroup', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', { LogGroupName: 'my-log-group', }); - - }); }); @@ -434,5 +407,4 @@ function dataDrivenTests(cases: string[], body: (suffix: string) => void): void body(args); }); } - } diff --git a/packages/@aws-cdk/aws-logs/test/logstream.test.ts b/packages/@aws-cdk/aws-logs/test/logstream.test.ts index c55501adc6b1b..d599ca8bdbe0a 100644 --- a/packages/@aws-cdk/aws-logs/test/logstream.test.ts +++ b/packages/@aws-cdk/aws-logs/test/logstream.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import { Stack } from '@aws-cdk/core'; import { LogGroup, LogStream } from '../lib'; @@ -15,9 +15,6 @@ describe('log stream', () => { }); // THEN - expect(stack).toHaveResource('AWS::Logs::LogStream', { - }); - - + Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogStream', { }); }); }); diff --git a/packages/@aws-cdk/aws-logs/test/metricfilter.test.ts b/packages/@aws-cdk/aws-logs/test/metricfilter.test.ts index 15814140a9488..6ab67899db2ea 100644 --- a/packages/@aws-cdk/aws-logs/test/metricfilter.test.ts +++ b/packages/@aws-cdk/aws-logs/test/metricfilter.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import { Metric } from '@aws-cdk/aws-cloudwatch'; import { Stack } from '@aws-cdk/core'; import { FilterPattern, LogGroup, MetricFilter } from '../lib'; @@ -19,7 +19,7 @@ describe('metric filter', () => { }); // THEN - expect(stack).toHaveResource('AWS::Logs::MetricFilter', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::MetricFilter', { MetricTransformations: [{ MetricNamespace: 'AWS/Test', MetricName: 'Latency', @@ -28,8 +28,6 @@ describe('metric filter', () => { FilterPattern: '{ $.latency = "*" }', LogGroupName: { Ref: 'LogGroupF5B46931' }, }); - - }); test('metric filter exposes metric', () => { @@ -54,8 +52,6 @@ describe('metric filter', () => { namespace: 'AWS/Test', statistic: 'avg', })); - - }); test('metric filter exposes metric with custom statistic', () => { @@ -80,7 +76,5 @@ describe('metric filter', () => { namespace: 'AWS/Test', statistic: 'maximum', })); - - }); }); diff --git a/packages/@aws-cdk/aws-logs/test/pattern.test.ts b/packages/@aws-cdk/aws-logs/test/pattern.test.ts index 848c3ef824aa7..b49c9cd220588 100644 --- a/packages/@aws-cdk/aws-logs/test/pattern.test.ts +++ b/packages/@aws-cdk/aws-logs/test/pattern.test.ts @@ -6,16 +6,12 @@ describe('pattern', () => { const pattern = FilterPattern.allTerms('foo', 'bar', 'baz'); expect('"foo" "bar" "baz"').toEqual(pattern.logPatternString); - - }); test('quoted terms', () => { const pattern = FilterPattern.allTerms('"foo" he said'); expect('"\\"foo\\" he said"').toEqual(pattern.logPatternString); - - }); test('disjunction of conjunctions', () => { @@ -25,8 +21,6 @@ describe('pattern', () => { ); expect('?"foo" "bar" ?"baz"').toEqual(pattern.logPatternString); - - }); test('dont prefix with ? if only one disjunction', () => { @@ -35,16 +29,12 @@ describe('pattern', () => { ); expect('"foo" "bar"').toEqual(pattern.logPatternString); - - }); test('empty log pattern is empty string', () => { const pattern = FilterPattern.anyTermGroup(); expect('').toEqual(pattern.logPatternString); - - }); }); @@ -53,24 +43,18 @@ describe('pattern', () => { const pattern = FilterPattern.stringValue('$.field', '=', 'value'); expect('{ $.field = "value" }').toEqual(pattern.logPatternString); - - }); test('also recognize ==', () => { const pattern = FilterPattern.stringValue('$.field', '==', 'value'); expect('{ $.field = "value" }').toEqual(pattern.logPatternString); - - }); test('number patterns', () => { const pattern = FilterPattern.numberValue('$.field', '<=', 300); expect('{ $.field <= 300 }').toEqual(pattern.logPatternString); - - }); test('combining with AND or OR', () => { @@ -82,8 +66,6 @@ describe('pattern', () => { const orPattern = FilterPattern.any(p1, p2); expect('{ ($.field <= 300) || ($.field = "value") }').toEqual(orPattern.logPatternString); - - }); test('single AND is not wrapped with parens', () => { @@ -92,32 +74,24 @@ describe('pattern', () => { const pattern = FilterPattern.all(p1); expect('{ $.field = "value" }').toEqual(pattern.logPatternString); - - }); test('empty AND is rejected', () => { expect(() => { FilterPattern.all(); }).toThrow(); - - }); test('invalid string operators are rejected', () => { expect(() => { FilterPattern.stringValue('$.field', '<=', 'hello'); }).toThrow(); - - }); test('can test boolean value', () => { const pattern = FilterPattern.booleanValue('$.field', false); expect('{ $.field IS FALSE }').toEqual(pattern.logPatternString); - - }); }); @@ -126,8 +100,6 @@ describe('pattern', () => { const pattern = FilterPattern.spaceDelimited('...', 'status_code', 'bytes'); expect(pattern.logPatternString).toEqual('[..., status_code, bytes]'); - - }); test('add restrictions', () => { @@ -136,16 +108,12 @@ describe('pattern', () => { .whereNumber('status_code', '!=', 403); expect(pattern.logPatternString).toEqual('[..., status_code = "4*" && status_code != 403, bytes]'); - - }); test('cant use more than one ellipsis', () => { expect(() => { FilterPattern.spaceDelimited('...', 'status_code', '...'); }).toThrow(); - - }); }); }); diff --git a/packages/@aws-cdk/aws-logs/test/policy.test.ts b/packages/@aws-cdk/aws-logs/test/policy.test.ts index 4b2684a9957b1..8ffb66ab8eb29 100644 --- a/packages/@aws-cdk/aws-logs/test/policy.test.ts +++ b/packages/@aws-cdk/aws-logs/test/policy.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import { PolicyStatement, ServicePrincipal } from '@aws-cdk/aws-iam'; import { Stack } from '@aws-cdk/core'; import { LogGroup, ResourcePolicy } from '../lib'; @@ -16,7 +16,7 @@ describe('resource policy', () => { })); // THEN - expect(stack).toHaveResource('AWS::Logs::ResourcePolicy', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::ResourcePolicy', { PolicyName: 'LogGroupPolicy643B329C', PolicyDocument: JSON.stringify({ Statement: [ @@ -45,7 +45,7 @@ describe('resource policy', () => { })); // THEN - expect(stack).toHaveResource('AWS::Logs::ResourcePolicy', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::ResourcePolicy', { PolicyName: 'ResourcePolicy', }); }); diff --git a/packages/@aws-cdk/aws-logs/test/subscriptionfilter.test.ts b/packages/@aws-cdk/aws-logs/test/subscriptionfilter.test.ts index 595e4933745ca..bc691e26aaa96 100644 --- a/packages/@aws-cdk/aws-logs/test/subscriptionfilter.test.ts +++ b/packages/@aws-cdk/aws-logs/test/subscriptionfilter.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import { Stack } from '@aws-cdk/core'; import { Construct } from 'constructs'; import { FilterPattern, ILogGroup, ILogSubscriptionDestination, LogGroup, SubscriptionFilter } from '../lib'; @@ -17,13 +17,11 @@ describe('subscription filter', () => { }); // THEN - expect(stack).toHaveResource('AWS::Logs::SubscriptionFilter', { + Template.fromStack(stack).hasResourceProperties('AWS::Logs::SubscriptionFilter', { DestinationArn: 'arn:bogus', FilterPattern: 'some pattern', LogGroupName: { Ref: 'LogGroupF5B46931' }, }); - - }); });