Skip to content

Commit

Permalink
feat(executor/http): result info new format and consolidated routine …
Browse files Browse the repository at this point in the history
…into one function (#772)

Signed-off-by: Ivan Velasco <[email protected]>
  • Loading branch information
ivan-velasco authored Mar 28, 2024
1 parent a6549bb commit 7a851d9
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions executors/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,7 @@ func (Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, erro
}
}

if result.BodyJSON != nil {
// Convert the map to a JSON string
jsonString, err := json.Marshal(result.BodyJSON)
if err != nil {
return nil, err
}
result.Systemout = fmt.Sprintf("%s-----%s----->%s ", resp.Request.Method, resp.Request.URL, string(jsonString))
} else {
result.Systemout = fmt.Sprintf("%s-----%s----->%s ", resp.Request.Method, resp.Request.URL, result.Body)
}
result.Systemout = buildResultInfo(&result, resp)
}
}

Expand Down Expand Up @@ -488,3 +479,25 @@ func (e Executor) TLSOptions(ctx context.Context) ([]func(*http.Transport) error

return opts, nil
}

func buildResultInfo(result *Result, resp *http.Response) string {
var body string
if result.BodyJSON != nil {
jsonString, err := json.Marshal(result.BodyJSON)
if err != nil {
return fmt.Sprintf("Error marshaling JSON: %s", err.Error())
}
body = string(jsonString)
} else {
body = result.Body
}

return fmt.Sprintf(`===== Result Info =====
Method: %s
URL: %s
Body: %s
======================`,
resp.Request.Method,
resp.Request.URL,
body)
}

0 comments on commit 7a851d9

Please sign in to comment.