Help us shape the future of Go! Take the 2026 Go Developer Survey

testutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package testutil holds helpers for tests only. Production code must not import it.

Index

Constants

View Source
const Delete = "\x00delete"

Delete, as a file's content in Commit, removes that path.

Variables

View Source
var Base = time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)

Base is the time every test commit is anchored to, so SHAs are stable.

Functions

func Author

func Author(n int) gitx.Identity

Author is the fixed test identity for the n-th commit on a branch.

func BareRepo

func BareRepo(t testing.TB, dir string) *gitx.Git

BareRepo creates a bare repository at dir.

func Commit

func Commit(t testing.TB, g *gitx.Git, branch, message string, files map[string]string) string

Commit adds a commit on refs/heads/<branch> that applies files on top of the branch's current tree, using plumbing only (no worktree). It returns the new commit's SHA.

func FakeGitHubToken

func FakeGitHubToken() string

FakeGitHubToken returns a string shaped like a GitHub PAT, so Gitleaks flags it. It is assembled at run time so this source file never contains a token-shaped literal (our own repo is scanned too).

func Main

func Main(m *testing.M, after ...func())

Main runs a package's tests, then each after func, then removes the git isolation directory the test binary made, so test runs leave nothing in the temp directory, and exits with the tests' code. Every package whose tests run git calls it from TestMain; after is for a package's own teardown.

func ValidateSchema

func ValidateSchema(t testing.TB, name string, raw []byte)

ValidateSchema fails t unless raw matches schemas/v0/<name>, with formats asserted. It finds the schemas from this file's own path, so any package's tests can call it.

Types

type Clock

type Clock struct {
	// contains filtered or unexported fields
}

Clock is a fake clock; Sleep advances it instantly.

func NewClock

func NewClock(t time.Time) *Clock

func (*Clock) Now

func (c *Clock) Now() time.Time

func (*Clock) Sleep

func (c *Clock) Sleep(d time.Duration)

func (*Clock) SleepCtx

func (c *Clock) SleepCtx(ctx context.Context, d time.Duration) error

SleepCtx is Sleep for an engine: it returns ctx's error instead of sleeping once ctx is done.

type SeqReader

type SeqReader struct {
	// contains filtered or unexported fields
}

SeqReader yields 0, 1, 2, … so generated IDs are deterministic.

func (*SeqReader) Read

func (r *SeqReader) Read(p []byte) (int, error)

Jump to

Keyboard shortcuts

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