test

package module
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: MIT Imports: 9 Imported by: 0

README

test: A Go testing package

Go Reference codecov gosec Go Report Card

Installation

go get github.com/broothie/test@latest

Documentation

Detailed documentation can be found at pkg.go.dev.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BetweenExclusive added in v0.1.4

func BetweenExclusive[T cmp.Ordered](t TestingT, actual, lower, upper T) bool

BetweenExclusive asserts that a value is between two values (exclusive).

func BetweenInclusive added in v0.1.4

func BetweenInclusive[T cmp.Ordered](t TestingT, actual, lower, upper T) bool

BetweenInclusive asserts that a value is between two values (inclusive).

func ContainedIn added in v0.1.5

func ContainedIn[T comparable, S ~[]T](t TestingT, actual T, expected S) bool

ContainedIn asserts that an element is contained in a slice.

func ContainedInEntries added in v0.1.5

func ContainedInEntries[K, V comparable, M ~map[K]V](t TestingT, actualKey K, actualValue V, expected M) bool

ContainedInEntries asserts that a key-value pair is contained in a map.

func ContainedInKeys added in v0.1.5

func ContainedInKeys[K comparable, V any, M ~map[K]V](t TestingT, actual K, expected M) bool

ContainedInKeys asserts that a key is contained in a map.

func ContainedInValues added in v0.1.5

func ContainedInValues[K, V comparable, M ~map[K]V](t TestingT, actual V, expected M) bool

ContainedInValues asserts that a value is contained in a map.

func Contains added in v0.1.4

func Contains[T comparable, S ~[]T](t TestingT, actual S, expected T) bool

Contains asserts that a slice contains an expected element.

func ContainsEntry added in v0.1.4

func ContainsEntry[K, V comparable, M ~map[K]V](t TestingT, actual M, expectedKey K, expectedValue V) bool

ContainsEntry asserts that a map contains an expected key-value pair.

func ContainsKey added in v0.1.4

func ContainsKey[K comparable, V any, M ~map[K]V](t TestingT, actual M, expected K) bool

ContainsKey asserts that a map contains an expected key.

func ContainsValue added in v0.1.4

func ContainsValue[K, V comparable, M ~map[K]V](t TestingT, actual M, expected V) bool

ContainsValue asserts that a map contains an expected value.

func DeepEqual

func DeepEqual(t TestingT, actual, expected any) bool

DeepEqual asserts that two values are deeply equal using reflect.DeepEqual.

func Equal

func Equal[T comparable](t TestingT, actual, expected T) bool

Equal asserts that two comparable values are equal.

func ErrorIs

func ErrorIs(t TestingT, actual, expected error) bool

ErrorIs asserts that an error matches another error using errors.Is.

func ErrorMessageIs added in v0.1.4

func ErrorMessageIs(t TestingT, actual error, expected string) bool

ErrorMessageIs asserts that an error's message matches the expected string.

func False

func False(t TestingT, actual bool) bool

False asserts that the actual value is false.

func GreaterThan added in v0.1.4

func GreaterThan[T cmp.Ordered](t TestingT, actual, expected T) bool

GreaterThan asserts that a value is greater than another value.

func GreaterThanOrEqual added in v0.1.4

func GreaterThanOrEqual[T cmp.Ordered](t TestingT, actual, expected T) bool

GreaterThanOrEqual asserts that a value is greater than or equal to another value.

func LessThan added in v0.1.4

func LessThan[T cmp.Ordered](t TestingT, actual, expected T) bool

LessThan asserts that a value is less than another value.

func LessThanOrEqual added in v0.1.4

func LessThanOrEqual[T cmp.Ordered](t TestingT, actual, expected T) bool

LessThanOrEqual asserts that a value is less than or equal to another value.

func MapEmpty added in v0.1.6

func MapEmpty[K comparable, V any, M ~map[K]V](t TestingT, actual M) bool

func MapLen added in v0.1.6

func MapLen[K comparable, V any, M ~map[K]V](t TestingT, actual M, expected int) bool

func Match added in v0.1.4

func Match[Actual any](t TestingT, actual Actual, matcher Matcher[Actual]) bool

Match asserts that a value matches a custom matcher.

func Must

func Must[T any](t TestingT, f func() (T, error)) T

Must runs a function that returns a value and error, fails immediately if error is not nil.

func MustNoError

func MustNoError(t TestingT, err error)

MustNoError fails the test immediately if the error is not nil.

func Nil added in v0.1.5

func Nil(t TestingT, actual any) bool

Nil asserts that a value is nil.

func NoError

func NoError(t TestingT, err error) bool

NoError asserts that an error is nil.

