Add fluent HTTP response assertions#3
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
*http.Responsevalues to improve ergonomics and chaining while preserving backwards compatibility with existing package-level functions.Respwrapper for method-style assertions and ensure graceful behavior for nil receivers.Description
Response(resp *http.Response) *Respand theRespwrapper type with anactual *http.Responsefield tohammy/httpassert/httpassert.go.Status,StatusInRange,Header,HeaderContains,BodyEqual,BodyContains, andBodyMatchesRegexpon*Respand delegate the existing package-level functions to these methods for compatibility.response()helper on*Respto handle nil-receiver cases safely, and reuse the existingreadBodyhelper to preserve body restoration behavior.hammy/httpassert/httpassert_test.gothat cover fluent success scenarios and nil-receiver handling for*Resp.Testing
go test ./hammy/httpassertand the package tests passed successfully.timeout 60s go test ./...and the full test suite completed successfully (all automated tests passed).Codex Task