assert

package
v0.0.0-...-680e691 Latest Latest
Warning

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

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

README

assert

出处

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(t T, list interface{}, element interface{}, argAndOpts ...interface{}) bool

func DirExists

func DirExists(t T, path string, argAndOpts ...interface{}) bool

DirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.

func Empty

func Empty(t T, object interface{}, argAndOpts ...interface{}) bool

Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either a slice or a channel with len == 0.

assert.Empty(t, obj)

func Equal

func Equal(t T, expected, actual interface{}, argAndOpts ...interface{}) bool

func False

func False(t T, value bool, argAndOpts ...interface{}) bool

False asserts that the specified value is false.

assert.False(t, myBool)

func FileExists

func FileExists(t T, path string, argAndOpts ...interface{}) bool

func Greater

func Greater(t T, expected, actual interface{}, argAndOpts ...interface{}) bool

Greater asserts that the first element is greater than the second

assert.Greater(t, 2, 1)
assert.Greater(t, float64(2), float64(1))
assert.Greater(t, "b", "a")

func GreaterEqual

func GreaterEqual(t T, expected, actual interface{}, argAndOpts ...interface{}) bool

func IsDecreasing

func IsDecreasing(t T, object interface{}, argAndOpts ...interface{}) bool

IsDecreasing asserts that the collection is decreasing

assert.IsDecreasing(t, []int{2, 1, 0})
assert.IsDecreasing(t, []float{2, 1})
assert.IsDecreasing(t, []string{"b", "a"})

func IsIncreasing

func IsIncreasing(t T, object interface{}, argAndOpts ...interface{}) bool

IsIncreasing asserts that the collection is increasing

assert.IsIncreasing(t, []int{1, 2, 3})
assert.IsIncreasing(t, []float{1, 2})
assert.IsIncreasing(t, []string{"a", "b"})

func IsNonDecreasing

func IsNonDecreasing(t T, object interface{}, argAndOpts ...interface{}) bool

IsNonDecreasing asserts that the collection is not decreasing

assert.IsNonDecreasing(t, []int{1, 1, 2})
assert.IsNonDecreasing(t, []float{1, 2})
assert.IsNonDecreasing(t, []string{"a", "b"})

func IsNonIncreasing

func IsNonIncreasing(t T, object interface{}, argAndOpts ...interface{}) bool

IsNonIncreasing asserts that the collection is not increasing

assert.IsNonIncreasing(t, []int{2, 1, 1})
assert.IsNonIncreasing(t, []float{2, 1})
assert.IsNonIncreasing(t, []string{"b", "a"})

func IsType

func IsType(t T, expectedType interface{}, object interface{}, argAndOpts ...interface{}) bool

IsType asserts that the specified objects are of the same type.

func Len

func Len(t T, object interface{}, length int, argAndOpts ...interface{}) bool

Len asserts that the specified object has specific length. Len also fails if the object has a type that len() not accept.

assert.Len(t, mySlice, 3)

func Less

func Less(t T, expected, actual interface{}, argAndOpts ...interface{}) bool

func LessEqual

func LessEqual(t T, expected, actual interface{}, argAndOpts ...interface{}) bool

func Negative

func Negative(t T, expected interface{}, argAndOpts ...interface{}) bool

Negative asserts that the specified element is negative

assert.Negative(t, -1)
assert.Negative(t, -1.23)

func Nil

func Nil(t T, object interface{}, argAndOpts ...interface{}) bool

Nil asserts that the specified object is nil.

assert.Nil(t, err)

func NoDirExists

func NoDirExists(t T, path string, argAndOpts ...interface{}) bool

func NoFileExists

func NoFileExists(t T, path string, argAndOpts ...interface{}) bool

func NotEmpty

func NotEmpty(t T, object interface{}, argAndOpts ...interface{}) bool

NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either a slice or a channel with len == 0.

if assert.NotEmpty(t, obj) {
  assert.Equal(t, "two", obj[1])
}

func NotEqual

func NotEqual(t T, expected, actual interface{}, argAndOpts ...interface{}) bool

func NotNil

func NotNil(t T, object interface{}, argAndOpts ...interface{}) bool

NotNil asserts that the specified object is not nil.

assert.NotNil(t, err)

func NotSame

func NotSame(t T, expected, actual interface{}, argAndOpts ...interface{}) bool

NotSame asserts that two pointers do not reference the same object.

assert.NotSame(t, ptr1, ptr2)

Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.

func NotZero

func NotZero(t T, object interface{}, argAndOpts ...interface{}) bool

NotZero .

func Positive

func Positive(t T, expected interface{}, argAndOpts ...interface{}) bool

Positive asserts that the specified element is positive

assert.Positive(t, 1)
assert.Positive(t, 1.23)

func Same

func Same(t T, expected, actual interface{}, argAndOpts ...interface{}) bool

