httpmock

package
v1.67.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathOnly matchType = iota
	HostOnly
	FullURL
	HostAndPath
	PathAndQuerystring
)

Variables

This section is empty.

Functions

func PathPrefix added in v1.66.0

func PathPrefix(prefix string) string

PathPrefix returns a matcher that matches any path with the given prefix

Types

type Matcher

type Matcher func(req *http.Request) bool

type Mocker

type Mocker struct {
	Requests []*http.Request
	MatchURL matchType // if false, only matches the path and if true, matches full url
	Debug    bool      // Add a debug flag for additional logging
	// contains filtered or unexported fields
}

func New

func New() *Mocker

func (*Mocker) GetStubs added in v1.66.0

func (r *Mocker) GetStubs() []*Stub

func (*Mocker) RegisterResponder

func (r *Mocker) RegisterResponder(method, path string, resp Responder)

func (*Mocker) RegisterResponderWithBody

func (r *Mocker) RegisterResponderWithBody(method, path, body string, resp Responder)

func (*Mocker) RegisterReusableResponder added in v1.66.0

func (r *Mocker) RegisterReusableResponder(method, path string, resp Responder)

func (*Mocker) RegisterReusableResponderWithBody added in v1.66.0

func (r *Mocker) RegisterReusableResponderWithBody(method, path, body string, resp Responder)

func (*Mocker) RoundTrip

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

RoundTrip satisfies http.RoundTripper

func (*Mocker) Verify

func (r *Mocker) Verify(t Testing)

type Responder

type Responder func(req *http.Request) (*http.Response, error)

func NewFileResponse

func NewFileResponse(status int, filename string) Responder

func NewJSONResponse

func NewJSONResponse(status int, body any) Responder

func NewStringResponse

func NewStringResponse(status int, body string) Responder

func NewStringResponseWithHeader

func NewStringResponseWithHeader(status int, body string, header http.Header) Responder

type Stub

type Stub struct {
	Used      bool
	Reusable  bool
	Matcher   Matcher
	Responder Responder

	Method string   // Field to track the method
	URL    *url.URL // Field to track the URL
	// contains filtered or unexported fields
}

type Testing

type Testing interface {
	Errorf(string, ...any)
	Helper()
	Logf(string, ...interface{})
}

Jump to

Keyboard shortcuts

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