Documentation
¶
Overview ¶
Package fixtures holds the servers, handlers and requests that the test suites share. It imports ehttp, so it lives apart from ehttptest, which the tests inside package ehttp import.
Index ¶
- Constants
- func CaptureLogs(t *testing.T) *observer.ObservedLogs
- func Client() *http.Client
- func CorsServer(_ testing.TB, opts *ehttp.CorsOptions) *ehttp.Server
- func Fetch(t testing.TB, method, url string, hdr http.Header) (resp *http.Response, body string)
- func FreePort(t testing.TB) string
- func Handler(h ehttp.HandlerFunc, mws ...ehttp.MiddlewareHandlerFunc) http.Handler
- func HandlerLogged(l *zap.Logger, h ehttp.HandlerFunc, mws ...ehttp.MiddlewareHandlerFunc) http.Handler
- func OK(res *ehttp.ResponseWriter, _ *ehttp.Request)
- func ObservedLogger() (*zap.Logger, *observer.ObservedLogs)
- func PostHandler(h ehttp.HandlerFunc, mws ...ehttp.MiddlewareHandlerFunc) http.Handler
- func Raw(t testing.TB, addr, raw string) string
- func Req(method, target string, kv ...string) *http.Request
- func Start(t testing.TB, srv *ehttp.Server) *httptest.Server
- func Status(code int, body string) ehttp.HandlerFunc
- type Listening
Constants ¶
const ( OriginA = "https://app.example" OriginB = "https://admin.example" OriginEvil = "https://evil.example" )
Origins used by the CORS suites.
Variables ¶
This section is empty.
Functions ¶
func CaptureLogs ¶
func CaptureLogs(t *testing.T) *observer.ObservedLogs
CaptureLogs swaps the global zap logger. Tests that call it are serial.
func Client ¶
Client returns a client that keeps raw responses: no redirects, no transparent gzip, short overall deadline.
func CorsServer ¶
CorsServer builds a server with the Cors middleware. Nil options mean DefaultCorsOptions.
func Handler ¶
func Handler(h ehttp.HandlerFunc, mws ...ehttp.MiddlewareHandlerFunc) http.Handler
Handler builds a server that serves h on GET /x (and HEAD) with the given route middlewares, in order (first = outermost). It registers one method only: GET plus POST on the same path answers 405 for POST.
func HandlerLogged ¶
func HandlerLogged(l *zap.Logger, h ehttp.HandlerFunc, mws ...ehttp.MiddlewareHandlerFunc) http.Handler
HandlerLogged is Handler with the server logger set.
func ObservedLogger ¶
func ObservedLogger() (*zap.Logger, *observer.ObservedLogs)
ObservedLogger returns a logger that records its entries, for WithLogger. It does not touch the global logger, so the test can run in parallel.
func PostHandler ¶
func PostHandler(h ehttp.HandlerFunc, mws ...ehttp.MiddlewareHandlerFunc) http.Handler
PostHandler is Handler for POST /x.
func Raw ¶
Raw writes raw bytes to addr and returns everything the server sends until it closes the connection or 2s pass.