exectest

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package exectest provides reusable fakes for the process-execution seams (exec.LookPath, exec.CommandContext, os.Executable) that GTB code injects for testability. Tests build a fake with one of these helpers and pass it in through a functional option or struct field, so the real subprocess is never spawned.

The fakes are deliberately plain functions rather than a mutable package-level var (e.g. no `var execLookPath = exec.LookPath` swap hook). A shared global swapped and restored per test races under t.Parallel(); returning a fresh closure that the caller injects keeps every test's seam private to that test, so the suite stays parallel-safe. See docs/how-to/testing.md for the full race-avoidance rationale.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EchoCommand

func EchoCommand(output string) func(context.Context, string, ...string) *exec.Cmd

EchoCommand returns a command factory that echoes the given output.

func FailCommand

func FailCommand() func(context.Context, string, ...string) *exec.Cmd

FailCommand returns a command factory that always exits non-zero.

func FakeExecutable

func FakeExecutable(path string) func() (string, error)

FakeExecutable returns an osExecutable function that always returns the given path.

func FakeLookPath

func FakeLookPath(path string) func(string) (string, error)

FakeLookPath returns a lookup function that always succeeds with the given path.

func MissingLookPath

func MissingLookPath() func(string) (string, error)

MissingLookPath returns a lookup function that always fails with "not found".

func NoopCommand

func NoopCommand() func(context.Context, string, ...string) *exec.Cmd

NoopCommand returns a command factory that produces a no-op process.

func TrackingCommand

func TrackingCommand(log *[]string) func(context.Context, string, ...string) *exec.Cmd

TrackingCommand returns a command factory that records each invocation (name + args) into the provided slice and returns a no-op process.

Types

This section is empty.

Jump to

Keyboard shortcuts

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