httpmock

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 11 Imported by: 0

README

License

MIT License. See LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareBody

func CompareBody(t TestReporter, requestBody io.Reader, inputBody Body)

func CompareHeader

func CompareHeader(t TestReporter, requestHeader, inputHeader http.Header)

func CompareInput

func CompareInput(t TestReporter, r *http.Request, input Input)

func CompareMethod

func CompareMethod(t TestReporter, requestMethod, inputMethod string)

func CompareQuery

func CompareQuery(t TestReporter, requestQuery, inputQuery url.Values)

func CompareURL

func CompareURL(t TestReporter, requestURL, inputURL *url.URL)

func HandleCallCompareInput

func HandleCallCompareInput(t TestReporter, w http.ResponseWriter, r *http.Request, call Call)

func NewHandlerTransport

func NewHandlerTransport(h http.Handler) http.RoundTripper

func NewTransport

func NewTransport(t TestReporter, calls Calls, handleCall HandleCall) http.RoundTripper

func WriteBody

func WriteBody(w http.ResponseWriter, body Body) error

func WriteHeader

func WriteHeader(w http.ResponseWriter, header http.Header, statusCode int)

func WriteResponse

func WriteResponse(w http.ResponseWriter, response Response) error

Types

type Body

type Body interface {
	Bytes() ([]byte, error)
}

func JSONBody

func JSONBody(value any) Body

type Call

type Call struct {
	Input    Input
	Response Response
	DoError  error
	Delay    time.Duration
}

type Calls

type Calls interface {
	// minimum called times is 1
	Call(calledTimes int) (Call, bool)

	Done(calledTimes int) bool
}

func SequenceCalls

func SequenceCalls(calls ...Call) Calls

func StaticCalls

func StaticCalls(calls ...Call) Calls

type HandleCall

type HandleCall func(t TestReporter, w http.ResponseWriter, r *http.Request, call Call)

type Input

type Input struct {
	Method string
	Body   Body
	Header http.Header
	URL    *url.URL
}

type RawBody

type RawBody []byte

func (RawBody) Bytes

func (r RawBody) Bytes() ([]byte, error)

type Response

type Response struct {
	StatusCode int
	Body       Body
	Header     http.Header
}

type TestReporter

type TestReporter interface {
	Errorf(format string, args ...any)
	Fatalf(format string, args ...any)

	Cleanup(func())
}

Jump to

Keyboard shortcuts

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