Documentation ¶
Overview ¶
Convenience utilities for testing.
Index ¶
- Constants
- Variables
- func AssertCloses(t TestingT, c io.Closer)
- func AssertErrorContains(t TestingT, err error, substr string)
- func EventuallyConsistent(duration time.Duration, f func() error) error
- func GetRepoRoot(t TestingT) string
- func LargeTest(t TestingT)
- func LocalOnlyTest(t TestingT)
- func ManualTest(t TestingT)
- func MarshalIndentJSON(t TestingT, i interface{}) string
- func MarshalJSON(t TestingT, i interface{}) string
- func MediumTest(t TestingT)
- func MustReadFile(filename string) string
- func MustReadJsonFile(filename string, dest interface{})
- func ReadFile(filename string) (string, error)
- func ReadJsonFile(filename string, dest interface{}) error
- func Remove(t TestingT, fp string)
- func RemoveAll(t TestingT, fp string)
- func ShouldRun(testType string) bool
- func SmallTest(t TestingT)
- func TempDir(t TestingT) (string, func())
- func TestDataDir() (string, error)
- func WriteFile(t TestingT, filename, contents string)
- type TestingT
Constants ¶
const ( SMALL_TEST = "small" MEDIUM_TEST = "medium" LARGE_TEST = "large" )
Variables ¶
var ( // DEFAULT_RUN indicates whether the given test type runs by default // when no filter flag is specified. DEFAULT_RUN = map[string]bool{ SMALL_TEST: true, MEDIUM_TEST: true, LARGE_TEST: true, } TIMEOUT_SMALL = "4s" TIMEOUT_MEDIUM = "15s" TIMEOUT_LARGE = "4m" TIMEOUT_RACE = "5m" // TEST_TYPES lists all of the types of tests. TEST_TYPES = []string{ SMALL_TEST, MEDIUM_TEST, LARGE_TEST, } // TryAgainErr use used by TryUntil. TryAgainErr = errors.New("Trying Again") )
Functions ¶
func AssertCloses ¶
AssertCloses takes an ioutil.Closer and asserts that it closes. E.g.: frobber := NewFrobber() defer testutils.AssertCloses(t, frobber)
func AssertErrorContains ¶
AssertErrorContains asserts that the given error contains the given string.
func EventuallyConsistent ¶
EventuallyConsistent tries a test repeatedly until either the test passes or time expires, and is used when tests are written to expect non-eventual consistency.
Use this function sparingly.
duration - The amount of time to keep trying. f - The func to run the tests, should return TryAgainErr if
we should keep trying, otherwise TryUntil will return with the err that f() returns.
func LargeTest ¶
func LargeTest(t TestingT)
LargeTest is a function which should be called at the beginning of a large test: a test (> 15 seconds) with significant reliance on external dependencies which makes it too slow or flaky to run as part of the normal test suite.
func LocalOnlyTest ¶
func LocalOnlyTest(t TestingT)
LocalOnlyTest will skip the test if it is bein run on GCE.
func ManualTest ¶
func ManualTest(t TestingT)
ManualTest is a function which should be called at the beginning of tests which shouldn't run on the bots due to excessive running time, external requirements, etc.
func MarshalIndentJSON ¶
MarshalIndentJSON encodes the given interface to an indented JSON string.
func MarshalJSON ¶
MarshalJSON encodes the given interface to a JSON string.
func MediumTest ¶
func MediumTest(t TestingT)
MediumTest is a function which should be called at the beginning of an medium-sized test: a test (2-15 seconds) which has dependencies on external databases, networks, etc.
func MustReadFile ¶
MustReadFile reads a file from the caller's testdata directory and panics on error.
func MustReadJsonFile ¶
func MustReadJsonFile(filename string, dest interface{})
MustReadJsonFile reads a JSON file from the caller's testdata directory into the given interface and panics on error.
func ReadJsonFile ¶
ReadJsonFile reads a JSON file from the caller's testdata directory into the given interface.
func RemoveAll ¶
RemoveAll attempts to remove the given directory and asserts that no error is returned.
func SmallTest ¶
func SmallTest(t TestingT)
SmallTest is a function which should be called at the beginning of a small test: A test (under 2 seconds) with no dependencies on external databases, networks, etc.
func TempDir ¶
TempDir is a wrapper for ioutil.TempDir. Returns the path to the directory and a cleanup function to defer.
func TestDataDir ¶
TestDataDir returns the path to the caller's testdata directory, which is assumed to be "<path to caller dir>/testdata".
Types ¶
type TestingT ¶
type TestingT interface { Error(...interface{}) Errorf(string, ...interface{}) Fail() FailNow() Failed() bool Fatal(...interface{}) Fatalf(string, ...interface{}) Helper() Log(...interface{}) Logf(string, ...interface{}) Name() string Skip(...interface{}) SkipNow() Skipf(string, ...interface{}) Skipped() bool }
TestingT is an interface which is compatible with testing.T and testing.B, used so that we don't have to import the "testing" package except in _test.go files.