README
¶
testcase/assert
This package meant to provide a small and dependency lightweight implementation for common assertion related requirements.
Example:
assert.Should(tb).True(true)
assert.Must(tb).Equal(expected, actual, "error message")
assert.Must(tb).NotEqual(true, false, "exp")
assert.Must(tb).Contain([]int{1, 2, 3}, 3, "exp")
assert.Must(tb).Contain([]int{1, 2, 3}, []int{1, 2}, "exp")
assert.Must(tb).Contain(map[string]int{"The Answer": 42, "oth": 13}, map[string]int{"The Answer": 42}, "exp")
For more examples, check out the example_test.go file.
Documentation
¶
Index ¶
- type AnyOf
- type Asserter
- func (a Asserter) AnyOf(blk func(a *AnyOf), msg ...interface{})
- func (a Asserter) Contain(src, has interface{}, msg ...interface{})
- func (a Asserter) ContainExactly(expected, actual interface{}, msg ...interface{})
- func (a Asserter) Empty(v interface{}, msg ...interface{})
- func (a Asserter) Equal(expected, actually interface{}, msg ...interface{})
- func (a Asserter) ErrorIs(expected, actual error, msg ...interface{})
- func (a Asserter) False(v bool, msg ...interface{})
- func (a Asserter) Nil(v interface{}, msg ...interface{})
- func (a Asserter) NotContain(source, oth interface{}, msg ...interface{})
- func (a Asserter) NotEmpty(v interface{}, msg ...interface{})
- func (a Asserter) NotEqual(v, oth interface{}, msg ...interface{})
- func (a Asserter) NotNil(v interface{}, msg ...interface{})
- func (a Asserter) NotPanic(blk func(), msg ...interface{})
- func (a Asserter) Panic(blk func(), msg ...interface{}) (panicValue interface{})
- func (a Asserter) True(v bool, msg ...interface{})
- type It
Examples ¶
- AnyOf (FanOutPublishing)
- AnyOf (ListOfCompositedStructuresWhereOnlyTheEmbededValueIsRelevant)
- AnyOf (ListOfInterface)
- AnyOf (ListOfStructuresWithIrrelevantValues)
- AnyOf (StructWithManyAcceptableState)
- Asserter.AnyOf
- Asserter.Contain
- Asserter.ContainExactly
- Asserter.Empty
- Asserter.Equal
- Asserter.Equal (IsEqualFunctionThatSupportsErrorReturning)
- Asserter.Equal (IsEqualFunctionUsedForComparison)
- Asserter.ErrorIs
- Asserter.False
- Asserter.Nil
- Asserter.NotContain
- Asserter.NotEmpty
- Asserter.NotEqual
- Asserter.NotNil
- Asserter.NotPanic
- Asserter.Panic
- Asserter.True
- Must
- Should
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnyOf ¶ added in v0.60.0
type AnyOf struct { TB testing.TB Fn func(...interface{}) // contains filtered or unexported fields }
AnyOf is an assertion helper that allows you run AnyOf.Test assertion blocks, that can fail, as lone at least one of them succeeds. common usage use-cases:
- list of interface, where test order, or the underlying structure's implementation is irrelevant for the behavior.
- list of big structures, where not all field value relevant, only a subset, like a structure it wraps under a field.
- list of structures with fields that has dynamic state values, which is irrelevant for the given test.
- structure that can have various state scenario, and you want to check all of them, and you expect to find one match with the input.
- fan out scenario, where you need to check in parallel that at least one of the worker received the event.
func (*AnyOf) Finish ¶ added in v0.60.0
func (ao *AnyOf) Finish(msg ...interface{})
Finish will check if any of the assertion succeeded.
type Asserter ¶
func (Asserter) ContainExactly ¶
func (a Asserter) ContainExactly(expected, actual interface{}, msg ...interface{})
func (Asserter) Empty ¶ added in v0.61.0
func (a Asserter) Empty(v interface{}, msg ...interface{})
Empty gets whether the specified value is considered empty.
func (Asserter) ErrorIs ¶ added in v0.68.0
ErrorIs allows you to assert an error value by an expectation. if the implementation of the test subject later changes, and for example, it starts to use wrapping, this should not be an issue as the IsEqualErr's error chain is also matched against the expectation.
func (Asserter) NotContain ¶
func (a Asserter) NotContain(source, oth interface{}, msg ...interface{})
func (Asserter) NotEmpty ¶ added in v0.61.0
func (a Asserter) NotEmpty(v interface{}, msg ...interface{})
NotEmpty gets whether the specified value is considered empty.
func (Asserter) NotEqual ¶ added in v0.58.0
func (a Asserter) NotEqual(v, oth interface{}, msg ...interface{})