assert

package
v0.13.3-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package assert provides value assertions.

Index

Constants

This section is empty.

Variables

View Source
var AppendError = multierror.Append

AppendError is a helper function that will append more errors onto an Error in order to create a larger multi-error.

Functions

func RegisterCustomEqualer

func RegisterCustomEqualer(eq Equaler)

RegisterCustomEqualer appends eq as a custom equaler. Registered equaler will be used when all default equalers judge two values are not equal.

Types

type Assertion

type Assertion interface {
	Assert(v interface{}) error
}

Assertion implements value assertion.

func And

func And(assertions ...Assertion) Assertion

And returns a new assertion to ensure that value passes all assertions. If the assertions are empty, it returns an error.

func Build

func Build(expect interface{}) Assertion

Build creates an assertion from Go value.

func Contains

func Contains(assertion Assertion) Assertion

Contains returns an assertion to ensure a value contains the value.

func Equal

func Equal(expected interface{}) Assertion

Equal returns an assertion to ensure a value equals the expected value.

func Greater

func Greater(expected interface{}) Assertion

Greater returns an assertion to ensure a value greater than the expected value.

func GreaterOrEqual

func GreaterOrEqual(expected interface{}) Assertion

GreaterOrEqual returns an assertion to ensure a value equal or greater than the expected value.

func Length

func Length(expected interface{}) Assertion

Length returns an assertion to ensure a value length is the expected value.

func Less

func Less(expected interface{}) Assertion

Less returns an assertion to ensure a value less than the expected value.

func LessOrEqual

func LessOrEqual(expected interface{}) Assertion

LessOrEqual returns an assertion to ensure a value equal or less than the expected value.

func NotContains

func NotContains(assertion Assertion) Assertion

NotContains returns an assertion to ensure a value doesn't contain the value.

func NotZero

func NotZero() Assertion

NotZero returns an assertion to ensure a value is not zero value.

func Or

func Or(assertions ...Assertion) Assertion

Or returns new assertion to ensure that value passes at least one of assertions. If the assertions are empty, it returns an error.

func Regexp

func Regexp(expr string) Assertion

Regexp returns an assertion to ensure a value matches the regular expression pattern.

type AssertionFunc

type AssertionFunc func(v interface{}) error

AssertionFunc is an adaptor to allow the use of ordinary functions as assertions.

func (AssertionFunc) Assert

func (f AssertionFunc) Assert(v interface{}) error

Assert asserts the v.

type Equaler

type Equaler interface {
	// Equal checks two values are equal or not.
	// If the ok is true, the err should be used as result.
	Equal(expected, got interface{}) (ok bool, err error)
}

Equaler is the interface for custom equaler.

func EqualerFunc

func EqualerFunc(eq func(interface{}, interface{}) (bool, error)) Equaler

EqualerFunc is an adaptor to allow the use of ordinary functions as Equaler.

type Error

type Error = multierror.Error

Error is an error type to track multiple errors.

Jump to

Keyboard shortcuts

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