-
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(assert): more powerful matchers #8444
Conversation
In order to write better assertions on complex resource structs that only test what we're interested in (and not properties that may accidentally change as part of unrelated refactors), add more powerful matchers that can express things like: - `objectLike()` - `arrayContaining()` - `stringContaining()` (not implemented by default but easy to add now) We can now write: ```ts expect(stack).toHaveResourceLike('AWS::S3::BucketPolicy', { PolicyDocument: { Statement: arrayContaining(objectLike({ Action: arrayContaining('s3:GetObject*', 's3:GetBucket*', 's3:List*'), Principal: { AWS: { 'Fn::Sub': stringContaining('-deploy-role-') } } })) } }); ``` And be invariant to things like the order of elements in the arrays, and default role name qualifiers. Refactor the old assertions to be epxressed in terms of the new matchers. NOTE: Matchers are now functions, which won't translate into jsii in the future. It will be easy enough to make them single-method objects in the future when we move this library (or a similar one to jsii). For now, I did not want to let that impact the design.
Considering a rename of |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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). |
In order to write better assertions on complex resource structs that
only test what we're interested in (and not properties that may
accidentally change as part of unrelated refactors), add more powerful
matchers that can express things like:
objectLike()
arrayWith()
stringContaining()
(not implemented by default but easy to add now)We can now write:
And be invariant to things like the order of elements in the arrays,
and default role name qualifiers.
Refactor the old assertions to be epxressed in terms of the new
matchers.
NOTE: Matchers are now functions, which won't translate into
jsii in the future. It will be easy enough to make them single-method
objects in the future when we move this library (or a similar
one to jsii). For now, I did not want to let that impact the design.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license