Documentation
¶
Overview ¶
Package httpclient supplies deterministic outbound HTTP transports for tests. A fake never falls through to the network. Recorded data is explicitly private test data; ordinary formatting omits URLs, headers and bodies.
Index ¶
- Constants
- Variables
- type Fake
- func (f *Fake) AssertNotSent(t testing.TB, match func(Request) bool)
- func (f *Fake) AssertSent(t testing.TB, match func(Request) bool)
- func (f *Fake) AssertSentCount(t testing.TB, expected int, match func(Request) bool)
- func (*Fake) Format(state fmt.State, _ rune)
- func (f *Fake) Pending() int
- func (f *Fake) Requests() []Request
- func (f *Fake) RoundTrip(request *http.Request) (response *http.Response, err error)
- func (f *Fake) Sent() int
- type Outcome
- type Request
- type Route
Constants ¶
const MaxRecordedBodyBytes = 1 << 20
const MaxRecordedBytes = 16 << 20
const MaxRecordedURLBytes = 16 << 10
const MaxRequests = 1024
Variables ¶
var Exhausted = fault.New(fault.Missing, "outbound HTTP fake has no remaining outcome")
var Unmatched = fault.New(fault.Missing, "outbound HTTP fake has no matching route")
Unmatched reports a request that matches no Route of a routed fake.
Functions ¶
This section is empty.
Types ¶
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
Fake is a mutex-protected HTTP transport fake with queued outcomes and bounded request recording.
func NewRoutes ¶
NewRoutes answers each request from the first matching Route. A request matching no route fails with Unmatched; an exhausted route with Exhausted.
func (*Fake) AssertNotSent ¶
AssertNotSent fails t when any recorded request satisfies match.
func (*Fake) AssertSent ¶
AssertSent fails t unless a recorded request satisfies match.
func (*Fake) AssertSentCount ¶
AssertSentCount fails t unless exactly expected requests satisfy match.
func (*Fake) Requests ¶
Requests returns a synchronized snapshot with independent header maps and body slices.
type Outcome ¶
type Outcome struct {
// contains filtered or unexported fields
}
Outcome is a fake HTTP response or transport failure.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is a recorded outbound HTTP request.
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route answers requests whose method and URL match, in declaration order of its outcomes. The pattern uses path.Match syntax against "host/path" (scheme and query excluded), for example "api.example.com/v1/users/*". An empty method matches every method.