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

feat(tests): add range supports #453

Merged
merged 6 commits into from
Dec 3, 2021
Merged

feat(tests): add range supports #453

merged 6 commits into from
Dec 3, 2021

Conversation

lowlighter
Copy link
Member

@lowlighter lowlighter commented Nov 25, 2021

May close #263 and close #288

This add support for the range attribute that can be passed in a step context.
The following types along their contexted variables are supported:

  • []interface{}: an array of values
    • .index/.key: current iteration index
    • .value: current iteration item value
  • map[string]interface{}: a map of values (each key will be iterated over)
    • .index: current iteration index
    • .key: current iteration item key
    • .value: current iteration item value
  • int: an integer to perform action n times
    • .index/.key/.value: current iteration index
  • string: a templated string which results in one of the above typing
    • It can be either inherited from vars file, or interpolated from a previous step result

Within a range context, .range variable will be set to true (while it'll be false in "regular" contexts)

Here's an example (see tests/ranged.yml in this PR diff for more examples):

- name: range with harcoded array
  steps:
  - type: exec
    range:
      - actual: hello
        expected: hello
        index: 0
      - actual: world
        expected: world
        index: 1
    script: echo "{{.range}} {{.index}} {{.value.actual}}"
    assertions:
    - result.code ShouldEqual 0
    - result.systemout ShouldEqual "true {{.value.index}} {{.value.expected}}"

Image below show the content of Range struct for each test case:
image


I haven't run go fmt yet as it'll enclose the current step processing (L176 to L281) within the for which make the diff harder to review. If no further changes are requested, I'll run the formatter and add some documentation in the README.md with definitive syntax 🙂

@lowlighter lowlighter changed the title feat(tests): add loop supports feat(tests): add range supports Nov 26, 2021
Copy link
Member

@fsamin fsamin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.
Here are some feedback.

Can you also add a new section in the README ?

process_testcase.go Outdated Show resolved Hide resolved
process_testcase.go Show resolved Hide resolved
process_testcase.go Show resolved Hide resolved
process_testcase.go Show resolved Hide resolved
process_testcase.go Outdated Show resolved Hide resolved
process_testcase.go Outdated Show resolved Hide resolved
process_testcase.go Show resolved Hide resolved
process_testcase.go Outdated Show resolved Hide resolved
Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
@lowlighter
Copy link
Member Author

  • Applied feedback changes and rebased to fix conflict with feat(executors): expose previous steps result #452
  • Updated the README.md to add section about range expression
  • Also applied go fmt (which makes the diff harder to read because it changes the indents, can revert it temporarly for review if you want)

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Signed-off-by: GitHub <noreply@github.com>
@yesnault yesnault merged commit 24cc72f into ovh:master Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possibility to iterate over an array in a step feat: Running same test case for list of inputs
3 participants