Тестирование Clarity Terraform для проверки тегов ресурсов - PullRequest
2 голосов
/ 19 июня 2020

Я новичок в инструменте проверки ясности. Я хотел знать, можно ли использовать ясность, чтобы проверить, добавлены ли теги к ресурсам 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

1 Ответ

1 голос
/ 20 июня 2020

Документация по ясности, к сожалению, довольно минимальна, и в ней ничего не упоминается о том, как написать сопоставление для записей в атрибуте type map. Также нет примеров в собственном наборе тестов ясности для этого типа сопоставления. ):

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