Documentation ¶
Overview ¶
Package testutil contains common test utilities.
Index ¶
- func ApplyDir(dir Dir)
- func Chdir(c Cleanuper, dir string) string
- func InTempDir(c Cleanuper) string
- func InTempHome(c Cleanuper) string
- func Must(err error)
- func MustChdir(dir string)
- func MustCreateEmpty(names ...string)
- func MustMkdirAll(names ...string)
- func MustPipe() (*os.File, *os.File)
- func MustReadAllAndClose(r io.ReadCloser) []byte
- func MustWriteFile(filename, data string)
- func Recover(f func()) (r interface{})
- func SaveEnv(c Cleanuper, name string)
- func Scaled(d time.Duration) time.Duration
- func Setenv(c Cleanuper, name, value string) string
- func TempDir(c Cleanuper) string
- func TempHome(c Cleanuper) string
- func Umask(c Cleanuper, m int)
- func Unsetenv(c Cleanuper, name string)
- type Cleanuper
- type Dir
- type File
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyDir ¶
func ApplyDir(dir Dir)
ApplyDir creates the given filesystem layout in the current directory.
func Chdir ¶
Chdir changes into a directory, and restores the original working directory when a test finishes. It returns the directory for easier chaining.
func InTempHome ¶
InTempHome is equivalent to Setenv(c, env.HOME, InTempDir(c))
func Must ¶
func Must(err error)
Must panics if the error value is not nil. It is typically used like this:
testutil.Must(someFunction(...))
Where someFunction returns a single error value. This is useful with functions like os.Mkdir to succinctly ensure the test fails to proceed if an operation required for the test setup results in an error.
func MustCreateEmpty ¶
func MustCreateEmpty(names ...string)
MustCreateEmpty creates empty file, after creating all ancestor directories that don't exist. It panics if an error occurs.
func MustMkdirAll ¶
func MustMkdirAll(names ...string)
MustMkdirAll calls os.MkdirAll for each argument. It panics if an error occurs.
func MustReadAllAndClose ¶
func MustReadAllAndClose(r io.ReadCloser) []byte
MustReadAllAndClose reads all bytes and closes the ReadCloser. It panics if an error occurs.
func MustWriteFile ¶
func MustWriteFile(filename, data string)
MustWriteFile writes data to a file, after creating all ancestor directories that don't exist. It panics if an error occurs.
func SaveEnv ¶
SaveEnv saves the current value of an environment variable so that it will be restored after a test has finished.
func Scaled ¶
Scaled returns d scaled by $E:ELVISH_TEST_TIME_SCALE. If the environment variable does not exist or contains an invalid value, the scale defaults to 1.
func Setenv ¶
Setenv sets the value of an environment variable for the duration of a test. It returns value.
func TempDir ¶
TempDir creates a temporary directory for testing that will be removed after the test finishes. It is different from testing.TB.TempDir in that it resolves symlinks in the path of the directory.
It panics if the test directory cannot be created or symlinks cannot be resolved. It is only suitable for use in tests.
Types ¶
type Cleanuper ¶
type Cleanuper interface {
Cleanup(func())
}
Cleanuper wraps the Cleanup method. It is a subset of testing.TB, thus satisfied by *testing.T and *testing.B.