From dc71f1021958623410ecc50ab5b0f80fdd040700 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 30 Sep 2021 15:00:51 +0800 Subject: [PATCH] fix: extract variables --- response.go | 5 +++-- runner.go | 5 ++++- step.go | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/response.go b/response.go index fd36ded2..bcd18d10 100644 --- a/response.go +++ b/response.go @@ -87,10 +87,11 @@ func (v *ResponseObject) Extract(extractors map[string]string) map[string]interf extractMapping := make(map[string]interface{}) for key, value := range extractors { - extractMapping[key] = v.searchJmespath(value) + extractedValue := v.searchJmespath(value) + log.Printf("extract %s => %v", value, extractedValue) + extractMapping[key] = extractedValue } - log.Printf("[Extract] extractMapping: %v", extractMapping) return extractMapping } diff --git a/runner.go b/runner.go index 4677e0cd..809fb0d1 100644 --- a/runner.go +++ b/runner.go @@ -140,8 +140,11 @@ func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) { extractMapping := respObj.Extract(extractors) stepData.ExportVars = extractMapping + // override step variables with extracted variables + stepVariables := mergeVariables(step.Variables, extractMapping) + // validate response - err = respObj.Validate(step.Validators, step.Variables) + err = respObj.Validate(step.Validators, stepVariables) if err != nil { return } diff --git a/step.go b/step.go index e5920b50..b4bbd021 100644 --- a/step.go +++ b/step.go @@ -170,6 +170,7 @@ func (s *requestWithOptionalArgs) Validate() *stepRequestValidation { } func (s *requestWithOptionalArgs) Extract() *stepRequestExtraction { + s.step.Extract = make(map[string]string) return &stepRequestExtraction{ step: s.step, }