Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockResponse ¶
type MockResponse struct { // Method matches against a incomming request Method string // use http.Status<something> to reponde to a request. Code int // the response body to send back. Body string // CheckFn is called on each request match. // Assert that the URL in the request matches what you expect, like so: // c.Assert(r.RequestURI, Equals, s.server.BaseURL+"/resource") CheckFn func(*http.Request, string) // Persistant controls if the response can remain and be used again. Persistant bool RequestBody string // Will hold a reference to the request after response is matched to a request Request *http.Request // Hits increments each time the response is sent back Hits int // contains filtered or unexported fields }
MockResponse defines a response to a matching request. Requests are matched based on Method and order of when they were added to the response queue.
type MockServer ¶
type MockServer struct { // Checker are invalidated on every new function call. Update before every usage. Checker *C Responses []*MockResponse Requests []*http.Request // The BaseURL of the server is unique with every server start. // Match urls to this by concactenating: s.server.BaseURL+"/resource" BaseURL string Server *httptest.Server HTTPClient *http.Client }
MockServer holds queries of mock responses and stores the requests made to it.
func (*MockServer) AddResponse ¶
func (m *MockServer) AddResponse(r *MockResponse) *MockResponse
AddResponse adds a mock response that HandleRequest will look foor
func (*MockServer) HandleRequest ¶
func (m *MockServer) HandleRequest(w http.ResponseWriter, r *http.Request)
HandleRequest is a HTTP handler that matches the request to the mock responses If a response with a matching url is found, the response body is written to the writer and the CheckFn is called.
func (*MockServer) SetChecker ¶
func (m *MockServer) SetChecker(c *C)
SetChecker sets the checker for the next request handler
func (*MockServer) VerifyNoMoreRequests ¶
func (m *MockServer) VerifyNoMoreRequests(c *C)
VerifyNoMoreRequests checks that no requests are unmet
Click to show internal directories.
Click to hide internal directories.