-
Notifications
You must be signed in to change notification settings - Fork 4k
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): add stack tagging assertions #29247
Conversation
Exemption Request As far as I can tell, the assertions library does not have integration tests, but I'm happy to be corrected. |
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 pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
Adds a Tag class to the assertions library that permits assertions against tags on synthesized CDK stacks.
This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week. |
Hey @jamestelfer, I'm taking a look. This functionality looks terrific! I think we can write some integ tests, but probably in @aws-cdk-testing/framework-integ. I need to check out how the |
@Mergifyio update |
❌ Mergify doesn't have permission to updateFor security reasons, Mergify can't update this pull request. Try updating locally. |
@jamestelfer turns out |
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
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.
@jamestelfer, thanks so much for this contribution! I really appreciate your detailed thought process in the PR description, and I think you settled on the best API.
Also thanks for bringing up testing for no tags. I agree its a little odd that Match.absent()
does not work well. I have a couple ideas on getting around this.
- Is there a way to see what type of Match statement is passed into
hasValues()
? If so could you check forMatch.absent
and substituteMatch.objectEquals({})
? - We could add a
Tags.none()
orTags.hasNone()
method that gives the result ofTags.hasValues(Match.objectEquals({}))
.
I would lean towards option 2 with hasNone()
, but let me know what you think.
Last comment, I think it would be good to add some unit tests where there are multiple tags on the stack. That way we can see how hasValues()
and all()
interact with more than just the one key value pair.
Review feedback Co-authored-by: Parker Scanlon <69879391+scanlonp@users.noreply.github.com>
@scanlonp thanks for your thoughtful review and commentary! I'm going to make the following changes as a result:
|
Convenience method over `hasValues(Match.exact({}))`. Required as `Match.absent()` (the natural choice) will not act as the user expects.
… with the `absent` matcher Since the value is defaulted to `{}`, the absent matcher will not work as expected. We throw an error here instead of changing the Matcher under the covers. This ensures the API is transparent about the limitation, rather than covering it up.
😞 Rosetta doesn't like my doco updates. I'll come back around on this after easter. |
Improvements to allow Rosetta to test the documentation.
Bring doc up to scratch, removing copy-pasta and properly explaining usage intent.
I've updated the documentation with some better examples, and included some tests with more keys and more complicated matching. I did add a simple check on the matcher so there was a better error message to API consumers. I figured it was better to explicitly fail with a good message than switch the matcher transparently. It's ready for another look when you're ready @scanlonp! |
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.
Looks terrific. Tests look great, and the documentation is fantastic.
I like how you handled the hasNone()
and the transparent failing of Match.absent()
.
Again, appreciate the contribution! Excited for this to get used!
Thank you for contributing! Your pull request will be updated from main 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 main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Adds a
Tag
class to the assertions library that permits assertions against tags on synthesized CDK stacks.Tags on AWS resources can be checked via assertions with the Template class, but since stack tags only appear on the cloud assembly manifest as a sibling of the template, a separate assertion mechanism is required.
Note
Previously submitted as #27633, which was closed automatically while waiting for review.
This PR is complete to the best of my knowledge, needing only an exemption from integration tests. As far as I can tell, this area of the library has no integration tests directly associated.
API
Usage
This new class permits tests of the form:
You can also get the set of tags to test them in other ways:
Issues
No tags case
One might expect that the case where no tags are present would match
undefined
ornull
, but since the Cloud Assembly API defaults tags to{}
when none are present, this isn't possible. It's also not practical to directly test theartifact.manifest.properties.tags
value directly, as there is a legacy case that the API handles. This means that theartifact.tags
property is the best value to check against.The tests for this PR show that matching with
Match.absent()
will fail when there are no tags, but testing against the empty object will succeed.I think that this behaviour (defaulting to empty) will be OK, but potentially require a callout on the assertion method.
API method naming
The current suggested API went through some evolution, starting with:
But this stuttered, and
getTags()
wasn't compatible with Java.I considered:
and
... before settling on a mix of the two. I think the current iteration fits with the rest of the
assertions
API and makes sense by itself, but very open to changes.Closes #27620.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license