Skip to content

Add HTTP request assertion helpers and unit tests#7

Merged
nfisher merged 1 commit into
mainfrom
codex/create-request-assertion-wrapper
Jun 16, 2026
Merged

Add HTTP request assertion helpers and unit tests#7
nfisher merged 1 commit into
mainfrom
codex/create-request-assertion-wrapper

Conversation

@nfisher

@nfisher nfisher commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Motivation

  • Provide a set of test helpers to assert properties of http.Request values for use with the hammy assertion framework.
  • Make it easy to assert method, path, full URL, host, headers, query params and request body content in tests while safely handling nils and restoring the request body after reads.

Description

  • Add hammy/httpassert/request.go which exposes Request(req *http.Request) *Req and assertion methods Method, Path, URL, URLEqual, Host, Header, HeaderContains, QueryParam, BodyEqual, and BodyContains that return hammy.AssertionMessage and validate nil inputs.
  • Implement readRequestBody to read the request body, return it as a string, handle read errors, and restore req.Body so assertions are non-destructive.
  • Add comprehensive tests in hammy/httpassert/request_test.go covering success and failure scenarios for each assertion, behavior when the request or URL is nil, and error handling when reading the request body fails.
  • Use the eye.Spy test spy to assert error messages produced by failing assertions.

Testing

  • Ran the package unit tests with go test ./hammy/httpassert -v, which executed the new request_test.go tests and completed successfully.
  • Tests cover positive and negative cases for each assertion and verify that the request body is restored after assertions and that read errors are reported.

Codex Task

@nfisher nfisher merged commit 75076d3 into main Jun 16, 2026
1 check passed
@nfisher nfisher deleted the codex/create-request-assertion-wrapper branch June 16, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant