Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/improve junit output #772

Merged
merged 13 commits into from
Mar 28, 2024
Merged
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)
}