-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(assertions):
hasResourceProperties
is incompatible with `Match.…
…not` and `Match.absent` (#16678) Fixes #16626. This PR modifies `hasResourceProperties()` so that it accounts for the special case where `Properties` does not exist on the template. The following assertions previously behaved incorrectly when `Properties` were not in the template and are now fixed: ```ts template.fromStack(stack); // some template with no `Properties`. // assert that `Properties` does not exist in the template. Returns true. template.hasResourceProperties('Foo::Bar', Match.absent()); // assert that `baz` is not a `Property` of 'Foo::Bar'. Returns true. template.hasResourceProperties('Foo::Bar', { baz: Match.absent(), }; // assert that `baz` does not have a value of `qux` in the `Properties` object. Returns true. template.hasResourceProperties('Foo::Bar', Match.not({baz: 'qux'}); ``` It also moves `AbsentMatch` into the `private` folder so that it can be exposed internally as a special case for `hasResourceProperties()`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
5 changed files
with
85 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/@aws-cdk/assertions/lib/private/matchers/absent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Matcher, MatchResult } from '../../matcher'; | ||
|
||
export 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters