testutils

package
v4.24.22 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertError

func AssertError(t *testing.T, err error, expectedMsg string)

AssertError asserts that an error is not nil and contains the expected message.

func AssertNoError

func AssertNoError(t *testing.T, err error)

AssertNoError asserts that an error is nil.

func CaptureStdout

func CaptureStdout(t *testing.T) (string, func())

CaptureStdout captures the output of stdout during a test. It returns the captured string and a function to restore stdout.

func ClearEnv

func ClearEnv(t interface {
	Helper()
	Setenv(key, value string)
}, keys []string) func()

ClearEnv clears a list of environment variables. It returns a cleanup function that restores the original environment variables.

func GetEnvMapFromStrings

func GetEnvMapFromStrings(envStrings []string) map[string]string

GetEnvMapFromStrings converts a slice of "KEY=VALUE" strings into a map.

func GitChildEnv added in v4.24.9

func GitChildEnv(extra ...string) []string

GitChildEnv returns an environment for a git child process with the repository overrides dropped and global and system config neutralised, followed by extra (for example GIT_AUTHOR_NAME=t).

func HermeticGit added in v4.24.9

func HermeticGit(t *testing.T)

HermeticGit makes the current test independent of the git environment it inherited: the repository overrides are removed from the process for the duration of the test (restored on cleanup) and global and system config are neutralised. Use it when the code under test shells out to git, or reads a repository with go-git, and so inherits the process environment. Tests that call it must not run in parallel.

func SetEnv

func SetEnv(t interface {
	Helper()
	Setenv(key, value string)
}, env map[string]string) func()

SetEnv temporarily sets environment variables for the duration of a test. It returns a cleanup function that restores the original environment variables.

Types

This section is empty.

Jump to

Keyboard shortcuts

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