test

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package test contains some simple utils for more readable tests. It is based on https://github.com/benbjohnson/testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(tb testing.TB, condition bool, msg string, v ...interface{}) bool

Assert fails the test if the condition is false. It returns true, if the test did not fail.

func Equals

func Equals(tb testing.TB, exp, act interface{}, options ...cmp.Option) bool

Equals fails the test if exp is not equal to act. It returns true, if the test did not fail.

func NotEquals added in v0.2.1

func NotEquals(tb testing.TB, exp, act interface{}, options ...cmp.Option) bool

NotEquals fails the test if exp is equal to act. It returns true, if the test did not fail.

func Ok

func Ok(tb testing.TB, err error) bool

Ok fails the test if an err is not nil. It returns true, if the test did not fail.

Types

type ExpectedErrorResult added in v0.2.1

type ExpectedErrorResult int
const (
	// IsCorrectNil is returned if both the expected and the actual
	// error are nil.
	IsCorrectNil ExpectedErrorResult = iota
	// IsCorrectErr is returned if both the expected and the actual
	// error are not nil and identical.
	IsCorrectErr
	// IsWrongErr is returned if the expected and the actual error
	// don't match.
	IsWrongErr
)

func ExpectedError added in v0.2.1

func ExpectedError(tb testing.TB, exp, act error) ExpectedErrorResult

ExpectError checks if the actual error is expected given error, using errors.Is. In all cases the test Fails if expected does not match actual.

The three states are useful if you want to check for errors and do different things based on the result. For example if the actual error is only in some cases not nil and you want to continue execution in that case, but stop on the other cases.

Jump to

Keyboard shortcuts

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