func NotContainedIn added in v0.1.5

func NotContainedIn[T comparable, S ~[]T](t TestingT, actual T, expected S) bool

NotContainedIn asserts that an element is not contained in a slice.

func NotContainedInEntries added in v0.1.5

func NotContainedInEntries[K, V comparable, M ~map[K]V](t TestingT, actualKey K, actualValue V, expected M) bool

NotContainedInEntries asserts that a key-value pair is not contained in a map.

func NotContainedInKeys added in v0.1.5

func NotContainedInKeys[K comparable, V any, M ~map[K]V](t TestingT, actual K, expected M) bool

NotContainedInKeys asserts that a key is not contained in a map.

func NotContainedInValues added in v0.1.5

func NotContainedInValues[K, V comparable, M ~map[K]V](t TestingT, actual V, expected M) bool

NotContainedInValues asserts that a value is not contained in a map.

func NotContains added in v0.1.4

func NotContains[T comparable, S ~[]T](t TestingT, actual S, expected T) bool

NotContains asserts that a slice does not contain an expected element.

func NotContainsEntry added in v0.1.4

func NotContainsEntry[K, V comparable, M ~map[K]V](t TestingT, actual M, expectedKey K, expectedValue V) bool

NotContainsEntry asserts that a map does not contain an expected key-value pair.

func NotContainsKey added in v0.1.4

func NotContainsKey[K comparable, V any, M ~map[K]V](t TestingT, actual M, expected K) bool

NotContainsKey asserts that a map does not contain an expected key.

func NotContainsValue added in v0.1.4

func NotContainsValue[K, V comparable, M ~map[K]V](t TestingT, actual M, expected V) bool

NotContainsValue asserts that a map does not contain an expected value.

func NotDeepEqual added in v0.1.4

func NotDeepEqual(t TestingT, actual, expected any) bool

NotDeepEqual asserts that two values are not deeply equal.

func NotEqual added in v0.1.4

func NotEqual[T comparable](t TestingT, actual, expected T) bool

NotEqual asserts that two comparable values are not equal.

func NotErrorIs added in v0.1.4

func NotErrorIs(t TestingT, actual, expected error) bool

NotErrorIs asserts that an error does not match another error using errors.Is.

func NotErrorMessageIs added in v0.1.4

func NotErrorMessageIs(t TestingT, actual error, expected string) bool

NotErrorMessageIs asserts that an error's message does not match the expected string.

func NotMapEmpty added in v0.1.6

func NotMapEmpty[K comparable, V any, M ~map[K]V](t TestingT, actual M) bool

func NotNil added in v0.1.4

func NotNil(t TestingT, actual any) bool

NotNil asserts that a value is not nil.

func NotRegexpMatch added in v0.1.4

func NotRegexpMatch(t TestingT, actual string, expected *regexp.Regexp) bool

NotRegexpMatch asserts that a string does not match a regular expression.

func NotSliceEmpty added in v0.1.6

func NotSliceEmpty[T any, S ~[]T](t TestingT, actual S) bool

func NotZero added in v0.1.5

func NotZero(t TestingT, actual any) bool

NotZero asserts that a value does not equal its zero value. Works with any type by using reflection.

func RegexpMatch added in v0.1.4

func RegexpMatch(t TestingT, actual string, expected *regexp.Regexp) bool

RegexpMatch asserts that a string matches a regular expression.

func SliceEmpty added in v0.1.6

func SliceEmpty[T any, S ~[]T](t TestingT, actual S) bool

func SliceLen added in v0.1.6

func SliceLen[T any, S ~[]T](t TestingT, actual S, expected int) bool

func True

func True(t TestingT, actual bool) bool

True asserts that the actual value is true.

func Zero added in v0.1.5

func Zero(t TestingT, actual any) bool

Zero asserts that a value equals its zero value. Works with any type by using reflection.

Types

type Matcher added in v0.1.4

type Matcher[Actual any] interface {
	Match(actual Actual) (bool, string)
}

Matcher is an interface for custom matchers that can match against a value.

type MatcherFunc added in v0.1.4

type MatcherFunc[Actual any] func(actual Actual) (bool, string)

MatcherFunc is a function type that implements Matcher.

func (MatcherFunc[Actual]) Match added in v0.1.4

func (f MatcherFunc[Actual]) Match(actual Actual) (bool, string)

type TestingT

type TestingT interface {
	Helper()
	Error(args ...any)
	FailNow()
}

TestingT is an interface wrapper around *testing.T.

Directories

Path Synopsis
Package mocktesting is a generated GoMock package.
Package mocktesting is a generated GoMock package.

Jump to

Keyboard shortcuts

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