assert

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

README

assert

This is just a small assert package that has some nice feature I personally need for my projects, such as:

  • Out of the box comparison of protobuf messages
  • Support for generics / type parameters

Documentation

Overview

package assert contains logic to assert test values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equals

func Equals[T comparable](t *testing.T, expected T, actual T) (ok bool)

Equals compares expected to actual and returns true if they are equal. If the expected type is a protobuf message, proto.Equals will be used for comparison. Otherwise, the test fails (but continues) and false is returned.

func EqualsFunc added in v0.0.6

func EqualsFunc[T comparable](t testing.TB, expected T, actual T, equals func(expected T, actual T) bool) (ok bool)

Equals compares expected to actual using the equals function and returns true if they are equal. If the expected type is a protobuf message, proto.Equals will be used for comparison. Otherwise, the test fails (but continues) and false is returned.

func ErrorIs added in v0.0.6

func ErrorIs(t testing.TB, expected error, actual error) bool

ErrorIs asserts that an error is the expected error using errors.Is.

func Is

func Is[T any](t *testing.T, value any) T

Is asserts that value is of type T. If it succeeds, it returns the value casted to T. If it fails, we fatally fail the test, because we cannot continue.

func Nil added in v0.0.2

func Nil(t *testing.T, value any) bool

NotNil asserts that value is nil

func NoError

func NoError(t *testing.T, err error) bool

NoError asserts that err does not contain an error.

func NotEquals added in v0.0.5

func NotEquals[T comparable](t *testing.T, expected T, actual T) (ok bool)

NotEquals compares expected to actual and returns true if they are not equal. If the expected type is a protobuf message, proto.Equals will be used for comparison. Otherwise, the test fails (but continues) and false is returned.

func NotNil added in v0.0.2

func NotNil(t *testing.T, value any) bool

NotNil asserts that value is not nil. If it fails, we fatally fail the test, because we will probably run into a panic otherwise anyway.

Types

type Want

type Want[T any] func(*testing.T, T) bool

Want is a function type that can be executed to chain several assertions together.

Jump to

Keyboard shortcuts

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