testutil

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package testutil provides utilities for writing unit tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal[T comparable](t *testing.T, a, b T)

Equal ensures that arguments compare equal.

func ErrorAs

func ErrorAs[T error](t *testing.T, e error) (as T)

ErrorAs ensures that an error of given type is stored in the given error according to errors.As.

func ErrorIs

func ErrorIs(t *testing.T, e, other error)

ErrorIs ensures that two errors are the same according to errors.Is.

func ErrorMatches

func ErrorMatches(t *testing.T, e error, pattern string)

ErrorMatches ensures that error message of the given error matches the given regular expression.

func NotEqual

func NotEqual[T comparable](t *testing.T, a, b T)

NotEqual ensures that arguments are not equal.

func NotNil

func NotNil[X any, T nullable[X]](t *testing.T, v T)

NotNil ensures that a value is not nil.

func NotOk

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

NotOk ensures that an error is not nil.

func ObjectEqual

func ObjectEqual[T Equatable[T]](t *testing.T, a, b T)

ObjectEqual ensures that two objects compare equal with the Equal method.

func ObjectSliceEqual

func ObjectSliceEqual[T Equatable[T]](t *testing.T, a, b []T)

ObjectSliceEqual ensures that two slices have the same length and that their elements compare equal with the Equal method.

func Ok

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

Ok ensures that an error is nil.

func PanicMatches

func PanicMatches(t *testing.T, fn func(), pattern string)

PanicMatches ensures that function panics with a message that matches the given regular expression.

func SliceHasLen

func SliceHasLen[T any](t *testing.T, v []T, length int)

SliceHasLen ensures that the argument has given length.

func SlicesEqual

func SlicesEqual[T comparable](t *testing.T, a, b []T)

SlicesEqual ensures that two slices have the same length and that their elements compare equal.

Types

type Equatable

type Equatable[T any] interface {
	Equal(T) bool
}

Equatable is the interface that wraps the Equal method.

Jump to

Keyboard shortcuts

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