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: dump body directly if json indent fails #643

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion humatest/humatest.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@
}
body.Close()
if strings.Contains(buf.String(), "json") {
json.Indent(buf, b, "", " ")
if err := json.Indent(buf, b, "", " "); err != nil {
// Indent failed, so just write the buffer.
buf.Write(b)
}

Check warning on line 351 in humatest/humatest.go

View check run for this annotation

Codecov / codecov/patch

humatest/humatest.go#L349-L351

Added lines #L349 - L351 were not covered by tests
Comment on lines +348 to +351
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding test coverage for the error path.

The new error handling code is currently not covered by tests. Consider adding test cases for:

  1. Invalid JSON that fails indentation
  2. Malformed JSON with special characters

Would you like me to help generate test cases for these scenarios?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 349-351: humatest/humatest.go#L349-L351
Added lines #L349 - L351 were not covered by tests

} else {
buf.Write(b)
}
Expand Down
Loading