-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(assertions): findXxx() APIs now includes the logical id as part of its result #16454
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The breaking change entries needs to be fixed -
the
findOutputs()
API previously returned a list of resources, but now returns a map of logical id to resource
"the findOutputs()
API previously returned a list of outputs, but now returns a map of logical id to output"
The other breaking change entry also needs to be fixed.
findXxx()
APIs return map of logicalId
to xxx
findXxx()
APIs return map of logicalId
to xxx
Thanks for the review @nija-at, I'm ready for another pass. Sorry about the continued copy/paste mishaps in the PR description... there should be no more. Build failure has nothing to do with me (I don't think), anything I can do to get it to build correctly? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one comment about return type when no matches.
The rest look good.
@@ -101,7 +101,7 @@ export class Template { | |||
* When a literal is provided, performs a partial match via `Match.objectLike()`. | |||
* Use the `Match` APIs to configure a different behaviour. | |||
*/ | |||
public findResources(type: string, props: any = {}): { [key: string]: any }[] { | |||
public findResources(type: string, props: any = {}): { [key: string]: { [key: string]: any } } { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, I missed this in the last revision. We should be returning undefined
here when there are no matches, not an empty object.
That would make the user experience better. Users can do -
const result = template.find...(...);
if (result !== undefined) {
// do something
}
With what we have today, it'll be
const result = template.find...(...);
if (Object.keys(result).length > 0) {
// do something
}
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this in principle but it will mean that since result
can be undefined
, something like expect(result.Foo).toEqual({})
becomes expect(result!.Foo).toEqual({})
. I could be wrong but forcing users to use the !
escape or otherwise dealing with the possibility of undefined
might not make the user experience better.
WDYT, @nija-at? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's go with what you have now. It might actually be the better way.
expect(Template.fromStack(stack).findResources('AWS::ApiGatewayV2::VpcLink', { | ||
expect(Object.keys(Template.fromStack(stack).findResources('AWS::ApiGatewayV2::VpcLink', { | ||
Name: 'Link-2', | ||
}).length).toEqual(0); | ||
})).length).toEqual(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I mean.
Would be nicer if we can do -
expect(Template.fromStack(stack).findResources('AWS::ApiGatewayV2::VpcLink', {
Name: 'Link-2',
})).toBeUndefined();
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
The current return type of
findResources()
,findOutputs()
, andfindMappings()
omits thelogicalId
. This creates ambiguity because it is not trivial to figure out which resource/output/mapping is being matched. For example,Could return a list like:
This does not provide information on which output(s) are being matched to the
Value: 'Fred'
property. Under the new return type proposed in this PR, the output would look like this:Returning the
logicalId
in this way for allfind*()
APIs will provide the full picture back to the user.BREAKING CHANGE: the
findResources()
API previously returned a list of resources, but now returns a map of logical id to resource.findOutputs()
API previously returned a list of outputs, but now returns a map of logical id to output.findMappings()
API previously returned a list of mappings, but now returns a map of logical id to mapping.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license