Skip to content

Commit

Permalink
change: add session variables
Browse files Browse the repository at this point in the history
  • Loading branch information
debugtalk committed Nov 15, 2021
1 parent 4827ebf commit f7efadf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
3 changes: 1 addition & 2 deletions boomer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ 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, extractedVariables)
stepData, err := runner.runStep(step, config)
elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond)
if err == nil {
boomer.RecordSuccess(step.Type(), step.Name(), elapsed, stepData.ResponseLength)
Expand Down
20 changes: 10 additions & 10 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ func NewRunner(t *testing.T) *Runner {
},
Timeout: 30 * time.Second,
},
sessionVariables: make(map[string]interface{}),
}
}

type Runner struct {
t *testing.T
debug bool
client *http.Client
t *testing.T
debug bool
client *http.Client
sessionVariables map[string]interface{}
}

func (r *Runner) SetDebug(debug bool) *Runner {
Expand Down Expand Up @@ -88,10 +90,8 @@ func (r *Runner) runCase(testcase *TestCase) error {

log.Info().Str("testcase", config.Name).Msg("run testcase start")

extractedVariables := make(map[string]interface{})

for _, step := range testcase.TestSteps {
_, err := r.runStep(step, config, extractedVariables)
_, err := r.runStep(step, config)
if err != nil {
return err
}
Expand All @@ -101,12 +101,12 @@ func (r *Runner) runCase(testcase *TestCase) error {
return nil
}

func (r *Runner) runStep(step IStep, config *TConfig, extractedVariables map[string]interface{}) (stepData *StepData, err error) {
func (r *Runner) runStep(step IStep, config *TConfig) (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 > session variables (extracted variables from previous steps)
stepVariables := mergeVariables(step.ToStruct().Variables, r.sessionVariables)
// step variables > testcase config variables
stepVariables = mergeVariables(stepVariables, config.Variables)

Expand Down Expand Up @@ -139,7 +139,7 @@ func (r *Runner) runStep(step IStep, config *TConfig, extractedVariables map[str

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

log.Info().
Expand Down
5 changes: 2 additions & 3 deletions step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ 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, extractedVariables); err != nil {
if _, err := runner.runStep(stepGET, config); err != nil {
t.Fatalf("tStep.Run() error: %s", err)
}
if _, err := runner.runStep(stepPOSTData, config, extractedVariables); err != nil {
if _, err := runner.runStep(stepPOSTData, config); err != nil {
t.Fatalf("tStepPOSTData.Run() error: %s", err)
}
}

0 comments on commit f7efadf

Please sign in to comment.