testutil

package
v0.11.11 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(t *testing.T, err error)

Check calls t.Fatal(err) if err is not nil.

func CheckTime

func CheckTime(t *testing.T, got, want time.Time)

CheckTime calls t.Fatalf if got != want. Included in the error message is want.Sub(got) to help diagnose the difference, along with their values in UTC.

func Checker

func Checker(t *testing.T) (check func(err error))

Checker returns a check function that calls t.Fatal if err is not nil.

func LogWriter

func LogWriter(t *testing.T) io.Writer

LogWriter returns an io.Writer that logs each Write using t.Log.

func SlogBuffer

func SlogBuffer() (lg *slog.Logger, out *bytes.Buffer)

SlogBuffer returns a *slog.Logger that writes each message to out.

func Slogger

func Slogger(t *testing.T) *slog.Logger

Slogger returns a *slog.Logger that writes each message using t.Log.

func StopPanic

func StopPanic(f func())

StopPanic runs f but silently recovers from any panic f causes. The normal usage is:

testutil.StopPanic(func() {
	callThatShouldPanic()
	t.Errorf("callThatShouldPanic did not panic")
})

func WriteFile

func WriteFile[S []byte | string](t testing.TB, name string, data S)

WriteFile writes data to a file named name. It makes the directory if it doesn't exist and sets the file mode to perm.

The name must be a relative path and must not contain .. or start with a /; otherwise WriteFile will panic.

Types

type CheckFunc

type CheckFunc func(err error)

CheckFunc exists so other packages do not need to invent their own type for taking a Check function.

Jump to

Keyboard shortcuts

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