Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrUnexpectedCall ¶
ErrUnexpectedCall crafts an error including a stack trace, to pinpoint a call that did not match any of the configured responses
Types ¶
type JSON ¶
type JSON struct {
Obj interface{}
}
JSON respects the ResponsePayload interface. It encloses another object and marshals it into json. This is used if your body object does not respect ResponsePayload.
type MockRoundTripper ¶
type MockRoundTripper struct { sync.Mutex Responses []*Response // contains filtered or unexported fields }
MockRoundTripper implements http.RoundTripper for mocking/testing purposes
func (*MockRoundTripper) AssertEmpty ¶
func (mc *MockRoundTripper) AssertEmpty(t *testing.T)
AssertEmpty ensures all expected responses have been consumed. It will call t.Error() detailing the remaining unconsumed responses.
func (*MockRoundTripper) Expect ¶
func (mc *MockRoundTripper) Expect(status int, body interface{}) *Response
Expect adds a new expected response, specifying status and body. The other components (headers, conditional filters) can be further specified by chaining setter calls on the response object.
type Raw ¶
type Raw []byte
Raw respects the ResponsePayload interface. It lets you define a Body object with raw bytes.
type Response ¶
type Response struct { Status int Body ResponsePayload Cond func(*Context) bool Mock *MockRoundTripper // contains filtered or unexported fields }
An expected mocked response. Defining traits are status and body. Optionally includes conditional filter function defined by one or several On(...) or OnIdentifier(...) calls.
func (*Response) OnFunc ¶
OnFunc matches calls that went throug a given go function. It accepts a reference to a function as input, and panics otherwise.
func (*Response) OnIdentifier ¶
OnIdentifier adds a conditional filter to the response. The response will be selected only if the HTTP path of the request contains "/.../IDENT(/...)": the identifier enclosed in a distinct path segment
type ResponsePayload ¶
ResponsePayload is an interface that the Body object you pass in your expected responses can respect. It lets you customize the way your body is handled. If you pass an object that does NOT respect ResponsePayload, JSON is the default.