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

testutil

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package testutil provides shared test helpers: fake implementations of internal/repo.Finder and internal/runner.Runner interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeGitRepo

func MakeGitRepo(t testing.TB, parent, name string) string

MakeGitRepo creates a minimal git repository directory (with a .git dir) under parent and returns its path.

func RunTestMain added in v0.2.0

func RunTestMain(m *testing.M)

RunTestMain unsets all GIT_ITER_* environment variables, runs the test suite m, restores the original environment variables, and terminates the process with m's exit code. TestMain implementations in packages can simply call testutil.RunTestMain(m).

Types

type FakeFinder

type FakeFinder struct {
	Paths []string
	Err   error
}

FakeFinder is a test double for repo.Finder that returns a pre-configured list of paths.

func (*FakeFinder) Find

func (f *FakeFinder) Find(_ context.Context) ([]string, error)

type FakeRunner

type FakeRunner struct {
	Calls  []RunCall
	Output string
	Err    error
	// contains filtered or unexported fields
}

FakeRunner is a test double for runner.Runner. It records every call and writes Output to stdout; returns Err on each call.

func (*FakeRunner) Run

func (r *FakeRunner) Run(_ context.Context, dir string, command []string, stdout, _ io.Writer) error

type RunCall

type RunCall struct {
	Dir     string
	Command []string
}

RunCall records a single invocation of FakeRunner.Run.

type SubcommandHandler

type SubcommandHandler func(cmd []string, stdout, stderr io.Writer) error

SubcommandHandler is invoked by SubcommandRunner when a matching subcommand is executed.

type SubcommandRunner

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

SubcommandRunner is a mock runner that dispatches to handlers based on command[1].

func NewSubcommandRunner

func NewSubcommandRunner() *SubcommandRunner

NewSubcommandRunner creates a new SubcommandRunner.

func (*SubcommandRunner) Calls

func (r *SubcommandRunner) Calls() [][]string

Calls returns a copy of all recorded calls.

func (*SubcommandRunner) On

func (r *SubcommandRunner) On(subcmd string, h SubcommandHandler)

On registers a handler for a given git subcommand (e.g. "rev-parse", "symbolic-ref").

func (*SubcommandRunner) Run

func (r *SubcommandRunner) Run(_ context.Context, _ string, command []string, stdout, stderr io.Writer) error

Run records the call and executes the registered handler if found.

Jump to

Keyboard shortcuts

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