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

testutil

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package testutil builds throwaway git repositories for tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(m *testing.M)

Main runs the package's tests with the user's git config kept out of every git process. It sets the environment once for the whole process, so tests that use NewRepo can call t.Parallel. Call it from TestMain.

Types

type Repo

type Repo struct {
	Dir    string
	Origin string
	// contains filtered or unexported fields
}

Repo is a working clone with a bare "origin" next to it.

func NewRepo

func NewRepo(t *testing.T) *Repo

NewRepo creates a bare origin with one commit on main and clones it.

func (*Repo) Clone

func (r *Repo) Clone() *Repo

Clone returns a fresh clone of the origin, e.g. to act as a teammate.

func (*Repo) Commit

func (r *Repo) Commit(file, content, msg string) string

Commit writes file and commits it on the current branch.

func (*Repo) Git

func (r *Repo) Git(args ...string) string

Git runs git in the working clone and returns trimmed stdout.

func (*Repo) PushFromElsewhere

func (r *Repo) PushFromElsewhere(branch, file, content, msg string) string

PushFromElsewhere commits file on branch in a separate clone and pushes it, simulating someone else updating the remote.

Jump to

Keyboard shortcuts

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