Same asserts that two pointers reference the same object.

assert.Same(t, ptr1, ptr2)

Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.

func True

func True(t T, value bool, argAndOpts ...interface{}) bool

True asserts that the specified value is true.

assert.True(t, myBool)

func Zero

func Zero(t T, object interface{}, argAndOpts ...interface{}) bool

Zero

Types

type Assertion

type Assertion struct {
	// contains filtered or unexported fields
}

Assertions provides assertion methods around the TestingT interface.

func New

func New(t T, opts ...Option) *Assertion

New .

func (*Assertion) Contains

func (a *Assertion) Contains(s interface{}, contains interface{}, argAndOpts ...interface{}) bool

func (*Assertion) DirExists

func (a *Assertion) DirExists(path string, argAndOpts ...interface{}) bool

func (*Assertion) Empty

func (a *Assertion) Empty(object interface{}, argAndOpts ...interface{}) bool

func (*Assertion) Equal

func (a *Assertion) Equal(expected, actual interface{}, argAndOpts ...interface{}) bool

func (*Assertion) False

func (a *Assertion) False(value bool, argAndOpts ...interface{}) bool

func (*Assertion) FileExists

func (a *Assertion) FileExists(path string, argAndOpts ...interface{}) bool

func (*Assertion) Greater

func (a *Assertion) Greater(expected, actual interface{}, argAndOpts ...interface{}) bool

func (*Assertion) GreaterEqual

func (a *Assertion) GreaterEqual(expected, actual interface{}, argAndOpts ...interface{}) bool

func (*Assertion) IsDecreasing

func (a *Assertion) IsDecreasing(expected interface{}, argAndOpts ...interface{}) bool

func (*Assertion) IsIncreasing

func (a *Assertion) IsIncreasing(expected interface{}, argAndOpts ...interface{}) bool

func (*Assertion) IsNonDecreasing

func (a *Assertion) IsNonDecreasing(expected interface{}, argAndOpts ...interface{}) bool

func (*Assertion) IsNonIncreasing

func (a *Assertion) IsNonIncreasing(expected interface{}, argAndOpts ...interface{}) bool

func (*Assertion) IsType

func (a *Assertion) IsType(expected, object interface{}, argAndOpts ...interface{}) bool

func (*Assertion) Len

func (a *Assertion) Len(object interface{}, length int, argAndOpts ...interface{}) bool

func (*Assertion) Less

func (a *Assertion) Less(expected, actual interface{}, argAndOpts ...interface{}) bool

func (*Assertion) LessEqual

func (a *Assertion) LessEqual(expected, actual interface{}, argAndOpts ...interface{}) bool

func (*Assertion) Negative

func (a *Assertion) Negative(expected interface{}, argAndOpts ...interface{}) bool

func (*Assertion) Nil

func (a *Assertion) Nil(object interface{}, argAndOpts ...interface{}) bool

func (*Assertion) NoDirExists

func (a *Assertion) NoDirExists(path string, argAndOpts ...interface{}) bool

func (*Assertion) NoFileExists

func (a *Assertion) NoFileExists(path string, argAndOpts ...interface{}) bool

func (*Assertion) NotEmpty

func (a *Assertion) NotEmpty(object interface{}, argAndOpts ...interface{}) bool

func (*Assertion) NotEqual

func (a *Assertion) NotEqual(expected, actual interface{}, argAndOpts ...interface{}) bool

func (*Assertion) NotNil

func (a *Assertion) NotNil(object interface{}, argAndOpts ...interface{}) bool

func (*Assertion) NotSame

func (a *Assertion) NotSame(expected, object interface{}, argAndOpts ...interface{}) bool

func (*Assertion) NotZero

func (a *Assertion) NotZero(object interface{}, argAndOpts ...interface{}) bool

func (*Assertion) Positive

func (a *Assertion) Positive(expected interface{}, argAndOpts ...interface{}) bool

func (*Assertion) Same

func (a *Assertion) Same(expected, object interface{}, argAndOpts ...interface{}) bool

func (*Assertion) True

func (a *Assertion) True(value bool, argAndOpts ...interface{}) bool

func (*Assertion) Zero

func (a *Assertion) Zero(object interface{}, argAndOpts ...interface{}) bool

type Option

type Option func(o *Options)

func WithFailNow

func WithFailNow() Option

WithFailNow .

func WithLoose

func WithLoose() Option

WithLoose .

type Options

type Options struct {
	// contains filtered or unexported fields
}

type T

type T interface {
	// Fail indicates that the test has failed but
	// allowed execution to continue.
	Fail()
	// FailNow indicates that the test has failed and
	// aborts the test.
	// FailNow is called in strict mode (via New).
	FailNow()
}

T reports when failures occur. testing.T implements this interface.

Jump to

Keyboard shortcuts

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