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 ¶
- func EchoCommand(output string) func(context.Context, string, ...string) *exec.Cmd
- func FailCommand() func(context.Context, string, ...string) *exec.Cmd
- func FakeExecutable(path string) func() (string, error)
- func FakeLookPath(path string) func(string) (string, error)
- func MissingLookPath() func(string) (string, error)
- func NoopCommand() func(context.Context, string, ...string) *exec.Cmd
- func TrackingCommand(log *[]string) func(context.Context, string, ...string) *exec.Cmd
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EchoCommand ¶
EchoCommand returns a command factory that echoes the given output.
func FailCommand ¶
FailCommand returns a command factory that always exits non-zero.
func FakeExecutable ¶
FakeExecutable returns an osExecutable function that always returns the given path.
func FakeLookPath ¶
FakeLookPath returns a lookup function that always succeeds with the given path.
func MissingLookPath ¶
MissingLookPath returns a lookup function that always fails with "not found".
func NoopCommand ¶
NoopCommand returns a command factory that produces a no-op process.
Types ¶
This section is empty.