Skip to content
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

Scenario Outline does not support regex containing pipe character #110

Closed
anthonycolon25 opened this issue Jun 27, 2019 · 4 comments
Closed
Labels
bug on upstream The bug is not in terraform-compliance, but in an upstream dependency

Comments

@anthonycolon25
Copy link

anthonycolon25 commented Jun 27, 2019

This is a follow up to #96

There I asked if the following were possible:

  • Is there a way to check if a specific tag key (e.g. department) has one of a list of possible values (e.g. IT, Marketing, HR)? Kind of like a scenario outline

  • Is there a way to enforce a regex pattern on values assigned to a tag? Name definitely come to mind here?

  • Can we check that a tag is not empty?

You kindly provided the following example:

  Scenario: Ensure that specific tags are defined
    Given I have resource that supports tags defined
    When it contains tags
    Then its value must match the "(IT|Marketing|HR)" regex

If I extend the example a bit to the following I able able to deal with all my use cases above:

  Scenario: Ensure that Role tag is defined
    Given I have resource that supports tags defined
    When it contains tags
    Then it must contain role
    And its value must match the "^[a-z]+role" regex

  Scenario: Ensure that BusinessUnit tag is defined
    Given I have resource that supports tags defined
    When it contains tags
    Then it must contain BusinessUnit
    And its value must match the "^(IT|Marketing|HR)$" regex

The problem with this approach is that I would have to write basically the same scenario for each tag and regex. Not terrible but it would be better with a Scenario Outline.

I tried the following and it worked:

  Scenario Outline: Ensure that my specific tags are defined
    Given I have resource that supports tags defined
    When it contains tags
    Then it must contain <tag_keys>
    And its value must match the "<pattern>" regex

  Examples:
  | tag_keys     | pattern                     |
  | role         | ^[a-z]+role                 |

The following did not work however:

  Scenario Outline: Ensure that my specific tags are defined
    Given I have resource that supports tags defined
    When it contains tags
    Then it must contain <tag_keys>
    And its value must match the "<pattern>" regex

  Examples:
  | tag_keys        | pattern                 |
  | BusinessUnit    | ^(IT|Marketing|HR)$     |

It fails with the following error:

Error: Hook 'console_writer_after_each_scenario' from /usr/local/lib/python3.7/site-packages/radish/extensions/formatters/gherkin.py:425 raised: 'RadishError: Invalid colum_index to get column width for ScenarioOutline 'Ensure that my specific tags are defined''

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/radish/scenariooutline.py", line 125, in get_column_width
    max([len(x.data[column_index]) for x in self.examples]),
  File "/usr/local/lib/python3.7/site-packages/radish/scenariooutline.py", line 125, in <listcomp>
    max([len(x.data[column_index]) for x in self.examples]),
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/radish/hookregistry.py", line 132, in call
    func(model, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/radish/extensions/formatters/gherkin.py", line 467, in console_writer_after_each_scenario
    for i, x in enumerate(scenario.example.data)
  File "/usr/local/lib/python3.7/site-packages/radish/extensions/formatters/gherkin.py", line 467, in <genexpr>
    for i, x in enumerate(scenario.example.data)
  File "/usr/local/lib/python3.7/site-packages/radish/scenariooutline.py", line 131, in get_column_width
    self.sentence
radish.exceptions.RadishError: Invalid colum_index to get column width for ScenarioOutline 'Ensure that my specific tags are defined'

I believe it has to do with the pipe character but I am not sure.

Any chance support for this can get added?

@eerkunt
Copy link
Member

eerkunt commented Jun 28, 2019

Thanks for the finding! This time it is not about terraform-compliance but it is about Gherkin/Cucumber support on radish-bdd. Ideally we should be able to escape | character within Scenario Outlines by \|, but it look like it is also failing.

I will create an issue against radish-bdd

@eerkunt eerkunt added the bug on upstream The bug is not in terraform-compliance, but in an upstream dependency label Jun 28, 2019
@eerkunt
Copy link
Member

eerkunt commented Jun 28, 2019

Using | within the Scenarios (by escaping them like \| is introduced on radish-bdd/radish#351 and also incorporated on terraform-compliance 1.0.13. Could you please have a try ?

Thanks!

@eerkunt eerkunt added the waiting for confirmation Workaround/Fix applied, waiting for confirmation label Jun 28, 2019
@anthonycolon25
Copy link
Author

Just tested 1.0.13. Escaping the pipe character for a regex in a scenario outline works now.

So much nicer than having to write multiple scenarios for each tag!

Thank you!

@eerkunt
Copy link
Member

eerkunt commented Jun 28, 2019

Thanks for testing!

@eerkunt eerkunt closed this as completed Jun 28, 2019
@eerkunt eerkunt removed the waiting for confirmation Workaround/Fix applied, waiting for confirmation label Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug on upstream The bug is not in terraform-compliance, but in an upstream dependency
Projects
None yet
Development

No branches or pull requests

2 participants