gitxtest

package
v0.29.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 10 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 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

func Deadline(d time.Duration) time.Duration

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

func HTTPRemote(t testing.TB, user, password string) (url, bare string)

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

func ReadOnlyHTTPRemote(t testing.TB, user, password string) (url, bare string)

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

func TokenEnv(tokenFile string) []string

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.

Jump to

Keyboard shortcuts

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