用于检查资源标签的 Clarity Terraform 测试

Clarity Terraform testing for checking resource tags

我是净度测试工具的新手。我想知道是否可以使用 clarity 来检查 AWS 资源中是否添加了标签。

我为如下标签编写了清晰度测试:

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  |

但是我得到以下错误:

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)
}

此处的任何建议都会有所帮助。

此致,

TechGirl

令人遗憾的是,关于清晰度的文档非常少,而且它没有提到如何为类型映射属性中的条目编写匹配器。 clarity自己的test suite中也没有这种匹配器的例子。

我找不到具体的答案,但这可能有效(调整你的匹配器以匹配标签名称的存在):

Then attribute "tags.<tag-key>" exists