Documentation
¶
Index ¶
- Constants
- Variables
- type HTTPMock
- type Matcher
- type MatcherResponder
- type Matchers
- type MethodMatcher
- type PathMatcher
- type QueryMatcher
- type RequestSnapshot
- type RequestSnapshotter
- type Responder
- func Body(body string) Responder
- func BytesBody(body []byte) Responder
- func Debug(t *testing.T) Responder
- func Header(key string, value ...string) Responder
- func JSON(t *testing.T, body interface{}) Responder
- func JSONContent(body []byte) Responder
- func JSONFromFile(t *testing.T, filename string) Responder
- func Status(status int) Responder
- type Responders
- type ResponseRecorder
- type SeqMatcherResponder
Constants ¶
View Source
const ( StatusNext = 555 StatusNoMatch = 556 FailedBody = "testing mock failed to find matching request handler" )
Variables ¶
View Source
var ( NoBody Matcher = &noBodyMatcher{} AnyRequest Matcher = &anyRequestMatcher{} Get = Method(http.MethodGet) Patch = Method(http.MethodPatch) Post = Method(http.MethodPost) Put = Method(http.MethodPut) Delete = Method(http.MethodDelete) )
Functions ¶
This section is empty.
Types ¶
type HTTPMock ¶
type HTTPMock struct { RequestSnapshots *RequestSnapshotter // contains filtered or unexported fields }
func MockHandler ¶
type MatcherResponder ¶
type MatcherResponder struct {
// contains filtered or unexported fields
}
func (*MatcherResponder) ServeHTTP ¶
func (mr *MatcherResponder) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Matchers ¶
type Matchers []Matcher
func (Matchers) Respond ¶
func (m Matchers) Respond(r ...Responder) *MatcherResponder
func (Matchers) RespondSeq ¶
func (m Matchers) RespondSeq(r ...Responders) *SeqMatcherResponder
type MethodMatcher ¶
type MethodMatcher struct {
// contains filtered or unexported fields
}
func Method ¶
func Method(method string) *MethodMatcher
type PathMatcher ¶
type PathMatcher struct {
// contains filtered or unexported fields
}
func Path ¶
func Path(path string) *PathMatcher
type QueryMatcher ¶
type QueryMatcher struct {
// contains filtered or unexported fields
}
func Query ¶
func Query(key, value string) *QueryMatcher
func QueryValues ¶
func QueryValues(key string, values ...string) *QueryMatcher
func (*QueryMatcher) Add ¶
func (q *QueryMatcher) Add(key, value string) *QueryMatcher
func (*QueryMatcher) AddValues ¶
func (q *QueryMatcher) AddValues(key string, values ...string) *QueryMatcher
func (*QueryMatcher) ExactMatch ¶
func (q *QueryMatcher) ExactMatch() *QueryMatcher
ExactMatch requires query values to match exactly (no extra keys/values accepted)
type RequestSnapshot ¶
func NewRequestSnapshot ¶
func NewRequestSnapshot(req *http.Request) *RequestSnapshot
type RequestSnapshotter ¶
type RequestSnapshotter struct { sync.Mutex Snapshots []*RequestSnapshot }
func NewRequestSnapshotter ¶
func NewRequestSnapshotter() *RequestSnapshotter
func (*RequestSnapshotter) Add ¶
func (s *RequestSnapshotter) Add(req *http.Request)
func (*RequestSnapshotter) Calls ¶
func (s *RequestSnapshotter) Calls() int
func (*RequestSnapshotter) Debug ¶
func (s *RequestSnapshotter) Debug(t *testing.T)
func (*RequestSnapshotter) ServeHTTP ¶
func (s *RequestSnapshotter) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Responder ¶
type Responder func(w http.ResponseWriter, r *http.Request)
func JSONContent ¶
JSONContent should be used when you already have json as []byte
func JSONFromFile ¶
JSONFromFile reads the contents of filename as []bytes writes that along with json content headers
type Responders ¶
type Responders []Responder
type ResponseRecorder ¶
func NewResponseRecorder ¶
func NewResponseRecorder() *ResponseRecorder
func (*ResponseRecorder) Header ¶
func (rr *ResponseRecorder) Header() http.Header
func (*ResponseRecorder) WriteHeader ¶
func (rr *ResponseRecorder) WriteHeader(code int)
type SeqMatcherResponder ¶
type SeqMatcherResponder struct {
// contains filtered or unexported fields
}
func (*SeqMatcherResponder) ServeHTTP ¶
func (mr *SeqMatcherResponder) ServeHTTP(w http.ResponseWriter, r *http.Request)
Click to show internal directories.
Click to hide internal directories.