Documentation
¶
Index ¶
- func NewTestLogger(t testing.TB) *slog.Logger
- type EchoHandler
- type GomegaSuite
- type HTTPRequestRecorder
- type LogRecorder
- func (r *LogRecorder) Enabled(context.Context, slog.Level) bool
- func (r *LogRecorder) FilterLevel(lvl slog.Level) (ret []slog.Record)
- func (r *LogRecorder) Handle(_ context.Context, rec slog.Record) error
- func (r *LogRecorder) Reset()
- func (r *LogRecorder) WithAttrs(attrs []slog.Attr) slog.Handler
- func (r *LogRecorder) WithGroup(name string) slog.Handler
- type StaticFile
- type StaticFileServer
- type TestingLogHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type EchoHandler ¶
type EchoHandler struct {
// Requests contains all HTTP requests sent to the handler
Requests []*http.Request
}
EchoHandler is an http.Handler that echos the requested path in the document heading, i.e., the <h1> element.
func (*EchoHandler) RequestCount ¶
func (h *EchoHandler) RequestCount() int
RequestCount returns how many HTTP requests have been made to the handler
func (*EchoHandler) ServeHTTP ¶
func (h *EchoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type GomegaSuite ¶
GomegaSuite is a specialised suite.Suite that provides support for the gomega assertion library by providing a GomegaSuite.Expect function automatically initializes gomega with
func (*GomegaSuite) Expect ¶
func (s *GomegaSuite) Expect(actual interface{}, extra ...interface{}) types.Assertion
Expect is wraps gomega/Gomega.Expect, passing the correct testing/T. This supports gomega matchers for verification; which can in some cases provide more expressive tests.
type HTTPRequestRecorder ¶ added in v0.6.0
HTTPRequestRecorder is an HTTPHandler middleware that keeps a record of all incoming request objects.
func NewHTTPRequestRecorder ¶ added in v0.6.0
func NewHTTPRequestRecorder(t testing.TB, handler http.Handler) *HTTPRequestRecorder
func (*HTTPRequestRecorder) Clear ¶ added in v0.6.0
func (r *HTTPRequestRecorder) Clear()
Clear deletes all recorded Requests.
func (*HTTPRequestRecorder) ServeHTTP ¶ added in v0.6.0
func (rec *HTTPRequestRecorder) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*HTTPRequestRecorder) Single ¶ added in v0.6.0
func (r *HTTPRequestRecorder) Single() *http.Request
func (HTTPRequestRecorder) URLs ¶ added in v0.6.0
func (r HTTPRequestRecorder) URLs() []string
URLs return all URL strings recorded
type LogRecorder ¶ added in v0.6.0
LogRecorder is an implementation of slog.Handler recording all log entries in a slice.
func (*LogRecorder) FilterLevel ¶ added in v0.6.0
func (r *LogRecorder) FilterLevel(lvl slog.Level) (ret []slog.Record)
FilterLevel returns a slice of log records with the specified log level
func (*LogRecorder) Reset ¶ added in v0.6.0
func (r *LogRecorder) Reset()
type StaticFile ¶ added in v0.6.0
A simple http.Handler that serves static file content. This type is a pair of MIMEType and body content.
func StaticHTML ¶ added in v0.6.0
func StaticHTML(html string) StaticFile
StaticHTML creates an http.Handler that serves static content with the MIME type, "text/html".
func StaticJS ¶ added in v0.6.0
func StaticJS(js string) StaticFile
StaticJS creates an http.Handler that serves static content with the MIME type, "text/javascript".
func (StaticFile) ServeHTTP ¶ added in v0.6.0
func (f StaticFile) ServeHTTP(w http.ResponseWriter, r *http.Request)
type StaticFileServer ¶ added in v0.6.0
type StaticFileServer map[string]StaticFile
StaticFileServer is a simple http.Handler that can simplify test code that only needs to configure static files.
As it has a map as an underlying type, you can create the entire http handler as a Go map literal, making it simpler to configure than creating a new mux.
func (StaticFileServer) ServeHTTP ¶ added in v0.6.0
func (s StaticFileServer) ServeHTTP(w http.ResponseWriter, r *http.Request)