Documentation
¶
Index ¶
- Variables
- func Assert(tb T, condition bool, msg string, v ...interface{})
- func CreateDirectory(path string)
- func Equals(tb T, expected, actual interface{})
- func JSONEquals(tb T, expected, actual []byte)
- func JSONEqualsString(tb T, expected string, actual interface{})
- func MustFail(tb T, err error, msg string, v ...interface{})
- func MustFailWith(tb T, err error, expectedError error)
- func NewService(cleanup func() error) *serviceWrapper
- func Ok(tb T, err error)
- func RandomArray(i, length int) []byte
- type DefaultServices
- type DefaultTestTools
- type FileServices
- type RandomServices
- type Service
- type StringSubTest
- type SubTest
- type T
- type TempDir
- type TestTools
- func (tt *TestTools) AddService(s Service)
- func (tt *TestTools) Assert(condition bool, msg string, v ...interface{})
- func (tt *TestTools) EndSubTest()
- func (tt *TestTools) Equals(expected, actual interface{})
- func (tt *TestTools) EqualsFile(file string, actual interface{})
- func (tt *TestTools) EqualsKey(key string, actual interface{})
- func (tt *TestTools) EqualsTextFile(file string, actual string)
- func (tt *TestTools) Error(err error)
- func (tt *TestTools) Fatal(args ...interface{})
- func (tt *TestTools) Fatalf(formatString string, args ...interface{})
- func (tt *TestTools) FinishTest()
- func (tt *TestTools) Go(subroutine func())
- func (tt *TestTools) JSONBytesEqualsFile(file string, actual []byte)
- func (tt *TestTools) JSONEquals(expected, actual []byte)
- func (tt *TestTools) JSONEqualsFile(file string, actual interface{})
- func (tt *TestTools) MustFail(err error, msg string, v ...interface{})
- func (tt *TestTools) MustFailWith(err error, expectedError error)
- func (tt *TestTools) MustPanic(f func())
- func (tt *TestTools) MustPanicWith(expectedMessage interface{}, f func())
- func (tt *TestTools) Ok(err error)
- func (tt *TestTools) RoutineEnd()
- func (tt *TestTools) RoutineStart()
- func (tt *TestTools) StartSubTest(fmtString string, args ...interface{})
- func (tt *TestTools) TestJSONMarshaller(filename string, sample interface{})
Constants ¶
This section is empty.
Variables ¶
var GENERATE_RESULTS bool
GENERATE_RESULTS is a global flag that haves all tests generate test results rather than verify them
var Internal internal
Internal defines test functions that can be used to build other test functions It is built as a struct to avoid polluting the namespace These functions just make checks or print messages, they don't stop the test
Functions ¶
func CreateDirectory ¶
func CreateDirectory(path string)
CreateDirectory creates a directory and all necessary parents.
func Equals ¶
func Equals(tb T, expected, actual interface{})
Equals fails the test if exp is not equal to act.
func JSONEquals ¶
JSONEquals fails if provided JSONs are not equivalent
func JSONEqualsString ¶
JSONEqualsString performs a JSON comparison of the given object with the JSON contained in the referenced string
func MustFailWith ¶
MustFailWith checks if err equals an expected error. If not, it will fail the test.
func NewService ¶
func NewService(cleanup func() error) *serviceWrapper
func RandomArray ¶
RandomArray returns a deterministically generated random array so values are the same across tests.
Types ¶
type DefaultServices ¶
type DefaultServices struct { *FileServices RandomServices }
type DefaultTestTools ¶
type DefaultTestTools struct { *TestTools Services *DefaultServices }
type FileServices ¶
type FileServices struct {
// contains filtered or unexported fields
}
func NewFileServices ¶
func NewFileServices(t *TestTools) *FileServices
func (*FileServices) NewTempDir ¶
func (fs *FileServices) NewTempDir() string
func (*FileServices) NewTempFile ¶
func (fs *FileServices) NewTempFile() string
type RandomServices ¶
type RandomServices struct{}
func (*RandomServices) RandomArray ¶
func (rs *RandomServices) RandomArray(i, length int) []byte
RandomArray returns a deterministically seeded random array of the given length
type Service ¶
type Service interface {
Close() error
}
Service is an interface to define a test service that needs cleanup on finish
type StringSubTest ¶
type StringSubTest string
StringSubTest is a simple subtest that is a string
func (*StringSubTest) String ¶
func (ss *StringSubTest) String() string
type T ¶
type T interface { Error(args ...interface{}) Errorf(format string, args ...interface{}) Fail() FailNow() Failed() bool Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) Log(args ...interface{}) Logf(format string, args ...interface{}) Name() string }
T is a interface to *testing.T with the minimal set of methods needed
type TestTools ¶
type TestTools struct { T W sync.WaitGroup SubTest SubTest TestdataDir string Results results // contains filtered or unexported fields }
TestTools is a replacement for testing.T that adds useful testing methods
func ToolsBeginTest ¶
ToolsBeginTest takes a *testing.T and returns a replacement TestTools. Don't forget to defer t.FinishTest() to ensure cleanup
func (*TestTools) AddService ¶
AddService adds a service that will be cleaned up when the test ends for any reason.
func (*TestTools) EndSubTest ¶
func (tt *TestTools) EndSubTest()
EndSubTest indicates a subtest has finished
func (*TestTools) Equals ¶
func (tt *TestTools) Equals(expected, actual interface{})
Equals tests if both objects are "deeply equal", otherwise it fails the test
func (*TestTools) EqualsFile ¶
EqualsFile checks if the passed "actual" value is equivalent to its JSON version contained in the indicated file in the current test's testadata folder
func (*TestTools) EqualsKey ¶
EqualsKey verifies if the passed "actual" value is equal to the value in the given key of the current test's results.json
func (*TestTools) EqualsTextFile ¶
EqualsTextFile checks if the passed "actual" value is equivalent to the text contained in the indicated file in the current test's testadata folder
func (*TestTools) Fatal ¶
func (tt *TestTools) Fatal(args ...interface{})
Fatal will fail the test immediately with an error message
func (*TestTools) FinishTest ¶
func (tt *TestTools) FinishTest()
FinishTest waits for all test goroutines and cleans up
func (*TestTools) JSONBytesEqualsFile ¶
JSONBytesEqualsFile performs a JSON comparison of the provided JSON bytes with the JSON contained in the referenced file
func (*TestTools) JSONEquals ¶
JSONEquals checks if the passed values are JSON-equal, comparing values taking into account keys can be in different order, etc.
func (*TestTools) JSONEqualsFile ¶
JSONEqualsFile performs a JSON comparison of the given object with the JSON contained in the referenced file
func (*TestTools) MustFailWith ¶
MustFailWith checks if err equals an expected error. If not, it will fail the test.
func (*TestTools) MustPanic ¶
func (tt *TestTools) MustPanic(f func())
MustPanic runs a function and checks that it panics
func (*TestTools) MustPanicWith ¶
func (tt *TestTools) MustPanicWith(expectedMessage interface{}, f func())
MustPanicWith runs a function and checks that it panics throwing a specific value
func (*TestTools) RoutineEnd ¶
func (tt *TestTools) RoutineEnd()
RoutineEnd notifies a child goroutine is finished
func (*TestTools) RoutineStart ¶
func (tt *TestTools) RoutineStart()
RoutineStart adds one to the goroutine waiting counter
func (*TestTools) StartSubTest ¶
StartSubTest marks the beginning of a new subtest
func (*TestTools) TestJSONMarshaller ¶
TestJSONMarshaller is a convenient tool to test JSON marshalling/unmarshalling matching the marshalled data to the referenced file.