From b3c557f076f0997d03c0c9c449f38b574d691042 Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Fri, 24 Sep 2021 14:28:22 -0400 Subject: [PATCH 1/9] fix(assertions): absentProperty is not of type Matcher --- packages/@aws-cdk/assertions/lib/match.ts | 38 ++++++++-------- .../@aws-cdk/assertions/test/match.test.ts | 29 +++++++++++-- .../@aws-cdk/assertions/test/template.test.ts | 43 ++++++++++++++++++- 3 files changed, 88 insertions(+), 22 deletions(-) diff --git a/packages/@aws-cdk/assertions/lib/match.ts b/packages/@aws-cdk/assertions/lib/match.ts index 4fea0ed0f713e..912d583cd448a 100644 --- a/packages/@aws-cdk/assertions/lib/match.ts +++ b/packages/@aws-cdk/assertions/lib/match.ts @@ -1,6 +1,5 @@ import { Matcher, MatchResult } from './matcher'; import { getType } from './private/type'; -import { ABSENT } from './vendored/assert'; /** * Partial and special matching during template assertions. @@ -9,8 +8,8 @@ export abstract class Match { /** * Use this matcher in the place of a field's value, if the field must not be present. */ - public static absentProperty(): string { - return ABSENT; + public static absentProperty(): Matcher { + return new AbsentMatch('absentProperty'); } /** @@ -128,10 +127,6 @@ class LiteralMatch extends Matcher { return result; } - if (this.pattern === ABSENT) { - throw new Error('absentProperty() can only be used in an object matcher'); - } - if (actual !== this.pattern) { result.push(this, [], `Expected ${this.pattern} but received ${actual}`); } @@ -184,9 +179,10 @@ class ArrayMatch extends Matcher { const patternElement = this.pattern[patternIdx]; const matcher = Matcher.isMatcher(patternElement) ? patternElement : new LiteralMatch(this.name, patternElement); - if (this.subsequence && matcher instanceof AnyMatch) { - // array subsequence matcher is not compatible with anyValue() matcher. They don't make sense to be used together. - throw new Error('The Matcher anyValue() cannot be nested within arrayWith()'); + const matcherName = matcher.name; + if (this.subsequence && (matcherName == 'absentProperty' || matcherName == 'anyValue')) { + // array subsequence matcher is not compatible with anyValue() or absentProperty() matcher. They don't make sense to be used together. + throw new Error(`The Matcher ${matcherName}() cannot be nested within arrayWith()`); } const innerResult = matcher.test(actual[actualIdx]); @@ -252,13 +248,7 @@ class ObjectMatch extends Matcher { } for (const [patternKey, patternVal] of Object.entries(this.pattern)) { - if (patternVal === ABSENT) { - if (patternKey in actual) { - result.push(this, [`/${patternKey}`], 'Key should be absent'); - } - continue; - } - if (!(patternKey in actual)) { + if (!(patternKey in actual) && !(patternVal instanceof AbsentMatch)) { result.push(this, [`/${patternKey}`], 'Missing key'); continue; } @@ -338,4 +328,18 @@ class AnyMatch extends Matcher { } return result; } +} + +class AbsentMatch extends Matcher { + constructor(public readonly name: string) { + super(); + } + + public test(actual: any): MatchResult { + const result = new MatchResult(actual); + if (actual !== undefined) { + result.push(this, [], `Received ${actual}, but key should be absent`); + } + return result; + } } \ No newline at end of file diff --git a/packages/@aws-cdk/assertions/test/match.test.ts b/packages/@aws-cdk/assertions/test/match.test.ts index b0c92a2da2c8f..0754d8ba08cfa 100644 --- a/packages/@aws-cdk/assertions/test/match.test.ts +++ b/packages/@aws-cdk/assertions/test/match.test.ts @@ -77,7 +77,7 @@ describe('Matchers', () => { }); test('absent', () => { - expect(() => Match.exact(Match.absentProperty()).test('foo')).toThrow(/absentProperty/); + expect(() => Match.exact(Match.absentProperty())).toThrow(/cannot directly contain another matcher/); }); }); @@ -125,8 +125,9 @@ describe('Matchers', () => { expectFailure(matcher, [{ foo: 'baz', fred: 'waldo' }], [/Missing element at pattern index 0/]); }); - test('absent', () => { - expect(() => Match.arrayWith([Match.absentProperty()]).test(['foo'])).toThrow(/absentProperty/); + test('incompatible with absent', () => { + matcher = Match.arrayWith(['foo', Match.absentProperty()]); + expect(() => matcher.test(['foo', 'bar'])).toThrow(/absentProperty\(\) cannot be nested within arrayWith\(\)/); }); test('incompatible with anyValue', () => { @@ -186,7 +187,7 @@ describe('Matchers', () => { test('absent', () => { matcher = Match.objectLike({ foo: Match.absentProperty() }); expectPass(matcher, { bar: 'baz' }); - expectFailure(matcher, { foo: 'baz' }, [/Key should be absent at \/foo/]); + expectFailure(matcher, { foo: 'baz' }, [/key should be absent at \/foo/]); }); }); @@ -363,6 +364,26 @@ describe('Matchers', () => { expectFailure(matcher, '{ "Foo"', [/invalid JSON string/i]); }); }); + + describe('absent property', () => { + let matcher: Matcher; + + test('simple', () => { + matcher = Match.absentProperty(); + expectFailure(matcher, 'foo', ['Received foo, but key should be absent']); + expectPass(matcher, undefined); + }); + + test('nested in object', () => { + matcher = Match.objectLike({ foo: Match.absentProperty() }); + expectFailure(matcher, { foo: 'bar' }, [/key should be absent at \/foo/]); + expectFailure(matcher, { foo: [1, 2] }, [/key should be absent at \/foo/]); + expectFailure(matcher, { foo: null }, [/key should be absent at \/foo/]); + + expectPass(matcher, { foo: undefined }); + expectPass(matcher, {}); + }); + }); }); function expectPass(matcher: Matcher, target: any): void { diff --git a/packages/@aws-cdk/assertions/test/template.test.ts b/packages/@aws-cdk/assertions/test/template.test.ts index 7c3221763446c..630e8a3b01a92 100644 --- a/packages/@aws-cdk/assertions/test/template.test.ts +++ b/packages/@aws-cdk/assertions/test/template.test.ts @@ -252,7 +252,7 @@ describe('Template', () => { }); expect(() => inspect.hasResource('Foo::Bar', { Properties: Match.objectLike({ baz: Match.absentProperty() }), - })).toThrow(/Key should be absent at \/Properties\/baz/); + })).toThrow(/key should be absent at \/Properties\/baz/); }); test('incorrect types', () => { @@ -269,6 +269,47 @@ describe('Template', () => { }); }); + describe('hasResourceProperties', () => { + test('absent', () => { + const stack = new Stack(); + new CfnResource(stack, 'Foo', { + type: 'Foo::Bar', + properties: { baz: 'qux' }, + }); + + const inspect = Template.fromStack(stack); + inspect.hasResourceProperties('Foo::Bar', { + bar: Match.absentProperty(), + }); + expect(() => inspect.hasResourceProperties('Foo::Bar', { + baz: Match.absentProperty(), + })).toThrow(/key should be absent at \/Properties\/baz/); + }); + + test('absent properties', () => { + const stack = new Stack(); + new CfnResource(stack, 'Foo', { + type: 'Foo::Bar', + }); + + const inspect = Template.fromStack(stack); + inspect.hasResourceProperties('Foo::Bar', Match.absentProperty()); + }); + + test('not', () => { + const stack = new Stack(); + new CfnResource(stack, 'Foo', { + type: 'Foo::Bar', + properties: { baz: 'qux' }, + }); + + const inspect = Template.fromStack(stack); + inspect.hasResourceProperties('Foo::Bar', Match.not({ + baz: 'boo', + })); + }); + }); + describe('getResources', () => { test('matching resource type', () => { const stack = new Stack(); From 463d4af3b04bed5e7c2c48d6d27505b21711753f Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Fri, 24 Sep 2021 15:03:03 -0400 Subject: [PATCH 2/9] linter --- packages/@aws-cdk/assertions/test/template.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/assertions/test/template.test.ts b/packages/@aws-cdk/assertions/test/template.test.ts index 630e8a3b01a92..b4be776c9f1f7 100644 --- a/packages/@aws-cdk/assertions/test/template.test.ts +++ b/packages/@aws-cdk/assertions/test/template.test.ts @@ -273,7 +273,7 @@ describe('Template', () => { test('absent', () => { const stack = new Stack(); new CfnResource(stack, 'Foo', { - type: 'Foo::Bar', + type: 'Foo::Bar', properties: { baz: 'qux' }, }); From e9f4405fe7b928f89d26cee51be0a42f2d6544d0 Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Mon, 27 Sep 2021 13:27:37 -0400 Subject: [PATCH 3/9] change absentProperty to absent --- packages/@aws-cdk/assertions/README.md | 8 ++++---- packages/@aws-cdk/assertions/lib/match.ts | 8 ++++---- packages/@aws-cdk/assertions/test/match.test.ts | 12 ++++++------ packages/@aws-cdk/assertions/test/template.test.ts | 10 +++++----- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/@aws-cdk/assertions/README.md b/packages/@aws-cdk/assertions/README.md index 0c2d9d1ecdadf..4d49184cde2ab 100644 --- a/packages/@aws-cdk/assertions/README.md +++ b/packages/@aws-cdk/assertions/README.md @@ -194,7 +194,7 @@ match. ### Presence and Absence -The `Match.absentProperty()` matcher can be used to specify that a specific +The `Match.absent()` matcher can be used to specify that a specific property should not exist on the target. This can be used within `Match.objectLike()` or outside of any matchers. @@ -216,15 +216,15 @@ or outside of any matchers. // The following will NOT throw an assertion error assert.hasResourceProperties('Foo::Bar', { Fred: Match.objectLike({ - Bob: Match.absentProperty(), + Bob: Match.absent(), }), }); // The following will throw an assertion error assert.hasResourceProperties('Foo::Bar', { Fred: Match.objectLike({ - Wobble: Match.absentProperty(), - }) + Wobble: Match.absent(), + }), }); ``` diff --git a/packages/@aws-cdk/assertions/lib/match.ts b/packages/@aws-cdk/assertions/lib/match.ts index 912d583cd448a..8e4d83a398347 100644 --- a/packages/@aws-cdk/assertions/lib/match.ts +++ b/packages/@aws-cdk/assertions/lib/match.ts @@ -8,8 +8,8 @@ export abstract class Match { /** * Use this matcher in the place of a field's value, if the field must not be present. */ - public static absentProperty(): Matcher { - return new AbsentMatch('absentProperty'); + public static absent(): Matcher { + return new AbsentMatch('absent'); } /** @@ -180,8 +180,8 @@ class ArrayMatch extends Matcher { const matcher = Matcher.isMatcher(patternElement) ? patternElement : new LiteralMatch(this.name, patternElement); const matcherName = matcher.name; - if (this.subsequence && (matcherName == 'absentProperty' || matcherName == 'anyValue')) { - // array subsequence matcher is not compatible with anyValue() or absentProperty() matcher. They don't make sense to be used together. + if (this.subsequence && (matcherName == 'absent' || matcherName == 'anyValue')) { + // array subsequence matcher is not compatible with anyValue() or absent() matcher. They don't make sense to be used together. throw new Error(`The Matcher ${matcherName}() cannot be nested within arrayWith()`); } diff --git a/packages/@aws-cdk/assertions/test/match.test.ts b/packages/@aws-cdk/assertions/test/match.test.ts index 0754d8ba08cfa..ced3fbabfe62a 100644 --- a/packages/@aws-cdk/assertions/test/match.test.ts +++ b/packages/@aws-cdk/assertions/test/match.test.ts @@ -77,7 +77,7 @@ describe('Matchers', () => { }); test('absent', () => { - expect(() => Match.exact(Match.absentProperty())).toThrow(/cannot directly contain another matcher/); + expect(() => Match.exact(Match.absent())).toThrow(/cannot directly contain another matcher/); }); }); @@ -126,8 +126,8 @@ describe('Matchers', () => { }); test('incompatible with absent', () => { - matcher = Match.arrayWith(['foo', Match.absentProperty()]); - expect(() => matcher.test(['foo', 'bar'])).toThrow(/absentProperty\(\) cannot be nested within arrayWith\(\)/); + matcher = Match.arrayWith(['foo', Match.absent()]); + expect(() => matcher.test(['foo', 'bar'])).toThrow(/absent\(\) cannot be nested within arrayWith\(\)/); }); test('incompatible with anyValue', () => { @@ -185,7 +185,7 @@ describe('Matchers', () => { }); test('absent', () => { - matcher = Match.objectLike({ foo: Match.absentProperty() }); + matcher = Match.objectLike({ foo: Match.absent() }); expectPass(matcher, { bar: 'baz' }); expectFailure(matcher, { foo: 'baz' }, [/key should be absent at \/foo/]); }); @@ -369,13 +369,13 @@ describe('Matchers', () => { let matcher: Matcher; test('simple', () => { - matcher = Match.absentProperty(); + matcher = Match.absent(); expectFailure(matcher, 'foo', ['Received foo, but key should be absent']); expectPass(matcher, undefined); }); test('nested in object', () => { - matcher = Match.objectLike({ foo: Match.absentProperty() }); + matcher = Match.objectLike({ foo: Match.absent() }); expectFailure(matcher, { foo: 'bar' }, [/key should be absent at \/foo/]); expectFailure(matcher, { foo: [1, 2] }, [/key should be absent at \/foo/]); expectFailure(matcher, { foo: null }, [/key should be absent at \/foo/]); diff --git a/packages/@aws-cdk/assertions/test/template.test.ts b/packages/@aws-cdk/assertions/test/template.test.ts index b4be776c9f1f7..b93eb5101592b 100644 --- a/packages/@aws-cdk/assertions/test/template.test.ts +++ b/packages/@aws-cdk/assertions/test/template.test.ts @@ -248,10 +248,10 @@ describe('Template', () => { const inspect = Template.fromStack(stack); inspect.hasResource('Foo::Bar', { - Properties: Match.objectLike({ foo: Match.absentProperty() }), + Properties: Match.objectLike({ foo: Match.absent() }), }); expect(() => inspect.hasResource('Foo::Bar', { - Properties: Match.objectLike({ baz: Match.absentProperty() }), + Properties: Match.objectLike({ baz: Match.absent() }), })).toThrow(/key should be absent at \/Properties\/baz/); }); @@ -279,10 +279,10 @@ describe('Template', () => { const inspect = Template.fromStack(stack); inspect.hasResourceProperties('Foo::Bar', { - bar: Match.absentProperty(), + bar: Match.absent(), }); expect(() => inspect.hasResourceProperties('Foo::Bar', { - baz: Match.absentProperty(), + baz: Match.absent(), })).toThrow(/key should be absent at \/Properties\/baz/); }); @@ -293,7 +293,7 @@ describe('Template', () => { }); const inspect = Template.fromStack(stack); - inspect.hasResourceProperties('Foo::Bar', Match.absentProperty()); + inspect.hasResourceProperties('Foo::Bar', Match.absent()); }); test('not', () => { From 12447cf60b5b4dd4f68695700f69b9c438d241a1 Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Mon, 27 Sep 2021 13:59:31 -0400 Subject: [PATCH 4/9] change absentProperty() to absent() --- packages/@aws-cdk/assertions/test/match.test.ts | 2 +- packages/@aws-cdk/assertions/test/template.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/assertions/test/match.test.ts b/packages/@aws-cdk/assertions/test/match.test.ts index ced3fbabfe62a..0b1ce784f9023 100644 --- a/packages/@aws-cdk/assertions/test/match.test.ts +++ b/packages/@aws-cdk/assertions/test/match.test.ts @@ -365,7 +365,7 @@ describe('Matchers', () => { }); }); - describe('absent property', () => { + describe('absent', () => { let matcher: Matcher; test('simple', () => { diff --git a/packages/@aws-cdk/assertions/test/template.test.ts b/packages/@aws-cdk/assertions/test/template.test.ts index b93eb5101592b..59a676f90d3af 100644 --- a/packages/@aws-cdk/assertions/test/template.test.ts +++ b/packages/@aws-cdk/assertions/test/template.test.ts @@ -286,7 +286,7 @@ describe('Template', () => { })).toThrow(/key should be absent at \/Properties\/baz/); }); - test('absent properties', () => { + test('absent - no properties on template', () => { const stack = new Stack(); new CfnResource(stack, 'Foo', { type: 'Foo::Bar', From 54b4af05d09907bdaf2c4bd01215be5a87acfa3d Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Mon, 27 Sep 2021 14:02:22 -0400 Subject: [PATCH 5/9] change absentProperty() to absent() --- .../test/http/lambda.test.ts | 2 +- .../aws-apigatewayv2/test/http/api.test.ts | 6 +-- .../aws-cloudwatch/test/alarm.test.ts | 6 +-- .../aws-cognito/test/user-pool-client.test.ts | 50 +++++++++---------- .../aws-cognito/test/user-pool.test.ts | 48 +++++++++--------- .../aws-efs/test/efs-file-system.test.ts | 2 +- .../test/s3-bucket.test.ts | 4 +- .../test/delivery-stream.test.ts | 12 ++--- .../@aws-cdk/aws-neptune/test/cluster.test.ts | 2 +- .../aws-redshift/test/cluster.test.ts | 4 +- .../aws-synthetics/test/canary.test.ts | 2 +- .../test/example-resource.test.ts | 2 +- 12 files changed, 70 insertions(+), 70 deletions(-) diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers/test/http/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-authorizers/test/http/lambda.test.ts index 1f62ad76867b0..c9fdf62c17d57 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers/test/http/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers/test/http/lambda.test.ts @@ -103,7 +103,7 @@ describe('HttpLambdaAuthorizer', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::ApiGatewayV2::Authorizer', { AuthorizerPayloadFormatVersion: '1.0', - EnableSimpleResponses: Match.absentProperty(), + EnableSimpleResponses: Match.absent(), }); }); diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/http/api.test.ts b/packages/@aws-cdk/aws-apigatewayv2/test/http/api.test.ts index dc096594d0ecd..5b7f1052bfe35 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/test/http/api.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2/test/http/api.test.ts @@ -127,7 +127,7 @@ describe('HttpApi', () => { new HttpApi(stack, 'HttpApi'); Template.fromStack(stack).hasResourceProperties('AWS::ApiGatewayV2::Api', { - CorsConfiguration: Match.absentProperty(), + CorsConfiguration: Match.absent(), }); }); @@ -447,7 +447,7 @@ describe('HttpApi', () => { Template.fromStack(stack).hasResourceProperties('AWS::ApiGatewayV2::Route', { RouteKey: 'GET /chickens', AuthorizationType: 'NONE', - AuthorizerId: Match.absentProperty(), + AuthorizerId: Match.absent(), }); }); @@ -469,7 +469,7 @@ describe('HttpApi', () => { }); Template.fromStack(stack).hasResourceProperties('AWS::ApiGatewayV2::Route', { - AuthorizationScopes: Match.absentProperty(), + AuthorizationScopes: Match.absent(), }); }); diff --git a/packages/@aws-cdk/aws-cloudwatch/test/alarm.test.ts b/packages/@aws-cdk/aws-cloudwatch/test/alarm.test.ts index c2381d2891a86..afb2224eb2f50 100644 --- a/packages/@aws-cdk/aws-cloudwatch/test/alarm.test.ts +++ b/packages/@aws-cdk/aws-cloudwatch/test/alarm.test.ts @@ -126,7 +126,7 @@ describe('Alarm', () => { Namespace: 'CDK/Test', Period: 300, Statistic: 'Maximum', - ExtendedStatistic: Match.absentProperty(), + ExtendedStatistic: Match.absent(), Threshold: 1000, }); @@ -152,7 +152,7 @@ describe('Alarm', () => { MetricName: 'Metric', Namespace: 'CDK/Test', Period: 300, - Statistic: Match.absentProperty(), + Statistic: Match.absent(), ExtendedStatistic: 'p99', Threshold: 1000, }); @@ -270,7 +270,7 @@ describe('Alarm', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { - Statistic: Match.absentProperty(), + Statistic: Match.absent(), ExtendedStatistic: 'tm99.9999999999', }); diff --git a/packages/@aws-cdk/aws-cognito/test/user-pool-client.test.ts b/packages/@aws-cdk/aws-cognito/test/user-pool-client.test.ts index d6fc81f28c43c..2d2a72d48f767 100644 --- a/packages/@aws-cdk/aws-cognito/test/user-pool-client.test.ts +++ b/packages/@aws-cdk/aws-cognito/test/user-pool-client.test.ts @@ -63,7 +63,7 @@ describe('User Pool Client', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { - ExplicitAuthFlows: Match.absentProperty(), + ExplicitAuthFlows: Match.absent(), }); }); @@ -179,7 +179,7 @@ describe('User Pool Client', () => { Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { AllowedOAuthFlows: ['client_credentials'], - CallbackURLs: Match.absentProperty(), + CallbackURLs: Match.absent(), }); Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { @@ -206,7 +206,7 @@ describe('User Pool Client', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { - CallbackURLs: Match.absentProperty(), + CallbackURLs: Match.absent(), }); }); @@ -447,7 +447,7 @@ describe('User Pool Client', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { UserPoolId: stack.resolve(pool.userPoolId), - PreventUserExistenceErrors: Match.absentProperty(), + PreventUserExistenceErrors: Match.absent(), }); }); @@ -515,8 +515,8 @@ describe('User Pool Client', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { ClientName: 'OAuthDisabled', - AllowedOAuthFlows: Match.absentProperty(), - AllowedOAuthScopes: Match.absentProperty(), + AllowedOAuthFlows: Match.absent(), + AllowedOAuthScopes: Match.absent(), AllowedOAuthFlowsUserPoolClient: false, }); Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { @@ -551,7 +551,7 @@ describe('User Pool Client', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { - EnableTokenRevocation: Match.absentProperty(), + EnableTokenRevocation: Match.absent(), }); }); @@ -632,42 +632,42 @@ describe('User Pool Client', () => { Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { ClientName: 'Client2', AccessTokenValidity: 60, - IdTokenValidity: Match.absentProperty(), - RefreshTokenValidity: Match.absentProperty(), + IdTokenValidity: Match.absent(), + RefreshTokenValidity: Match.absent(), TokenValidityUnits: { AccessToken: 'minutes', - IdToken: Match.absentProperty(), - RefreshToken: Match.absentProperty(), + IdToken: Match.absent(), + RefreshToken: Match.absent(), }, }); Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { ClientName: 'Client3', - AccessTokenValidity: Match.absentProperty(), + AccessTokenValidity: Match.absent(), IdTokenValidity: 60, - RefreshTokenValidity: Match.absentProperty(), + RefreshTokenValidity: Match.absent(), TokenValidityUnits: { - AccessToken: Match.absentProperty(), + AccessToken: Match.absent(), IdToken: 'minutes', - RefreshToken: Match.absentProperty(), + RefreshToken: Match.absent(), }, }); Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { ClientName: 'Client4', - AccessTokenValidity: Match.absentProperty(), - IdTokenValidity: Match.absentProperty(), + AccessTokenValidity: Match.absent(), + IdTokenValidity: Match.absent(), RefreshTokenValidity: 43200, TokenValidityUnits: { - AccessToken: Match.absentProperty(), - IdToken: Match.absentProperty(), + AccessToken: Match.absent(), + IdToken: Match.absent(), RefreshToken: 'minutes', }, }); Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { ClientName: 'Client5', - TokenValidityUnits: Match.absentProperty(), - IdTokenValidity: Match.absentProperty(), - RefreshTokenValidity: Match.absentProperty(), - AccessTokenValidity: Match.absentProperty(), + TokenValidityUnits: Match.absent(), + IdTokenValidity: Match.absent(), + RefreshTokenValidity: Match.absent(), + AccessTokenValidity: Match.absent(), }); }); @@ -886,8 +886,8 @@ describe('User Pool Client', () => { // EXPECT Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolClient', { - ReadAttributes: Match.absentProperty(), - WriteAttributes: Match.absentProperty(), + ReadAttributes: Match.absent(), + WriteAttributes: Match.absent(), }); }); diff --git a/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts b/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts index 0c61312222355..7b132803da2d6 100644 --- a/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts +++ b/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts @@ -17,7 +17,7 @@ describe('User Pool', () => { Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { AdminCreateUserConfig: { AllowAdminCreateUserOnly: true, - InviteMessageTemplate: Match.absentProperty(), + InviteMessageTemplate: Match.absent(), }, EmailVerificationMessage: 'The verification code to your new account is {####}', EmailVerificationSubject: 'Verify your new account', @@ -28,9 +28,9 @@ describe('User Pool', () => { EmailSubject: 'Verify your new account', SmsMessage: 'The verification code to your new account is {####}', }, - SmsAuthenticationMessage: Match.absentProperty(), - SmsConfiguration: Match.absentProperty(), - lambdaTriggers: Match.absentProperty(), + SmsAuthenticationMessage: Match.absent(), + SmsConfiguration: Match.absent(), + lambdaTriggers: Match.absent(), }); Template.fromStack(stack).hasResource('AWS::Cognito::UserPool', { @@ -68,8 +68,8 @@ describe('User Pool', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { - EmailVerificationMessage: Match.absentProperty(), - EmailVerificationSubject: Match.absentProperty(), + EmailVerificationMessage: Match.absent(), + EmailVerificationSubject: Match.absent(), SmsVerificationMessage: 'The verification code to your new account is {####}', VerificationMessageTemplate: { DefaultEmailOption: 'CONFIRM_WITH_LINK', @@ -415,8 +415,8 @@ describe('User Pool', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { - UsernameAttributes: Match.absentProperty(), - AliasAttributes: Match.absentProperty(), + UsernameAttributes: Match.absent(), + AliasAttributes: Match.absent(), }); }); @@ -438,7 +438,7 @@ describe('User Pool', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { - UsernameAttributes: Match.absentProperty(), + UsernameAttributes: Match.absent(), AliasAttributes: ['email'], }); }); @@ -455,7 +455,7 @@ describe('User Pool', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { UsernameAttributes: ['email', 'phone_number'], - AliasAttributes: Match.absentProperty(), + AliasAttributes: Match.absent(), }); }); @@ -526,7 +526,7 @@ describe('User Pool', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { - UsernameConfiguration: Match.absentProperty(), + UsernameConfiguration: Match.absent(), }); }); @@ -638,7 +638,7 @@ describe('User Pool', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { UserPoolName: 'Pool', - Schema: Match.absentProperty(), + Schema: Match.absent(), }); }); @@ -687,14 +687,14 @@ describe('User Pool', () => { { Name: 'custom-string-attr', AttributeDataType: 'String', - StringAttributeConstraints: Match.absentProperty(), - NumberAttributeConstraints: Match.absentProperty(), + StringAttributeConstraints: Match.absent(), + NumberAttributeConstraints: Match.absent(), }, { Name: 'custom-number-attr', AttributeDataType: 'Number', - StringAttributeConstraints: Match.absentProperty(), - NumberAttributeConstraints: Match.absentProperty(), + StringAttributeConstraints: Match.absent(), + NumberAttributeConstraints: Match.absent(), }, ], }); @@ -759,13 +759,13 @@ describe('User Pool', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { UserPoolName: 'Pool1', - MfaConfiguration: Match.absentProperty(), - EnabledMfas: Match.absentProperty(), + MfaConfiguration: Match.absent(), + EnabledMfas: Match.absent(), }); Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { UserPoolName: 'Pool2', MfaConfiguration: 'OFF', - EnabledMfas: Match.absentProperty(), + EnabledMfas: Match.absent(), }); }); @@ -1120,7 +1120,7 @@ describe('User Pool', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { - AccountRecoverySetting: Match.absentProperty(), + AccountRecoverySetting: Match.absent(), }); }); @@ -1153,7 +1153,7 @@ describe('User Pool', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { - SmsConfiguration: Match.absentProperty(), + SmsConfiguration: Match.absent(), }); }); @@ -1245,7 +1245,7 @@ describe('User Pool', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { - SmsConfiguration: Match.absentProperty(), + SmsConfiguration: Match.absent(), }); }); @@ -1267,7 +1267,7 @@ describe('User Pool', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { - SmsConfiguration: Match.absentProperty(), + SmsConfiguration: Match.absent(), }); }); @@ -1351,7 +1351,7 @@ describe('User Pool', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', { - SmsConfiguration: Match.absentProperty(), + SmsConfiguration: Match.absent(), }); }); diff --git a/packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts b/packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts index 60a0133e63ca2..ae1d85666e294 100644 --- a/packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts +++ b/packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts @@ -42,7 +42,7 @@ testLegacyBehavior('when @aws-cdk/aws-efs:defaultEncryptionAtRest is missing, en }); Template.fromStack(customStack).hasResourceProperties('AWS::EFS::FileSystem', { - Encrypted: Match.absentProperty(), + Encrypted: Match.absent(), }); }); diff --git a/packages/@aws-cdk/aws-kinesisfirehose-destinations/test/s3-bucket.test.ts b/packages/@aws-cdk/aws-kinesisfirehose-destinations/test/s3-bucket.test.ts index 448d0b8efcf40..74d37d180f954 100644 --- a/packages/@aws-cdk/aws-kinesisfirehose-destinations/test/s3-bucket.test.ts +++ b/packages/@aws-cdk/aws-kinesisfirehose-destinations/test/s3-bucket.test.ts @@ -169,7 +169,7 @@ describe('S3 destination', () => { Template.fromStack(stack).resourceCountIs('AWS::Logs::LogGroup', 0); Template.fromStack(stack).hasResourceProperties('AWS::KinesisFirehose::DeliveryStream', { ExtendedS3DestinationConfiguration: { - CloudWatchLoggingOptions: Match.absentProperty(), + CloudWatchLoggingOptions: Match.absent(), }, }); }); @@ -548,7 +548,7 @@ describe('S3 destination', () => { Template.fromStack(stack).resourceCountIs('AWS::S3::Bucket', 1); Template.fromStack(stack).hasResourceProperties('AWS::KinesisFirehose::DeliveryStream', { ExtendedS3DestinationConfiguration: { - S3BackupConfiguration: Match.absentProperty(), + S3BackupConfiguration: Match.absent(), }, }); }); diff --git a/packages/@aws-cdk/aws-kinesisfirehose/test/delivery-stream.test.ts b/packages/@aws-cdk/aws-kinesisfirehose/test/delivery-stream.test.ts index f716e56a8f326..ec206b739ed01 100644 --- a/packages/@aws-cdk/aws-kinesisfirehose/test/delivery-stream.test.ts +++ b/packages/@aws-cdk/aws-kinesisfirehose/test/delivery-stream.test.ts @@ -47,10 +47,10 @@ describe('delivery stream', () => { }); Template.fromStack(stack).hasResourceProperties('AWS::KinesisFirehose::DeliveryStream', { - DeliveryStreamEncryptionConfigurationInput: Match.absentProperty(), - DeliveryStreamName: Match.absentProperty(), + DeliveryStreamEncryptionConfigurationInput: Match.absent(), + DeliveryStreamName: Match.absent(), DeliveryStreamType: 'DirectPut', - KinesisStreamSourceConfiguration: Match.absentProperty(), + KinesisStreamSourceConfiguration: Match.absent(), ExtendedS3DestinationConfiguration: { BucketARN: bucketArn, RoleARN: roleArn, @@ -205,7 +205,7 @@ describe('delivery stream', () => { Template.fromStack(stack).hasResourceProperties('AWS::KinesisFirehose::DeliveryStream', { DeliveryStreamType: 'DirectPut', DeliveryStreamEncryptionConfigurationInput: { - KeyARN: Match.absentProperty(), + KeyARN: Match.absent(), KeyType: 'AWS_OWNED_CMK', }, }); @@ -222,7 +222,7 @@ describe('delivery stream', () => { Template.fromStack(stack).resourceCountIs('AWS::IAM::Policy', 0); Template.fromStack(stack).hasResourceProperties('AWS::KinesisFirehose::DeliveryStream', { DeliveryStreamType: 'DirectPut', - DeliveryStreamEncryptionConfigurationInput: Match.absentProperty(), + DeliveryStreamEncryptionConfigurationInput: Match.absent(), }); }); @@ -326,7 +326,7 @@ describe('delivery stream', () => { DependsOn: [dependableId], }); Template.fromStack(stack).hasResource('AWS::IAM::Role', { - DependsOn: Match.absentProperty(), + DependsOn: Match.absent(), }); }); diff --git a/packages/@aws-cdk/aws-neptune/test/cluster.test.ts b/packages/@aws-cdk/aws-neptune/test/cluster.test.ts index 74f4770a8a74c..f53af7911dc6c 100644 --- a/packages/@aws-cdk/aws-neptune/test/cluster.test.ts +++ b/packages/@aws-cdk/aws-neptune/test/cluster.test.ts @@ -446,7 +446,7 @@ describe('DatabaseCluster', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Neptune::DBCluster', { - IamAuthEnabled: Match.absentProperty(), + IamAuthEnabled: Match.absent(), }); }); diff --git a/packages/@aws-cdk/aws-redshift/test/cluster.test.ts b/packages/@aws-cdk/aws-redshift/test/cluster.test.ts index 28f2fbfd4655b..f537d0e0e8605 100644 --- a/packages/@aws-cdk/aws-redshift/test/cluster.test.ts +++ b/packages/@aws-cdk/aws-redshift/test/cluster.test.ts @@ -145,7 +145,7 @@ describe('node count', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Redshift::Cluster', { ClusterType: 'single-node', - NumberOfNodes: Match.absentProperty(), + NumberOfNodes: Match.absent(), }); }); @@ -163,7 +163,7 @@ describe('node count', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Redshift::Cluster', { ClusterType: 'single-node', - NumberOfNodes: Match.absentProperty(), + NumberOfNodes: Match.absent(), }); }); diff --git a/packages/@aws-cdk/aws-synthetics/test/canary.test.ts b/packages/@aws-cdk/aws-synthetics/test/canary.test.ts index c4583ef5494cf..b4a456f1cd71b 100644 --- a/packages/@aws-cdk/aws-synthetics/test/canary.test.ts +++ b/packages/@aws-cdk/aws-synthetics/test/canary.test.ts @@ -229,7 +229,7 @@ test('environment variables are skipped if not provided', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Synthetics::Canary', { - RunConfig: Match.absentProperty(), + RunConfig: Match.(), }); }); diff --git a/packages/@aws-cdk/example-construct-library/test/example-resource.test.ts b/packages/@aws-cdk/example-construct-library/test/example-resource.test.ts index 091c0c7d1f65a..db1e8d68d4830 100644 --- a/packages/@aws-cdk/example-construct-library/test/example-resource.test.ts +++ b/packages/@aws-cdk/example-construct-library/test/example-resource.test.ts @@ -56,7 +56,7 @@ describe('Example Resource', () => { 'Ref': 'ExampleResourceWaitConditionHandle9C53A8D3', }, // this is how you can check a given property is _not_ set - 'RandomProperty': Match.absentProperty(), + 'RandomProperty': Match.absent(), }); }); From 99be8b360a6acee9c48c85b8d69b2cb47cb71447 Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Mon, 27 Sep 2021 14:03:32 -0400 Subject: [PATCH 6/9] readme change --- packages/@aws-cdk/assertions/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/assertions/README.md b/packages/@aws-cdk/assertions/README.md index 4d49184cde2ab..96899b432b1d5 100644 --- a/packages/@aws-cdk/assertions/README.md +++ b/packages/@aws-cdk/assertions/README.md @@ -195,7 +195,7 @@ match. ### Presence and Absence The `Match.absent()` matcher can be used to specify that a specific -property should not exist on the target. This can be used within `Match.objectLike()` +value should not exist on the target. This can be used within `Match.objectLike()` or outside of any matchers. ```ts From 1764aabdf954c06a72956c3cf3c947ba31eb18ff Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Mon, 27 Sep 2021 14:21:33 -0400 Subject: [PATCH 7/9] typo in synthetics --- packages/@aws-cdk/aws-synthetics/test/canary.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-synthetics/test/canary.test.ts b/packages/@aws-cdk/aws-synthetics/test/canary.test.ts index b4a456f1cd71b..27491d01b2850 100644 --- a/packages/@aws-cdk/aws-synthetics/test/canary.test.ts +++ b/packages/@aws-cdk/aws-synthetics/test/canary.test.ts @@ -229,7 +229,7 @@ test('environment variables are skipped if not provided', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::Synthetics::Canary', { - RunConfig: Match.(), + RunConfig: Match.absent(), }); }); From 582bbf063c37ede0c0d02bd901b5c9b4c50db776 Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Tue, 28 Sep 2021 12:23:57 -0400 Subject: [PATCH 8/9] fix merge test --- .../test/scalable-target.test.ts | 2 +- .../aws-chatbot/test/slack-channel-configuration.test.ts | 2 +- .../@aws-cdk/aws-iam/test/permissions-boundary.test.ts | 8 ++++---- packages/@aws-cdk/aws-logs/test/log-retention.test.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/@aws-cdk/aws-applicationautoscaling/test/scalable-target.test.ts b/packages/@aws-cdk/aws-applicationautoscaling/test/scalable-target.test.ts index 1ef4b7aac38b7..2cc6ae20ea4c4 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/test/scalable-target.test.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/test/scalable-target.test.ts @@ -110,7 +110,7 @@ describe('scalable target', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { - Period: Match.absentProperty(), + Period: Match.absent(), }); Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { diff --git a/packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts b/packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts index 195bbdcd51794..1c6accc1d0c93 100644 --- a/packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts +++ b/packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts @@ -210,7 +210,7 @@ describe('SlackChannelConfiguration', () => { Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { Namespace: 'AWS/Chatbot', MetricName: 'MetricName', - Dimensions: Match.absentProperty(), + Dimensions: Match.absent(), ComparisonOperator: 'GreaterThanThreshold', EvaluationPeriods: 1, Threshold: 0, diff --git a/packages/@aws-cdk/aws-iam/test/permissions-boundary.test.ts b/packages/@aws-cdk/aws-iam/test/permissions-boundary.test.ts index a916cd53896eb..30ef748966b6c 100644 --- a/packages/@aws-cdk/aws-iam/test/permissions-boundary.test.ts +++ b/packages/@aws-cdk/aws-iam/test/permissions-boundary.test.ts @@ -149,11 +149,11 @@ test('unapply inherited boundary from a user: order 1', () => { // THEN // Template.fromStack(stack).hasResource('AWS::IAM::User', { - // PermissionsBoundary: Match.absentProperty(), + // PermissionsBoundary: Match.absent(), // }); // Correct after when this issue is fixed - https://github.com/aws/aws-cdk/issues/16626 Template.fromStack(stack).hasResource('AWS::IAM::User', { - Properties: Match.absentProperty(), + Properties: Match.absent(), }); }); @@ -167,10 +167,10 @@ test('unapply inherited boundary from a user: order 2', () => { // THEN // Template.fromStack(stack).hasResource('AWS::IAM::User', { - // PermissionsBoundary: Match.absentProperty(), + // PermissionsBoundary: Match.absent(), // }); // Correct after when this issue is fixed - https://github.com/aws/aws-cdk/issues/16626 Template.fromStack(stack).hasResource('AWS::IAM::User', { - Properties: Match.absentProperty(), + Properties: Match.absent(), }); }); 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 c826baf3aabfa..48d5aaca67bdd 100644 --- a/packages/@aws-cdk/aws-logs/test/log-retention.test.ts +++ b/packages/@aws-cdk/aws-logs/test/log-retention.test.ts @@ -105,7 +105,7 @@ describe('log retention', () => { }); Template.fromStack(stack).hasResourceProperties('Custom::LogRetention', { - RetentionInDays: Match.absentProperty(), + RetentionInDays: Match.absent(), }); From bcb88c540e695cd4c723da2e628d717f46123ce7 Mon Sep 17 00:00:00 2001 From: kaizen3031593 Date: Tue, 5 Oct 2021 09:55:14 -0400 Subject: [PATCH 9/9] absentProperty to absent --- packages/@aws-cdk/aws-ivs/test/ivs.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-ivs/test/ivs.test.ts b/packages/@aws-cdk/aws-ivs/test/ivs.test.ts index 6e4cd765576e4..4104994ed882c 100644 --- a/packages/@aws-cdk/aws-ivs/test/ivs.test.ts +++ b/packages/@aws-cdk/aws-ivs/test/ivs.test.ts @@ -23,7 +23,7 @@ test('channel default properties', () => { new ivs.Channel(stack, 'Channel'); Template.fromStack(stack).hasResource('AWS::IVS::Channel', { - Properties: Match.absentProperty(), + Properties: Match.absent(), }); });