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: test case and test suite totalSteps built-in variables added #812

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ testcases:
- name: testA
steps:
- type: exec
script: echo '{{.venom.testsuite}} {{.venom.testsuite.filename}} {{.venom.testcase}} {{.venom.teststep.number}} {{.venom.datetime}} {{.venom.timestamp}}'
# will display something as: MyTestSuite MyTestSuiteWithVenomBuiltinVar.yml testA 0 2018-08-05T21:38:24+02:00 1533497904
script: echo '{{.venom.testsuite}} {{.venom.testsuite.filename}} {{.venom.testcase}} {{.venom.teststep.number}} {{.venom.datetime}} {{.venom.timestamp}} {{.venom.testcase.totalSteps}} {{.venom.testsuite.totalSteps}}'
# will display something as: MyTestSuite MyTestSuiteWithVenomBuiltinVar.yml testA 0 2018-08-05T21:38:24+02:00 1533497904 3 5

```

Expand All @@ -585,13 +585,15 @@ Builtin variables:
* {{.venom.libdir}}
* {{.venom.outputdir}}
* {{.venom.testcase}}
* {{.venom.testcase.totalSteps}}
* {{.venom.teststep.number}}
* {{.venom.testsuite.name}}
* {{.venom.testsuite.filename}}
* {{.venom.testsuite.filepath}}
* {{.venom.testsuite.shortName}}
* {{.venom.testsuite.workdir}}
* {{.venom.testsuite}}
* {{.venom.testsuite.totalSteps}}
* {{.venom.timestamp}}


Expand Down
6 changes: 5 additions & 1 deletion process_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (v *Venom) runTestCase(ctx context.Context, ts *TestSuite, tc *TestCase) {
tc.Vars = ts.Vars.Clone()
tc.Vars.Add("venom.testcase", tc.Name)
tc.Vars.AddAll(ts.ComputedVars)
tc.Vars.Add("venom.testcase.totalSteps", len(tc.RawTestSteps))
tc.computedVars = H{}

ctx = v.processSecrets(ctx, ts, tc)
Expand Down Expand Up @@ -185,10 +186,13 @@ func (v *Venom) runTestSteps(ctx context.Context, tc *TestCase, tsIn *TestStepRe
fromUserExecutor := tsIn != nil

loopRawTestSteps:
for stepNumber, rawStep := range tc.RawTestSteps {
for stepIndex, rawStep := range tc.RawTestSteps {
stepVars := tc.Vars.Clone()
stepVars.AddAll(previousStepVars)
stepVars.AddAllWithPrefix(tc.Name, tc.computedVars)

// Use stepNumber as a 1-based index
stepNumber := stepIndex + 1
stepVars.Add("venom.teststep.number", stepNumber)

ranged, err := parseRanged(ctx, rawStep, stepVars)
Expand Down
5 changes: 3 additions & 2 deletions process_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ func (v *Venom) runTestSuite(ctx context.Context, ts *TestSuite) error {

totalSteps := 0
for _, tc := range ts.TestCases {
totalSteps += len(tc.testSteps)
totalSteps += len(tc.RawTestSteps)
}

ts.Vars.Add(("venom.testsuite.totalSteps"), totalSteps)
ts.Status = StatusRun
Info(ctx, "With secrets in testsuite")
for _, v := range ts.Secrets {
Expand Down Expand Up @@ -218,7 +219,7 @@ func (v *Venom) parseTestCases(ts *TestSuite) ([]string, []string, error) {
for i := range ts.TestCases {
tc := &ts.TestCases[i]
tc.originalName = tc.Name
tc.number = i
tc.number = i + 1
tc.Name = slug.Make(tc.Name)
tc.Vars = ts.Vars.Clone()
tc.Vars.Add("venom.testcase", tc.Name)
Expand Down