Skip to content

Commit

Permalink
loop
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-touron committed Nov 19, 2021
1 parent a8a664b commit d6b3607
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
29 changes: 29 additions & 0 deletions rocktest/rocktest/scenario/loop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package scenario

func (module *Module) Loop(params map[string]interface{}, scenario *Scenario) error {

paramsEx, err := scenario.ExpandMap(params)
if err != nil {
return err
}

from, _ := scenario.GetNumber(paramsEx, "from", 0)
inc, _ := scenario.GetNumber(paramsEx, "inc", 1)
counter, _ := scenario.GetString(paramsEx, "counter", "i")
to, err := scenario.GetNumber(paramsEx, "to", nil)
if err != nil {
return err
}

steps, _ := scenario.GetList(params, "steps", nil)
if err != nil {
return err
}

for i := from; i < to; i += inc {
scenario.PutContext(counter, i)
scenario.RunSteps(steps)
}

return nil
}
9 changes: 9 additions & 0 deletions rocktest/rocktest/test/yaml/loop_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package yamlTest

import (
"testing"
)

func TestLoop1(t *testing.T) {
shouldPass(t, "loop/loop.yaml")
}
21 changes: 21 additions & 0 deletions rocktest/rocktest/test/yaml/scen/loop/loop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- title: Loop test

- var: concat = -

- loop:
params:
from: 0
to: 10
inc: 2
counter: i
steps:
- display: ${i}
- display: AVANT ${concat}
- var: concat = ${concat}${i}
- display: APRES ${concat}
- dump:

- assert.equals:
params:
expected: "-02468"
actual: ${concat}

0 comments on commit d6b3607

Please sign in to comment.