testutil

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 7 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

Overview

Package testutil provides small, shared helpers for tests across the codebase.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsolateUserDirs

func IsolateUserDirs(root string) (restore func() error, err error)

IsolateUserDirs points every per-user directory root at root so code under test cannot read the developer's real config, cache or home directory, or write to them. It is meant for a package's TestMain, which has no *testing.T (tests that need their own layout still use t.Setenv, which wins while it is active). The returned function restores the previous environment.

It fails closed: if any variable cannot be redirected, the variables it had already changed are restored and an error is returned, so the caller must not run the tests against a partially isolated environment.

func PathWithin

func PathWithin(root, path string) bool

PathWithin reports whether path is root or lies beneath it, comparing the physical forms so symlinked temp dirs (/var vs /private/var on macOS) and Windows short names do not cause false results. Components that do not exist yet are kept as spelled under their nearest existing ancestor.

func WaitFor

func WaitFor(t *testing.T, what string, cond func() bool)

WaitFor polls cond until it returns true, or fails the test if it does not become true within a generous deadline. what names the condition being waited for so a timeout failure message is actionable.

Types

This section is empty.

Jump to

Keyboard shortcuts

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