testhelpers

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package testhelpers provides utilities for testing.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTestBuildFailed is returned when the build failed during the go test run.
	ErrTestBuildFailed = errors.New("test build failed")
)

Functions

func CopyDir

func CopyDir(tb testing.TB, src, dst string) error

CopyDir recursively copies a directory from src to dst. Handy for copying files needed for testing into a temp directory.

func CopyFile

func CopyFile(tb testing.TB, src, dst string) error

CopyFile copies a file from src to dst. Handy for copying files needed for testing into a temp directory.

func Logger

func Logger(tb testing.TB, options ...logging.Option) zerolog.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.

func ShowDirContents

func ShowDirContents(tb testing.TB, rootPath string) error

ShowDirContents prints the full directory structure starting from the given path. Handy for debugging test failures in temp directories, like in testscript integration tests.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL