question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(assert): matchTemplate with superset matchstyle does not consider output section

See original GitHub issue

Reproduction 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
nija-atcommented, Mar 19, 2021

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.

0reactions
github-actions[bot]commented, Jun 17, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found