aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.66k stars 3.92k forks source link

(assertions): Annotations should support `hasNoXxx()` APIs #18874

Closed fitzoh closed 2 years ago

fitzoh commented 2 years ago

Description

Add has_no_error, has_no_warning, and has_no_info methods to the Annotations assertions toolkit.

Use Case

I'm testing some EC2 constructs and lettings users pass in block volumes, adding errors if any volumes are unencrypted.

The test for something that produces an error is easy:

Annotations.from_stack(stack).has_error("*", "unencrypted volume /dev/sda1")

The test for a value that doesn't produce an error is awkward:

    errors = Annotations.from_stack(stack).find_error(
        "*", Match.string_like_regexp(".*")
    )
    assert not errors

I would like to easily assert that there are no errors in the stack

Proposed Solution

Add a has_no_error method next to the has_error and find_error methods (as well as info and warning variants).

Other information

No response

Acknowledge

kaizencc commented 2 years ago

This would be helpful. I agree the workaround is a bit awkward.

github-actions[bot] commented 2 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.