Documentation
¶
Overview ¶
Package gitxtest is a git smart-HTTP server for tests: the real git-http-backend behind basic authentication, in process, so a test meets what a forge's HTTPS endpoint does (a 401, a credential helper, a pre-receive hook's "remote:" lines) without a network. Only _test.go files import it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deadline ¶
Deadline is the wall-clock budget a test gives to something that waits on git or on the server (a commit, a push, a debounced repair run, one MCP response): d on a normal machine, four times d on Windows. The test-windows runners take 1-2 s for a single commit and run the shards under load, so a bare 5 s or 20 s that never fails on Linux fails there without any bug (#1048). Wrap every deadline of that kind in it, in `time.After(gitxtest.Deadline(...))` or `time.Now().Add(...)`, instead of raising one number after each red run. A wait that fires the instant the event happens (a channel, a condition polled until it holds) costs nothing when the scale is generous; a deadline that is itself under test (a timeout the code must hit) is not scaled.
func HTTPRemote ¶
HTTPRemote serves a new empty bare repository, on branch main, over smart HTTP with basic authentication for user and password. It returns the clone URL and the bare repository's path (to install a hook in, or to read what a push left). The test is skipped when git has no http-backend.
func IsolatedEnv ¶
func IsolatedEnv() []string
IsolatedEnv keeps the machine's own git configuration out of a test: its credential helper (a keychain) would answer for a missing token, and store a test token. Not t.Setenv, which a parallel test cannot use.
func QuietGit ¶
func QuietGit()
QuietGit switches off git's automatic gc and maintenance for every git the test binary spawns, the code under test included (gitx starts each command from os.Environ()). A commit or rebase can otherwise start a detached `git gc --auto` that keeps writing into .git while t.TempDir() removes it, and the cleanup fails with "directory not empty". Call it first in TestMain of every package whose tests create a git repository: a repodocs test fails when one does not.
func ReadOnlyHTTPRemote ¶ added in v0.29.0
ReadOnlyHTTPRemote is HTTPRemote for a credential without write access: the receiving side (git-receive-pack, a push) answers 403 to a good login, as a forge does to a read-only token, while a clone and a fetch work.
func TokenEnv ¶
TokenEnv is the git environment that makes a credential helper answer with user "token" and the content of tokenFile: the GIT_CONFIG_* variables (a reset of the helper list, then the helper) of cmd/cartographer's gitTokenCredentialEnv, which that package's own test checks against a server (bootstrap_test.go). Kept in step by hand.
Types ¶
This section is empty.