fix: extract variables

This commit is contained in:
debugtalk
2021-09-30 15:00:51 +08:00
parent a205ecbc48
commit dc71f10219
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{})
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
}

View File

@@ -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
}

View File

@@ -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,
}