-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(assertions): Capture captures value from last resource with matching type, not matched props #17009
Comments
This is interesting. The Can you switch to using the |
@nija-at As the way how the template is being processed does not differ between the The same issue exists as well when using test('captures values from matched resources', () => {
const stack = new Stack();
new CfnResource(stack, 'res1', { type: 'res', properties: { Name: 'foo', fred: 'waldo' } });
new CfnResource(stack, 'res2', { type: 'res', properties: { Name: 'bar', fred: 'fred' } });
const inspect = Template.fromStack(stack);
const capture = new Capture();
inspect.hasResource('res', { Properties: { Name: 'foo', fred: capture } });
expect(capture.asString()).toEqual('waldo');
}); You can simply disable my fix in if (false && Object.keys(section).length > Object.keys(matching).length) { Running a test with
Well my fix is quiet simple as it tests the |
Got it. Thanks for the update @poWer4aiX |
Originally posted by @nija-at in #17012 (review) First, we need to decide what is the correct behaviour if (1) return all of them in a series such as captured.asString(); // "Foo"
captured.next().asString(); // "Bar"
... or In either case, the solution should be in the |
There are three major changes around the capture feature of assertions. Firstly, when there are multiple targets (say, Resource in the CloudFormation template) that matches the given condition, any `Capture` defined in the condition will contain only the last matched resource. Convert the `Capture` class into an iterable so all matching values can be retrieved. Secondly, add support to allow sub-patterns to be specified to the `Capture` class. This allows further conditions be specified, via Matchers or literals, when a value is to be captured. Finally, this fixes a bug with the current implementation where `Capture` contains the results of the last matched section, irrespective of whether that section matched with the rest of the matcher or not. fixes #17009 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
There are three major changes around the capture feature of assertions. Firstly, when there are multiple targets (say, Resource in the CloudFormation template) that matches the given condition, any `Capture` defined in the condition will contain only the last matched resource. Convert the `Capture` class into an iterable so all matching values can be retrieved. Secondly, add support to allow sub-patterns to be specified to the `Capture` class. This allows further conditions be specified, via Matchers or literals, when a value is to be captured. Finally, this fixes a bug with the current implementation where `Capture` contains the results of the last matched section, irrespective of whether that section matched with the rest of the matcher or not. fixes aws#17009 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
What is the problem?
I used
Template.findResources()
to filter for one resource in a stack, by type and value of theName
tag. For one property I used aCapture()
. My expectation was that the captured value will be the one of the resource found, which was not the case. Instead, it was the value from the resource in the stack matching just the given type.Reproduction Steps
What did you expect to happen?
The captured value should be the value from the last resource being filtered (i.e. by type and optional attributes). In the example code given above this should be 1 instead of 2.
What actually happened?
The captured value is the one of the attribute from the last resource of the resource type, independent if this one matched or not.
CDK CLI Version
1.128.0
Framework Version
1.128.0
Node.js Version
14.17.4
OS
Ubuntu 20.04, running in an WSL on Windows 10
Language
Typescript
Language Version
3.9.7
Other information
No response
The text was updated successfully, but these errors were encountered: