Documentation ¶
Overview ¶
Package knockttp is a Go library providing to mock a http server for testing purposes
It has been initially designed to test crawlers reproducing different web scenarios.
There are two modes of operation:
Transport - works by setting a http.RoundTripper in your client requests. Due the nature of this implementation, a multiple host/service setup can be implemented.
Server - creates a test server into a random port
Index ¶
Constants ¶
This section is empty.
Variables ¶
var WildcardMethod = "*"
WildcardMethod points to the default handler when there is no explicit method defined
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct { ContentType string `json:"content_type,omitempty"` StatusCode int `json:"status_code,omitempty"` //Location is specified if a redirect is required Location string `json:"location,omitempty"` Filename string `json:"filename,omitempty"` Body []byte `json:"body,omitempty"` Headers http.Header `json:"headers,omitempty"` // contains filtered or unexported fields }
Handler contains the elements to build a response
type MethodHandlers ¶
MethodHandlers contains handlers for specific methods
func (*MethodHandlers) GetHandler ¶
func (m *MethodHandlers) GetHandler(Method string) (*Handler, bool)
GetHandler returns a Handler given a Method
type Route ¶
type Route struct { Path string `json:"query,omitempty"` Methods MethodHandlers `json:"methods,omitempty"` }
type TestServer ¶
func NewTestServer ¶
func NewTestServer(routes Routes) (*TestServer, error)
func (*TestServer) ServeFunc ¶
func (ts *TestServer) ServeFunc(route *Route) func(w http.ResponseWriter, r *http.Request)
type Transport ¶
func NewTransport ¶
NewTransport instantiates a transport given a Network and Data