Documentation ¶
Index ¶
- type DoerSpy
- type DoerSpyRecord
- type DoerStub
- type DoerStubCall
- type RequestMatcher
- type RequestMatcherBuilder
- func (b *RequestMatcherBuilder) BodyForm(compareWith url.Values, strict bool) *RequestMatcherBuilder
- func (b *RequestMatcherBuilder) BodyJSON(compareWith any, getDest func() any, strict bool) *RequestMatcherBuilder
- func (b *RequestMatcherBuilder) HeadersContains(headers http.Header) *RequestMatcherBuilder
- func (b *RequestMatcherBuilder) MatchRequest(req *http.Request) error
- func (b *RequestMatcherBuilder) Method(method string) *RequestMatcherBuilder
- func (b *RequestMatcherBuilder) URLHost(host string) *RequestMatcherBuilder
- func (b *RequestMatcherBuilder) URLPath(path string) *RequestMatcherBuilder
- func (b *RequestMatcherBuilder) URLQueryParamsContains(params url.Values) *RequestMatcherBuilder
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DoerSpy ¶
type DoerSpy struct {
// contains filtered or unexported fields
}
DoerSpy implements Doer and exposes calls made on the underlying Doer. It is safe to call it concurrently.
func NewDoerSpy ¶
func NewDoerSpy(doer httpclient.Doer) *DoerSpy
NewDoerSpy creates a new spy on provided Doer. Spied doer keep track of input and output made on the underlying doer.
func (*DoerSpy) Calls ¶
func (d *DoerSpy) Calls() []DoerSpyRecord
Calls returns the list of calls made on the Doer and clears the list.
type DoerSpyRecord ¶
type DoerSpyRecord struct { InputRequest *http.Request OutputResponse *http.Response OutputError error }
DoerSpyRecord stores input and outputs of one Doer call.
type DoerStub ¶
type DoerStub struct {
// contains filtered or unexported fields
}
DoerStub implements Doer and returns pre-configured calls. It is safe to call it concurrently.
func NewDoerStub ¶
func NewDoerStub(calls []DoerStubCall, strictOrder bool) *DoerStub
NewDoerStub returns a new stubbed Doer. See DoerStubCall for how to configure calls.
func (*DoerStub) Do ¶
Do wraps the underlying doer call and returns pre-configured responses. If strictOrder is true, Doer will go through each configured calls in order and if the request matcher is set and don't match the request, an error will be returned. Otherwise, if strictOrder is false, Doer will go through each configured calls in order but if the request matcher is set and don't match the request, the call will be skipped and the next will be tried. If no calls are remaining, or if structOrder is false and no call match, an error will be returned.
func (*DoerStub) RemainingCalls ¶
func (d *DoerStub) RemainingCalls() []DoerStubCall
RemainingCalls returns calls that were not made but configured.
type DoerStubCall ¶
type DoerStubCall struct { Matcher RequestMatcher Response *http.Response Error error }
DoerStubCall define the configuration of a call. If a matcher is not set, the duo 'response,error' will be returned regardless of the request. Otherwise, the request will be checked against matcher and duo 'response,error' will be returned only if the request match.
type RequestMatcher ¶
RequestMatcher defines a way to check whenever a request match against some pre-defined rules.
type RequestMatcherBuilder ¶
type RequestMatcherBuilder struct {
// contains filtered or unexported fields
}
RequestMatcherBuilder stores assertions and implements RequestMatcher.
func NewRequestMatcherBuilder ¶
func NewRequestMatcherBuilder() *RequestMatcherBuilder
NewRequestMatcherBuilder creates a new empty RequestMatcherBuilder.
func (*RequestMatcherBuilder) BodyForm ¶
func (b *RequestMatcherBuilder) BodyForm(compareWith url.Values, strict bool) *RequestMatcherBuilder
BodyForm asserts that the provided url values are contained in request.PostForm. Strict parameters define whenever the request.PostForm should be exactly the provided url values or more values can exists.
func (*RequestMatcherBuilder) BodyJSON ¶
func (b *RequestMatcherBuilder) BodyJSON(compareWith any, getDest func() any, strict bool) *RequestMatcherBuilder
BodyJSON asserts that request's body is a JSON can be bound to getDest()'s output and is the same as compareWith. Strict parameters define whenever the body can contain unknown fields.
func (*RequestMatcherBuilder) HeadersContains ¶
func (b *RequestMatcherBuilder) HeadersContains(headers http.Header) *RequestMatcherBuilder
HeadersContains asserts that the provided headers are contained in request.Header.
func (*RequestMatcherBuilder) MatchRequest ¶
func (b *RequestMatcherBuilder) MatchRequest(req *http.Request) error
MatchRequest implements RequestMatcher and asserts all built assertions.
func (*RequestMatcherBuilder) Method ¶
func (b *RequestMatcherBuilder) Method(method string) *RequestMatcherBuilder
Method asserts that the provided method matches request.Method.
func (*RequestMatcherBuilder) URLHost ¶
func (b *RequestMatcherBuilder) URLHost(host string) *RequestMatcherBuilder
URLHost asserts that the provided host matches request.URL.Host.
func (*RequestMatcherBuilder) URLPath ¶
func (b *RequestMatcherBuilder) URLPath(path string) *RequestMatcherBuilder
URLPath asserts that the provided path matches request.URL.Path.
func (*RequestMatcherBuilder) URLQueryParamsContains ¶
func (b *RequestMatcherBuilder) URLQueryParamsContains(params url.Values) *RequestMatcherBuilder
URLQueryParamsContains asserts that the provided url values are contained in request.URL.Query().
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server runs a server on which one can assert requests.
func NewServer ¶
func NewServer(do func(serverAddress url.URL, serverDoer httpclient.Doer, checkResponseFunc any) error) *Server
NewServer creates a server. Provided do argument is a fonction that should perform a request.
func (*Server) AssertRequest ¶
func (srv *Server) AssertRequest(requestExpectations RequestMatcher, writeResponse func(http.ResponseWriter) error, checkResponseFunc any) error
AssertRequest performs the request and asserts.