testutil

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package testutil provides small polling helpers shared across test packages, so individual tests don't re-derive deadline/poll loops (which tend to drift in interval and failure messaging).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Consistently

func Consistently(t fataler, duration, interval time.Duration, check func() string)

Consistently polls check for the full duration at the given interval, failing the test the first time check returns a non-empty failure message. It is the inverse of Eventually: the condition must hold the whole time.

func Eventually

func Eventually(t fataler, timeout, interval time.Duration, cond func() bool, msgf string, args ...any)

Eventually polls cond until it returns true or timeout elapses, failing the test (via t.Fatalf with the formatted message) on timeout.

func InitRepo

func InitRepo(t gitTB) string

InitRepo creates a throwaway git repository under t.TempDir() with a single committed README on the default "main" branch and returns its path.

func InitRepoWithBranch

func InitRepoWithBranch(t gitTB, branch string) string

InitRepoWithBranch is InitRepo with a caller-chosen initial branch name.

func RunGit

func RunGit(t gitTB, dir string, args ...string) string

RunGit runs `git args...` in dir and returns its trimmed combined output, failing the test on error. It strips inherited GIT_DIR/GIT_WORK_TREE/ GIT_INDEX_FILE (which a surrounding pre-push hook or harness may set) so the command always operates on dir, and pins a deterministic author/committer identity so commits succeed without depending on the machine's global git config.

func WaitForAtomic

func WaitForAtomic[T cmp.Ordered](t fataler, load func() T, want T, timeout time.Duration)

WaitForAtomic polls load until it reports a value >= want or timeout elapses, failing the test on timeout. load typically reads an atomic counter.

Types

This section is empty.

Jump to

Keyboard shortcuts

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