From 9f7288712de6b904640dca9fd2ea04c30c4ffcac Mon Sep 17 00:00:00 2001 From: Ivan Velasco Date: Mon, 2 Sep 2024 14:37:51 -0600 Subject: [PATCH] process: test case and suite `totalSteps` variables added to address https://github.com/ovh/venom/issues/808 Signed-off-by: Ivan Velasco --- process_testcase.go | 6 +++++- process_testsuite.go | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/process_testcase.go b/process_testcase.go index e7fa0a78..3b04ba45 100644 --- a/process_testcase.go +++ b/process_testcase.go @@ -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) @@ -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) diff --git a/process_testsuite.go b/process_testsuite.go index 0b9c9267..6aad767f 100644 --- a/process_testsuite.go +++ b/process_testsuite.go @@ -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 { @@ -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)