Skip to content

Commit

Permalink
fix: run boomer test
Browse files Browse the repository at this point in the history
  • Loading branch information
debugtalk committed Nov 14, 2021
1 parent 16347d6 commit 4827ebf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
5 changes: 3 additions & 2 deletions boomer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ func (b *Boomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
Weight: testcase.Config.Weight,
Fn: func() {
config := &testcase.Config
extractedVariables := make(map[string]interface{})
for _, step := range testcase.TestSteps {
var err error
start := time.Now()
stepData, err := runner.runStep(step, config)
stepData, err := runner.runStep(step, config, extractedVariables)
elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond)

if err == nil {
boomer.RecordSuccess(step.Type(), step.Name(), elapsed, stepData.ResponseLength)
} else {
Expand Down
43 changes: 23 additions & 20 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,36 +91,33 @@ func (r *Runner) runCase(testcase *TestCase) error {
extractedVariables := make(map[string]interface{})

for _, step := range testcase.TestSteps {
// override variables
// step variables > extracted variables from previous steps
stepVariables := mergeVariables(step.ToStruct().Variables, extractedVariables)
// step variables > testcase config variables
stepVariables = mergeVariables(stepVariables, config.Variables)

// parse step variables
parsedVariables, err := parseVariables(stepVariables)
_, err := r.runStep(step, config, extractedVariables)
if err != nil {
log.Error().Interface("variables", config.Variables).Err(err).Msg("parse step variables failed")
return err
}
step.ToStruct().Variables = parsedVariables

stepData, err := r.runStep(step, config)
if err != nil {
return err
}
// update extracted variables
for k, v := range stepData.ExportVars {
extractedVariables[k] = v
}
}

log.Info().Str("testcase", config.Name).Msg("run testcase end")
return nil
}

func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err error) {
func (r *Runner) runStep(step IStep, config *TConfig, extractedVariables map[string]interface{}) (stepData *StepData, err error) {
log.Info().Str("step", step.Name()).Msg("run step start")

// override variables
// step variables > extracted variables from previous steps
stepVariables := mergeVariables(step.ToStruct().Variables, extractedVariables)
// step variables > testcase config variables
stepVariables = mergeVariables(stepVariables, config.Variables)

// parse step variables
parsedVariables, err := parseVariables(stepVariables)
if err != nil {
log.Error().Interface("variables", config.Variables).Err(err).Msg("parse step variables failed")
return
}
step.ToStruct().Variables = parsedVariables

if tc, ok := step.(*testcaseWithOptionalArgs); ok {
// run referenced testcase
log.Info().Str("testcase", tc.step.Name).Msg("run referenced testcase")
Expand All @@ -139,6 +136,12 @@ func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err e
return
}
}

// update extracted variables
for k, v := range stepData.ExportVars {
extractedVariables[k] = v
}

log.Info().
Str("step", step.Name()).
Bool("success", stepData.Success).
Expand Down
5 changes: 3 additions & 2 deletions step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ func TestRunRequestRun(t *testing.T) {
config := &TConfig{
BaseURL: "https://postman-echo.com",
}
extractedVariables := make(map[string]interface{})
runner := NewRunner(t).SetDebug(true)
if _, err := runner.runStep(stepGET, config); err != nil {
if _, err := runner.runStep(stepGET, config, extractedVariables); err != nil {
t.Fatalf("tStep.Run() error: %s", err)
}
if _, err := runner.runStep(stepPOSTData, config); err != nil {
if _, err := runner.runStep(stepPOSTData, config, extractedVariables); err != nil {
t.Fatalf("tStepPOSTData.Run() error: %s", err)
}
}

0 comments on commit 4827ebf

Please sign in to comment.