Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Request ¶
type Request struct {
Method string
Path string
Want func(t *testing.T, r *http.Request)
Status int
JSON any
JSONRaw string
TextRaw string
}
Request describes a http request that a httptest.Server should receive, and the corresponding response to return.
Additional checks on the request (e.g. request body) may be added using the Request.Want function.
The response body is populated from either a JSON struct, or a JSON string.
func NewErrorRequest ¶ added in v2.54.0
func NewErrorRequest(method string, path string, status int, errorCode, errorMessage string) Request
NewErrorRequest returns a new generic error request for the given HTTP method and path and status.
func NotFoundRequest ¶ added in v2.54.0
NotFoundRequest returns a generic `Not found` (404) request for the given HTTP method and path.
func ServerErrorRequest ¶ added in v2.54.0
ServerErrorRequest returns a generic `Internal Server Error` (500) request for the given HTTP method and path.
type Server ¶ added in v2.15.0
Server embeds a httptest.Server that answers HTTP calls with a list of expected Request.
Request matching is based on the request count, and the user provided request will be iterated over.
A Server must be created using the NewServer function.
Experimental: `exp` package is experimental, breaking changes may occur within minor releases.