httpclient

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 10 Imported by: 0

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

View Source
const MaxRecordedBodyBytes = 1 << 20
View Source
const MaxRecordedBytes = 16 << 20
View Source
const MaxRecordedURLBytes = 16 << 10
View Source
const MaxRequests = 1024

Variables

View Source
var Exhausted = fault.New(fault.Missing, "outbound HTTP fake has no remaining outcome")
View Source
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
}

func New

func New(outcomes ...Outcome) (*Fake, error)

New answers requests with outcomes in arrival order.

func NewRoutes

func NewRoutes(routes ...Route) (*Fake, error)

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

func (f *Fake) AssertNotSent(t testing.TB, match func(Request) bool)

AssertNotSent fails t when any recorded request satisfies match.

func (*Fake) AssertSent

func (f *Fake) AssertSent(t testing.TB, match func(Request) bool)

AssertSent fails t unless a recorded request satisfies match.

func (*Fake) AssertSentCount

func (f *Fake) AssertSentCount(t testing.TB, expected int, match func(Request) bool)

AssertSentCount fails t unless exactly expected requests satisfy match.

func (*Fake) Format

func (*Fake) Format(state fmt.State, _ rune)

func (*Fake) Pending

func (f *Fake) Pending() int

func (*Fake) Requests

func (f *Fake) Requests() []Request

func (*Fake) RoundTrip

func (f *Fake) RoundTrip(request *http.Request) (response *http.Response, err error)

func (*Fake) Sent

func (f *Fake) Sent() int

type Outcome

type Outcome struct {
	// contains filtered or unexported fields
}

func Fail

func Fail(err error) Outcome

func Respond

func Respond(status int, headers http.Header, body []byte) Outcome

func (Outcome) Format

func (Outcome) Format(state fmt.State, _ rune)

type Request

type Request struct {
	// contains filtered or unexported fields
}

func (Request) Body

func (r Request) Body() []byte

func (Request) Format

func (Request) Format(state fmt.State, _ rune)

func (Request) Headers

func (r Request) Headers() http.Header

func (Request) Method

func (r Request) Method() string

func (Request) URL

func (r Request) URL() string

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.

func On

func On(method, pattern string, outcomes ...Outcome) Route

func (Route) Format

func (Route) Format(state fmt.State, _ rune)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL