Documentation
¶
Overview ¶
Package httpmock is an http.RoundTripper test double for stubbing outbound HTTP in unit tests, keeping them off the live network with NO test-only seam in production code. It mirrors cli/cli's pkg/httpmock pattern: a Registry implements http.RoundTripper and matches each request against registered stubs. Callers inject Registry.Client() wherever production code accepts an *http.Client (e.g. the Factory's HttpClient noun), so the request URL is the real one — the transport, not a swapped URL, is the seam.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Registry ¶
Registry is an http.RoundTripper test double. Register stubs in the order you expect requests; each request is matched against stubs in registration order and served by the first match. Every request is recorded (Requests) for assertions, and an unmatched request returns an error — so a test that makes an unexpected call fails loudly instead of reaching the network.
func (*Registry) Client ¶
Client returns an *http.Client whose Transport is this registry — pass it wherever production code wants an *http.Client.
type Responder ¶
Responder produces the response (or error) for a matched request.
func JSONResponse ¶
JSONResponse is a 200 whose body is the JSON encoding of v.
func StatusJSONResponse ¶
StatusJSONResponse responds with status and the JSON encoding of v.
func StatusStringResponse ¶
StatusStringResponse responds with status and a raw string body.
func StringResponse ¶
StringResponse is a 200 with a raw string body.