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

fix(#21): support non-json body types #23

Merged
merged 1 commit into from Jul 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions implementation/verifier/verifier.go
Expand Up @@ -113,9 +113,27 @@ func (c *VerifierImpl) Perform(ctx context.Context, method string, requestUrl st
response.Status = mockResponse.Status
response.Time = mockResponse.Time
if response.Body != nil && mockResponse.Body != nil {
// copy over through json round trip
marshalled, _ := json.Marshal(mockResponse.Body)
_ = json.Unmarshal(marshalled, response.Body)
switch response.Body.(type) {
case **[]byte:
if asString, ok := mockResponse.Body.(string); ok {
// allow strings containing anything
asBytes := []byte(asString)
*(response.Body.(**[]byte)) = &asBytes
} else {
// if given a structure, marshal to json and return that
marshalled, _ := json.Marshal(mockResponse.Body)
*(response.Body.(**[]byte)) = &marshalled
}
default:
if asString, ok := mockResponse.Body.(string); ok {
// allow strings containing a json doc
_ = json.Unmarshal([]byte(asString), response.Body)
} else {
// copy over through json round trip
marshalled, _ := json.Marshal(mockResponse.Body)
_ = json.Unmarshal(marshalled, response.Body)
}
}
}

return nil
Expand Down