(assert): matchTemplate with superset matchstyle does not consider output section
See original GitHub issueReproduction Steps
Have a simple test that matches if a stack is a superset of an empty object:
test('Empty Stack', () => {
const app = new cdk.App();
// WHEN
const stack = new Test.TestStack(app, 'MyTestStack');
// THEN
expectCDK(stack).to(matchTemplate({
"Resources": { }
}, MatchStyle.SUPERSET))
});
and a simple Stack with an ApiGateway:
export class TestStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const api = new apigateway.RestApi(this, 'books-api');
api.root.addMethod('ANY');
}
}
What did you expect to happen?
The simple test should pass as it does with other stacks that include for example sns topics, sqs queues, DynamoDBs.
What actually happened?
The test fails:
Template comparison produced unacceptable match
8 | const stack = new Test.TestStack(app, 'MyTestStack');
9 | // THEN
> 10 | expectCDK(stack).to(matchTemplate({
| ^
11 | "Resources": {
at StackMatchesTemplateAssertion.assertOrThrow (node_modules/@aws-cdk/assert/lib/assertions/match-template.ts:38:13)
at StackInspector._to (node_modules/@aws-cdk/assert/lib/inspector.ts:25:15)
at StackInspector.to (node_modules/@aws-cdk/assert/lib/inspector.ts:15:14)
at Object.<anonymous> (test/test.test.ts:10:22)
Environment
- CDK CLI Version : 1.92.0 (build de536cc)
- Framework Version: 1.92.0
- Node.js Version: v14.15.4
- OS : Fedora 33
- Language (Version): TypeScript
Other
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Infrastructure Tests with CDK - kreuzwerker
This article gives an overview of the main testing functionalities provided by the AWS Cloud Development Kit (CDK) and shares some of our ......
Read more >@aws-cdk/assert - npm Package Health Analysis | Snyk
Learn more about @aws-cdk/assert: package health score, ... stack template looks like the given template, or is a superset of it.
Read more >aws-cdk/assertions module
This behavior can be configured using matchers. See subsequent section on special matchers. Output and Mapping sections. The module allows you to assert...
Read more >Understanding and evaluating template matching methods
I've read through and implemented code based on the tutorial, but other than understanding that one looks for minimum results for TM_SQDIFF for ......
Read more >Exploring AWS CDK - Step Functions - DEV Community
Continuing to search, I came across this article. This one is a pretty good tutorial that combines five lambda functions into a flow...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The code responsible for this is here - https://github.com/aws/aws-cdk/blob/ab2c48e05ca3e2edf04e21a41051a46a5061b2dc/packages/%40aws-cdk/assert/lib/assertions/match-template.ts#L80-L86
The logic seems to be that any change to the ‘Parameters’ or ‘Outputs’ sections should be considered a diff even if
MatchStyle.SUPERSET
is used. It’s not immediately clear why it’s configured like this.This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.