Documentation
¶
Overview ¶
Package httpmock provides a mock HTTP RoundTripper for testing purposes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RoundTrip ¶
type RoundTrip struct {
RequestCheck RoundTripRequestCheck
Response RoundTripResponse
}
RoundTrip defines the behavior for a single HTTP response in the sequence.
type RoundTripRequestCheck ¶
RoundTripRequestCheck defines a function type for checking HTTP requests.
func ChainRoundTripRequestChecks ¶
func ChainRoundTripRequestChecks(checks ...RoundTripRequestCheck) RoundTripRequestCheck
ChainRoundTripRequestChecks chains multiple RoundTripRequestCheck functions into a single RoundTripRequestCheck.
func RoundTripRequestCheckJSON ¶
func RoundTripRequestCheckJSON[T any](checkFn func(t *testing.T, data T)) RoundTripRequestCheck
RoundTripRequestCheckJSON creates a RoundTripRequestCheck that parses the request body as JSON into the specified type T and applies the provided check function.
type RoundTripResponse ¶
type RoundTripResponse struct {
Status int
Headers map[string]string
Body []byte
// Error allows simulating a network error (RoundTrip returns error)
Error error
}
RoundTripResponse defines the components of an HTTP response.
type RoundTripper ¶
type RoundTripper struct {
// contains filtered or unexported fields
}
RoundTripper is a simplistic http.RoundTripper that serves a pre-defined sequence of responses.
func NewRoundTripper ¶
func NewRoundTripper(t *testing.T, resps []RoundTrip) *RoundTripper
NewRoundTripper creates a new RoundTripper.