Documentation ¶
Overview ¶
Package clientserver is a utility for writing HTTP tests.
A ClientServer embeds an httptest.Server and a requests.Requests client. The client is preconfigured to talk to the server.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientServer ¶
type ClientServer struct { *httptest.Server *requests.Requests Handler http.Handler // The last request handled by the server. LastSrvReq *http.Request // The last request sent by the client. LastClientReq *http.Request // The last response received by the client. LastClientResp *http.Response }
A ClientServer is an http server and an http client. The client is preconfigured to talk to the server. Because it embeds a requests.Requeests, it support all the same methods for composing and sending HTTP requests, which are send to the embedded HTTP server.
Should be closed at the end of the test.
func New ¶
func New(s *httptest.Server, options ...requests.Option) *ClientServer
New creates a new ClientServer.
Panics if the option arguments cause an error.
func (*ClientServer) Clear ¶
func (t *ClientServer) Clear()
Clear clears the attributes captured by the last request.
func (*ClientServer) Close ¶
func (t *ClientServer) Close()
Close shuts down the embedded HTTP server.
func (*ClientServer) HandlerFunc ¶
func (t *ClientServer) HandlerFunc(hf http.HandlerFunc)
HandlerFunc is a convience method for installing a HandlerFunc as the handler.
func (*ClientServer) Mux ¶
func (t *ClientServer) Mux() *http.ServeMux
Mux returns a ServeMux. If the current Handler is a ServeMux, that is returned. Otherwise, a new ServerMux is created and installed as the handler.
func (*ClientServer) ServeHTTP ¶
func (t *ClientServer) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServerHTTP implements http.Handler. ClientServer installs itself as the server's Handler so it can capture the request. It then delegates to the Handler attribute.