Documentation
¶
Overview ¶
Package testhelpers provides utilities for testing.
Index ¶
- Variables
- func CopyDir(tb testing.TB, src, dst string) error
- func CopyFile(tb testing.TB, src, dst string) error
- func Logger(tb testing.TB, options ...logging.Option) zerolog.Logger
- func ParseTestOutputs(jsonOutputs ...[]byte) (map[string]*PackageTestResults, error)
- func ShowDirContents(tb testing.TB, rootPath string) error
- type PackageTestResults
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTestBuildFailed is returned when the build failed during the go test run. ErrTestBuildFailed = errors.New("test build failed") )
Functions ¶
func CopyDir ¶
CopyDir recursively copies a directory from src to dst. Handy for copying files needed for testing into a temp directory.
func CopyFile ¶
CopyFile copies a file from src to dst. Handy for copying files needed for testing into a temp directory.
func Logger ¶
Logger returns a zerolog.Logger for the test. It creates a log file in the current directory with the test name. It also cleans up the log file after the test. If the test fails, it leaves the log file for debugging.
func ParseTestOutputs ¶
func ParseTestOutputs(jsonOutputs ...[]byte) (map[string]*PackageTestResults, error)
ParseTestOutputs parses the output of go test -json and returns basic test result summary. It is not a highly rigorous test result parser, but it is enough to get the basic test results. There will probably be some odd behavior around races, panics, and other edge cases. Meant only for use in integration tests where we're reasonably sure about what we're expecting.
Types ¶
type PackageTestResults ¶
type PackageTestResults struct {
Found []string `json:"found"` // All tests that were found in the run
Skipped []string `json:"skipped"` // All tests that were skipped in the run
Passed []string `json:"passed"` // All tests that passed in the run
Failed []string `json:"failed"` // All tests that failed in the run
Panic bool `json:"panic"` // Whether a panic occurred in the run
Race bool `json:"race"` // Whether a race condition occurred in the run
Timeout bool `json:"timeout"` // Whether a timeout occurred in the run
}
PackageTestResults is a summary of the test results for a given package.