fix: extract variables

This commit is contained in:
debugtalk
2021-09-30 15:00:51 +08:00
parent a3543215dc
commit 9304a4e839
3 changed files with 8 additions and 3 deletions

View File

@@ -87,10 +87,11 @@ func (v *ResponseObject) Extract(extractors map[string]string) map[string]interf
extractMapping := make(map[string]interface{}) extractMapping := make(map[string]interface{})
for key, value := range extractors { 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 return extractMapping
} }

View File

@@ -140,8 +140,11 @@ func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) {
extractMapping := respObj.Extract(extractors) extractMapping := respObj.Extract(extractors)
stepData.ExportVars = extractMapping stepData.ExportVars = extractMapping
// override step variables with extracted variables
stepVariables := mergeVariables(step.Variables, extractMapping)
// validate response // validate response
err = respObj.Validate(step.Validators, step.Variables) err = respObj.Validate(step.Validators, stepVariables)
if err != nil { if err != nil {
return return
} }

View File

@@ -170,6 +170,7 @@ func (s *requestWithOptionalArgs) Validate() *stepRequestValidation {
} }
func (s *requestWithOptionalArgs) Extract() *stepRequestExtraction { func (s *requestWithOptionalArgs) Extract() *stepRequestExtraction {
s.step.Extract = make(map[string]string)
return &stepRequestExtraction{ return &stepRequestExtraction{
step: s.step, step: s.step,
} }