assert

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0, Apache-2.0 Imports: 7 Imported by: 0

README

Assert embeddings

This package exists to drop the dependency on stretchr/testify/assert. It mutes the conversation on which to use (assert or require), and provides a limited API that does about the same.

It's based on fortio.org/assert and contains the following modifications:

  • Use testing.TB instead of explicit *testing.T
  • Use any or ...any for printf arguments

It's meant to be used from inside the current module and not intended as an imported dependency.

Documentation

Overview

Package assert is a minimalistic drop-in replacement for testify/assert. It is based on fortio.org/assert and is internal to this module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(t testing.TB, cond bool, msg string, rest ...any)

Assert is similar to True() under a different name and earlier fortio/stats test implementation.

func CheckEquals

func CheckEquals(t testing.TB, actual, expected any, msg ...any)

CheckEquals checks if actual == expect and fails the test and logs failure (including filename:linenum if they are not equal).

func Contains

func Contains(t testing.TB, haystack, needle any, msg ...any)

Contains checks that needle is in haystack.

func Empty

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

Empty checks that value is nil, zero, or has length zero.

func Equal

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

Equal also checks for a equal b.

func EqualValues

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

EqualValues checks for a equal b.

func Error

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

Error checks/expects an error.

func ErrorContains

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

ErrorContains checks that err is non-nil and its message contains want.

func ErrorIs

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

ErrorIs checks that err matches target.

func Errorf

func Errorf(t testing.TB, format string, rest ...any)

Errorf is a local variant to get the right line numbers.

func Fail

func Fail(t testing.TB, msg string, args ...any)

Fail fails the test.

func False

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

False checks bool is false.

func Greater

func Greater(t testing.TB, actual, expected any, msg ...any)

Greater checks that actual is greater than expected.

func IsIncreasing

func IsIncreasing(t testing.TB, value any, msg ...any)

IsIncreasing checks that every item is greater than the item before it.

func Len

func Len(t testing.TB, value any, expected int, msg ...any)

Len checks the length of a string, array, channel, map, or slice.

func Nil

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

Nil checks that value is nil, including a typed nil.

func NoError

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

NoError checks for no errors (nil).

func NotContains

func NotContains(t testing.TB, haystack, needle any, msg ...any)

NotContains checks that needle is not in haystack.

func NotEmpty

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

NotEmpty checks that value is neither nil nor empty.

func NotEqual

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

NotEqual checks for a not equal b.

func NotNil

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

NotNil checks that value is not nil, including a typed nil.

func ObjectsAreEqualValues

func ObjectsAreEqualValues(a, b any) bool

ObjectsAreEqualValues returns true if a == b (through refection).

func Run

func Run(t *testing.T, suite hasT)

Run runs the test suite with SetupTest first and TearDownTest after. Replaces https://pkg.go.dev/github.com/stretchr/testify/suite#Run.

func True

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

True checks bool is true.

Types

type TestSuite

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

TestSuite to be used as base struct for test suites. Replaces https://pkg.go.dev/github.com/stretchr/testify@v1.8.0/suite.

func (*TestSuite) SetT

func (s *TestSuite) SetT(t *testing.T)

SetT sets the testing.T in the suite object.

func (*TestSuite) T

func (s *TestSuite) T() *testing.T

T returns the current testing.T.

Jump to

Keyboard shortcuts

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