Documentation
¶
Overview ¶
Package handlertest implements support for testing implementations of HTTP handlers.
This is inspired by fstest.TestFS, but implemented differently, notably using a testing.T parameter for better reporting.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HostTest ¶
func HostTest(t *testing.T, h handler.Host, newCtx func(handler.Features) (context.Context, handler.Features)) error
HostTest tests a handler.Host by testing default property values and ability to change them.
To use this, pass your host and the context which allows access to the request and response objects. This should be configured for "HTTP/1.1".
Here's an example of a net/http host which supports no features:
newCtx := func(features handler.Features) (context.Context, handler.Features) { if features != 0 { return testCtx, 0 // unsupported } r, _ := http.NewRequest("GET", "", nil) w := &httptest.ResponseRecorder{HeaderMap: map[string][]string{}} return context.WithValue(testCtx, requestStateKey{}, &requestState{r: r, w: w}), features } // Run all the tests handlertest.HostTest(t, host{}, newCtx)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.