Skip to content

Add httptest.ResponseRecorder assertions#2

Merged
nfisher merged 4 commits into
mainfrom
codex/add-wrapper-for-httptest.responserecorder
Jun 16, 2026
Merged

Add httptest.ResponseRecorder assertions#2
nfisher merged 4 commits into
mainfrom
codex/add-wrapper-for-httptest.responserecorder

Conversation

@nfisher

@nfisher nfisher commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Motivation

  • Provide a convenient wrapper around *httptest.ResponseRecorder so tests can assert recorded responses using the existing http.Response assertion helpers.

Description

  • Add Recorder(rec *httptest.ResponseRecorder) *RecorderAssert and the RecorderAssert type in hammy/httpassert/recorder.go with a pointer to the recorder.
  • Implement Status, StatusInRange, Header, HeaderContains, BodyEqual, BodyContains, and BodyMatchesRegexp on RecorderAssert by converting the recorder via Result() and delegating to the existing http.Response assertion functions.
  • Return clear failure messages for nil recorders and invalid input (e.g., invalid status range or invalid regexp patterns).
  • Add unit tests in hammy/httpassert/recorder_test.go that cover successful and failing assertions, nil recorder handling, invalid ranges, regexp failures, and body-read restoration behavior.

Testing

  • Ran go test ./... and all packages succeeded.

Codex Task

@nfisher nfisher merged commit 0027e0c into main Jun 16, 2026
1 check passed
@nfisher nfisher deleted the codex/add-wrapper-for-httptest.responserecorder branch June 16, 2026 20: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