testx

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convey

func Convey(description string, t *testing.T, f func())

func Eval

func Eval(f assert.EvalFunc, msgAndArgs ...interface{}) bool

Eval uses a EvalFunc to assert a complex condition.

func Fail

func Fail(failureMessage string, msgAndArgs ...interface{}) bool

Fail reports a failure through

func FailNow

func FailNow(failureMessage string, msgAndArgs ...interface{}) bool

FailNow fails test

func InDelta

func InDelta(expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool

InDelta asserts that the two numerals are within delta of each other.

InDelta(math.Pi, (22 / 7.0), 0.01)

func IsType

func IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool

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

func JsonShouldEq

func JsonShouldEq(expected string, actual string, msgAndArgs ...interface{}) bool

JSONEq asserts that two JSON strings are equivalent.

JsonShouldEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)

func Log

func Log() log.ILogger

func MarshalJSON added in v1.0.8

func MarshalJSON(obj interface{}) string

func MarshalJSONIndent added in v1.0.8

func MarshalJSONIndent(obj interface{}) string

func MarshalYAML added in v1.0.8

func MarshalYAML(obj interface{}) string

func OnFailure added in v1.0.5

func OnFailure(handler func())

OnFailure registers a callback that will be executed if a test fails

func PrintObj added in v1.0.6

func PrintObj(msg string, obj interface{}, writer ...io.Writer)

func ShouldBeEmpty

func ShouldBeEmpty(object interface{}, msgAndArgs ...interface{}) bool

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

ShouldBeEmpty(obj)

func ShouldBeFalse

func ShouldBeFalse(value bool, msgAndArgs ...interface{}) bool

ShouldBeFalse asserts that the specified value is false.

ShouldBeFalse(myBool)

func ShouldBeNil

func ShouldBeNil(object interface{}, msgAndArgs ...interface{}) bool

ShouldBeNil asserts that the specified object is nil.

ShouldBeNil(err)

func ShouldBeTrue

func ShouldBeTrue(value bool, msgAndArgs ...interface{}) bool

ShouldBeTrue asserts that the specified value is true.

ShouldBeTrue(myBool)

func ShouldContain

func ShouldContain(s, contains interface{}, msgAndArgs ...interface{}) bool

ShouldContain asserts that the specified string, list(array, slice...) or map contains the specified substring or element.

ShouldContain("Hello World", "World")
ShouldContain(["Hello", "World"], "World")
ShouldContain({"Hello": "World"}, "Hello")

func ShouldEqual

func ShouldEqual(expected, actual interface{}, msgAndArgs ...interface{}) bool

ShouldEqual asserts that two objects are equal.

ShouldEqual(123, 123)

Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses). Function equality cannot be determined and will always fail.

func ShouldEqualError

func ShouldEqualError(err error, errString string, msgAndArgs ...interface{}) bool

ShouldEqualError asserts that a function returned an error (i.e. not `nil`) and that it is equal to the provided error.

actualObj, err := SomeFunction()
ShouldEqualError(err,  expectedErrorString)

func ShouldEqualValues

func ShouldEqualValues(expected, actual interface{}, msgAndArgs ...interface{}) bool

EqualValues asserts that two objects are equal or convertable to the same types and equal.

EqualValues(uint32(123), int32(123))

func ShouldError

func ShouldError(err error, msgAndArgs ...interface{}) bool

ShouldError asserts that a function returned an error (i.e. not `nil`).

actualObj, err := SomeFunction()
if ShouldError(err) {
    ShouldEqual(expectedError, err)
}

func ShouldHaveSubset

func ShouldHaveSubset(list, subset interface{}, msgAndArgs ...interface{}) (ok bool)

ShouldHaveSubset asserts that the specified list(array, slice...) contains all elements given in the specified subset(array, slice...).

