testutil

package
v1.114.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureOutput

func CaptureOutput(t *testing.T, fn func()) string

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

func ReplaceDateTime(src, repl string) string

ReplaceDateTime replaces a datetime value. This function is useful to compare JSON responses containing variable values.

func ReplaceUnixTimestamp

func ReplaceUnixTimestamp(src, repl string) string

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

type ErrorCloser struct {
	*bytes.Reader
	// contains filtered or unexported fields
}

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.

func (*ErrorReader) Read added in v1.109.1

func (r *ErrorReader) Read([]byte) (int, error)

Read always returns an error.

type TestHTTPResponseWriter

type TestHTTPResponseWriter interface {
	http.ResponseWriter
}

TestHTTPResponseWriter wraps a standard lib http.ResponseWriter to allow mock generation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL