httpmock

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(reg *Registry) *http.Client

NewClient returns an http.Client that uses the Registry as its transport.

Types

type Registry

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

Registry records stubs and implements http.RoundTripper.

func (*Registry) Register

func (r *Registry) Register(s *Stub)

Register adds a stub to the registry.

func (*Registry) RoundTrip

func (r *Registry) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

func (*Registry) Verify

func (r *Registry) Verify(t testing.TB)

Verify asserts all stubs were matched.

type Stub

type Stub struct {
	Method      string      // empty = match any method
	URL         string      // substring match on URL
	Status      int         // default 200
	Body        interface{} // auto JSON-serialized
	RawBody     []byte      // raw bytes (takes precedence over Body when non-nil)
	ContentType string      // override Content-Type header (default: application/json)
	Headers     http.Header // optional full response headers (takes precedence over ContentType)

	// CapturedHeaders records the request headers of the matched request.
	// Populated after RoundTrip matches this stub.
	CapturedHeaders http.Header
	CapturedBody    []byte
	// contains filtered or unexported fields
}

Stub defines a preset HTTP response.

Jump to

Keyboard shortcuts

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