Documentation ¶
Overview ¶
Package testutil provides common testing utility functions.
Index ¶
- func CaptureOutput(t *testing.T, fn func()) string
- func Context() context.Context
- func ContextWithHTTPRouterParams(ctx context.Context, params map[string]string) context.Context
- func ContextWithLogObserver(level zapcore.LevelEnabler) (context.Context, *observer.ObservedLogs)
- func ReplaceDateTime(src, repl string) string
- func ReplaceUnixTimestamp(src, repl string) string
- func RouterWithHandler(method, path string, handlerFunc http.HandlerFunc) http.Handler
- type TestHTTPResponseWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureOutput ¶
CaptureOutput hijacks and captures stderr and stdout for testing the given function.
func ContextWithHTTPRouterParams ¶
ContextWithHTTPRouterParams creates a context copy containing map of URL path segments.
func ContextWithLogObserver ¶
func ContextWithLogObserver(level zapcore.LevelEnabler) (context.Context, *observer.ObservedLogs)
ContextWithLogObserver returns a context initialized with a NOP logger for testing.
func ReplaceDateTime ¶
ReplaceDateTime replaces a datetime value. This function is useful to compare JSON responses containing variable values.
func ReplaceUnixTimestamp ¶
ReplaceUnixTimestamp replaces a unix timestamp. This function is useful to compare JSON responses containing variable values.
func RouterWithHandler ¶
func RouterWithHandler(method, path string, handlerFunc http.HandlerFunc) http.Handler
RouterWithHandler returns a new httprouter instance with the give handler function attached.
Types ¶
type TestHTTPResponseWriter ¶
type TestHTTPResponseWriter interface { http.ResponseWriter }
TestHTTPResponseWriter wraps a standard lib http.ResponseWriter to allow mock generation.