Help us shape the future of Go! Take the 2026 Go Developer Survey

testutil

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package testutil holds the small assertion helpers shared by tests, so they stay on the stdlib testing package. Plain functions (Equal, NoError, ...) mark the test failed and continue; the Require-prefixed forms stop it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(t testing.TB, container, elem any, msg ...any)

Contains fails the test unless the string, slice, array or map holds elem.

func Empty

func Empty(t testing.TB, v any, msg ...any)

Empty fails the test unless v is nil, zero, or an empty string, slice, map or array.

func Equal

func Equal(t testing.TB, want, got any, msg ...any)

Equal fails the test unless want and got are deeply equal.

func EqualError

func EqualError(t testing.TB, err error, want string, msg ...any)

EqualError fails the test unless err is non-nil with exactly the given message.

func Error

func Error(t testing.TB, err error, msg ...any)

Error fails the test when err is nil.

func ErrorIs

func ErrorIs(t testing.TB, err, target error, msg ...any)

ErrorIs fails the test unless err wraps target.

func False

func False(t testing.TB, v bool, msg ...any)

False fails the test unless v is false.

func JSONEqual

func JSONEqual(t testing.TB, want, got string, msg ...any)

JSONEqual fails the test unless both strings are JSON documents with equal content.

func Len

func Len(t testing.TB, v any, want int, msg ...any)

Len fails the test unless v (string, slice, array, map or chan) has length want.

func LessOrEqual

func LessOrEqual[T int | int64 | float64 | string](t testing.TB, a, b T, msg ...any)

LessOrEqual fails the test unless a <= b.

func Nil

func Nil(t testing.TB, v any, msg ...any)

Nil fails the test unless v is nil (including typed nil pointers, slices, maps).

func NoError

func NoError(t testing.TB, err error, msg ...any)

NoError fails the test when err is non-nil.

func NotContains

func NotContains(t testing.TB, container, elem any, msg ...any)

NotContains fails the test when the string, slice, array or map holds elem.

func NotEmpty

func NotEmpty(t testing.TB, v any, msg ...any)

NotEmpty fails the test when v is empty.

func NotEqual

func NotEqual(t testing.TB, a, b any, msg ...any)

NotEqual fails the test when a and b are deeply equal.

func NotErrorIs

func NotErrorIs(t testing.TB, err, target error, msg ...any)

NotErrorIs fails the test when err wraps target.

func NotNil

func NotNil(t testing.TB, v any, msg ...any)

NotNil fails the test when v is nil.

func RequireEqual

func RequireEqual(t testing.TB, want, got any, msg ...any)

RequireEqual is Equal, stopping the test on failure.

func RequireError

func RequireError(t testing.TB, err error, msg ...any)

RequireError is Error, stopping the test on failure.

func RequireErrorIs

func RequireErrorIs(t testing.TB, err, target error, msg ...any)

RequireErrorIs is ErrorIs, stopping the test on failure.

func RequireJSONEqual

func RequireJSONEqual(t testing.TB, want, got string, msg ...any)

RequireJSONEqual is JSONEqual, stopping the test on failure.

func RequireLen

func RequireLen(t testing.TB, v any, want int, msg ...any)

RequireLen is Len, stopping the test on failure.

func RequireNoError

func RequireNoError(t testing.TB, err error, msg ...any)

RequireNoError is NoError, stopping the test on failure.

func RequireNotNil

func RequireNotNil(t testing.TB, v any, msg ...any)

RequireNotNil is NotNil, stopping the test on failure.

func True

func True(t testing.TB, v bool, msg ...any)

True fails the test unless v is true.

Types

type QueryCounter

type QueryCounter struct {
	// contains filtered or unexported fields
}

QueryCounter is a pgx.QueryTracer that records the statements a pool runs. Set it as ConnConfig.Tracer before the pool is created, then compare Count before and after the code under test (Since lists what ran in between).

func (*QueryCounter) Count

func (c *QueryCounter) Count() int

Count is the number of statements started so far.

func (*QueryCounter) Since

func (c *QueryCounter) Since(n int) []string

Since returns the statements started after the first n (n from Count).

func (*QueryCounter) TraceQueryEnd

func (c *QueryCounter) TraceQueryEnd(context.Context, *pgx.Conn, pgx.TraceQueryEndData)

TraceQueryEnd is part of pgx.QueryTracer.

func (*QueryCounter) TraceQueryStart

func (c *QueryCounter) TraceQueryStart(ctx context.Context, _ *pgx.Conn, d pgx.TraceQueryStartData) context.Context

TraceQueryStart records one statement.

Jump to

Keyboard shortcuts

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