Documentation
¶
Overview ¶
Package testutil provides common testing utility functions.
The functions provided by this package are intended to simplify the process of setting up tests and to provide a consistent way to do so across the codebase.
These functions are intended for use in tests only.
Index ¶
- func CaptureOutput(t *testing.T, fn func()) string
- func NewErrorCloser(errMsg string) io.ReadCloser
- func ReplaceDateTime(src, repl string) string
- func ReplaceUnixTimestamp(src, repl string) string
- func RouterWithHandler(method, path string, handlerFunc http.HandlerFunc) http.Handler
- type ErrorCloser
- type ErrorReader
- 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 NewErrorCloser ¶ added in v1.109.1
func NewErrorCloser(errMsg string) io.ReadCloser
NewErrorCloser creates a ReadCloser that returns the specified error when closed.
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 ErrorCloser ¶ added in v1.109.1
ErrorCloser is an io.ReadCloser that always returns an error on Close.
func (*ErrorCloser) Close ¶ added in v1.109.1
func (e *ErrorCloser) Close() error
Close always returns an error.
type ErrorReader ¶ added in v1.109.1
type ErrorReader struct {
// contains filtered or unexported fields
}
ErrorReader is an io.Reader that always returns an error.
func NewErrorReader ¶ added in v1.109.1
func NewErrorReader(msg string) *ErrorReader
NewErrorReader creates a new errIoReader that always returns the given error message.
type TestHTTPResponseWriter ¶
type TestHTTPResponseWriter interface {
http.ResponseWriter
}
TestHTTPResponseWriter wraps a standard lib http.ResponseWriter to allow mock generation.