I am new to clarity test tool. I wanted to know whether clarity can be used to check whether tags are added to AWS resources or not.
I wrote the clarity test for tags like below:
Scenario: EC2 should have tag "application"
Given Terraform
And a "aws_instance" of type "resource"
And "our component is <tag-key>"
When attribute "tags" exists
Then attribute "tags" matches regex "tags.*<tag-key>*"
Examples:
| tag-key |
| Name |
| application |
But I got below error:
Feature: EC2 should have encrypted EBS volume attached
Scenario: EC2 should have tag "application" # main.feature:3
Given Terraform # terraform.go:92 -> *Match
And a "aws_instance" of type "resource" # terraform.go:279 -> *Match
And "our component is <tag-key>" # clarity_test.go:49 -> noopComment
Then attribute "tags" exists # terraform.go:304 -> *Match
Then attribute "tags" matches regex "<tag-key>"
Examples:
| tag-key |
| Name |
| application |
2 scenarios (2 undefined)
10 steps (8 passed, 2 undefined)
1.849441ms
You can implement step definitions for undefined steps with these snippets:
func attributeMatchesRegex(arg1, arg2 string) error {
return godog.ErrPending
}
func FeatureContext(s *godog.Suite) {
s.Step(`^attribute "([^"]*)" matches regex "([^"]*)"$`, attributeMatchesRegex)
}
Any suggestions here would be helpful.
Regards,
TechGirl
The documentation on clarity is pretty minimal regrettably and it mentions nothing about how to write a matcher for entries in an attribute of type map. There are also no examples in clarity's own test suite for this kind of matcher.
I could not find a concrete answer to this, but this might work (adjusting your matcher to match the existence of a tag by its name):
Then attribute "tags.<tag-key>" exists