Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // PanicExpected indicates that the function being tested is expected to panic. PanicExpected = errors.New("panic expected") // ErrAny indicates that the function being tested is expected to return an (unspecified) error. ErrAny = errors.New("any error expected") // CustomTest indicates that you want to perform your own test inside the Run1, RunErr or Run2 function. // You will be expected to signify when a test failed yourself i.e. using t.Errorf(...). CustomTest = errors.New("custom test") )
Functions ¶
Types ¶
type Comparator ¶
type Comparator func(x, y interface{}) bool
Comparator returns true if x and y are equal (as determined by the Comparator function). x and y are the returned and expected value respectively from a function being tested. The default Comparator uses reflect.DeepEqual. However the github.com/google/go-cmp package may also be used. See: https://github.com/google/go-cmp.
type ErrContains ¶
type ErrContains struct{ Substr string }
ErrContains is used to check if the observed error contains a particular substring. It uses strings.Contains().
Example:
testCases := []struct { in bool ExpErr error }{ {false, ErrContains{"database error"}}, }
type Is ¶
type Is struct{ Err error }
Is indicates that errors.Is() be used to test if an expected error matches the observed error. When not set, a simple equality check is performed using reflect.DeepEqual.
type Not ¶
type Not struct{ Val interface{} }
Not means the expected value/error is expected to be not equal.
Example:
testCases := []struct { in bool ExpErr error }{ {false, Not{ErrContains{"database error"}}}, }
type TestConfig ¶
type TestConfig struct { C Comparator Fatal bool // contains filtered or unexported fields }
TestConfig ...
See ret1_test.go file for usage example.
func NewTestConfig ¶
func NewTestConfig(t *testing.T) *TestConfig
NewTestConfig creates a new TestConfig.
func (TestConfig) Run1 ¶
func (tcfg TestConfig) Run1(name string, tc interface{}, f func(t *testing.T) interface{})
Run1 is used when testing a function that returns a single (non-error) value.
See ret1_test.go file for usage example.