testutil

package
v1.90.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package testutil provides common testing utility functions.

The provided functions are intended to simplify the process of setting up tests and to provide a consistent way to do so across the codebase.

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 Context

func Context() context.Context

Context returns a context initialized with a NOP logger for testing.

func ContextWithHTTPRouterParams

func ContextWithHTTPRouterParams(ctx context.Context, params map[string]string) context.Context

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

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 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