ShouldHaveSubset([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")

func ShouldImplement

func ShouldImplement(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool

ShouldImplement asserts that an object is implemented by the specified interface.

ShouldImplement((*MyInterface)(nil), new(MyObject))

func ShouldLen

func ShouldLen(object interface{}, length int, msgAndArgs ...interface{}) bool

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

ShouldLen(mySlice, 3)

func ShouldMatchElements

func ShouldMatchElements(listA, listB interface{}, msgAndArgs ...interface{}) bool

ShouldMatchElements asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.

ShouldMatchElements([1, 3, 2, 3], [1, 3, 3, 2])

func ShouldMatchExactly

func ShouldMatchExactly(expected, actual interface{}, msgAndArgs ...interface{}) bool

ShouldMatchExactly asserts that two objects are equal in value and type.

ShouldMatchExactly(int32(123), int64(123))

func ShouldMatchRegexp

func ShouldMatchRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool

ShouldMatchRegexp asserts that a specified regexp matches a string.

ShouldMatchRegexp(regexp.MustCompile("start"), "it's starting")
ShouldMatchRegexp("start...$", "it's not starting")

func ShouldNotBeEmpty

func ShouldNotBeEmpty(object interface{}, msgAndArgs ...interface{}) bool

ShouldNotBeEmpty 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 ShouldNotBeEmpty(obj) {
   ShouldBeEqual("two", obj[1])
}

func ShouldNotBeEqual

func ShouldNotBeEqual(expected, actual interface{}, msgAndArgs ...interface{}) bool

ShouldNotBeEqual asserts that the specified values are NOT equal.

ShouldNotBeEqual(obj1, obj2)

Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses).

func ShouldNotBeNil

func ShouldNotBeNil(object interface{}, msgAndArgs ...interface{}) bool

ShouldNotBeNil asserts that the specified object is not nil.

ShouldNotBeNil(err)

func ShouldNotContain

func ShouldNotContain(s, contains interface{}, msgAndArgs ...interface{}) bool

ShouldNotContain asserts that the specified string, list(array, slice...) or map does NOT contain the specified substring or element.

ShouldNotContain("Hello World", "Earth")
ShouldNotContain(["Hello", "World"], "Earth")
ShouldNotContain({"Hello": "World"}, "Earth")

func ShouldNotError

func ShouldNotError(err error, msgAndArgs ...interface{}) bool

ShouldNotError asserts that a function returned no error (i.e. `nil`).

actualObj, err := SomeFunction()
if ShouldNotError(err) {
    ShouldEqual(expectedObj, actualObj)
}

func ShouldNotHaveSubset

func ShouldNotHaveSubset(list, subset interface{}, msgAndArgs ...interface{}) (ok bool)

ShouldNotHaveSubset asserts that the specified list(array, slice...) contains not all elements given in the specified subset(array, slice...).

ShouldNotHaveSubset([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")

func ShouldNotMatchRegexp

func ShouldNotMatchRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool

ShouldNotMatchRegexp asserts that a specified regexp does not match a string.

ShouldNotMatchRegexp(regexp.MustCompile("starts"), "it's starting")
ShouldNotMatchRegexp("^start", "it's not starting")

func ShouldNotPanic

func ShouldNotPanic(f assert.PanicTestFunc, msgAndArgs ...interface{}) bool

ShouldNotPanic asserts that the code inside the specified PanicTestFunc does NOT panic.

ShouldNotPanic(func(){ RemainCalm() })

func ShouldNotZero

func ShouldNotZero(i interface{}, msgAndArgs ...interface{}) bool

NotZero asserts that i is not the zero value for its type.

func ShouldPanic

func ShouldPanic(f assert.PanicTestFunc, msgAndArgs ...interface{}) bool

ShouldPanic asserts that the code inside the specified PanicTestFunc panics.

ShouldPanic(func(){ GoCrazy() })

func ShouldPanicWithValue

func ShouldPanicWithValue(expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) bool

ShouldPanicWithValue asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value equals the expected panic value.

ShouldPanicWithValue("crazy error", func(){ GoCrazy() })

func ShouldZero

func ShouldZero(i interface{}, msgAndArgs ...interface{}) bool

ShouldZero asserts that i is the zero value for its type.

func WithinDuration

func WithinDuration(expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool

WithinDuration asserts that the two times are within duration delta of each other.

WithinDuration(time.Now(), time.Now(), 10*time.Second)

Types

This section is empty.

Jump to

Keyboard shortcuts

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