Documentation
¶
Overview ¶
Package execxtest provides a fake execx.Runner that records every command instead of running it.
Index ¶
- Variables
- type Fake
- func (f *Fake) Calls() []execx.Cmd
- func (f *Fake) Commands() []string
- func (f *Fake) Find(prefix string) (execx.Cmd, bool)
- func (f *Fake) LookPath(name string) (string, error)
- func (f *Fake) Output(c execx.Cmd) ([]byte, error)
- func (f *Fake) Processes() []*Process
- func (f *Fake) Run(c execx.Cmd) error
- func (f *Fake) Start(ctx context.Context, c execx.Cmd) (execx.Process, error)
- type Process
Constants ¶
This section is empty.
Variables ¶
var ErrFailed = errors.New("exit status 1")
ErrFailed is a generic command failure for handlers to return.
var ErrKilled = errors.New("signal: killed")
ErrKilled is what Wait returns for a fake process stopped with Kill or by its context.
Functions ¶
This section is empty.
Types ¶
type Fake ¶
type Fake struct {
// Handler decides the result of each Run or Output call. When nil, every
// command succeeds with no output.
Handler func(c execx.Cmd) ([]byte, error)
// Installed lists the executables LookPath reports as present.
Installed map[string]bool
// OnStart is called with every process launched through Start, e.g. to
// make it exit at once. Returning an error makes Start fail instead.
OnStart func(p *Process) error
// contains filtered or unexported fields
}
Fake is an execx.Runner that records commands and answers them through Handler. The zero value succeeds for every command with empty output and reports every executable as missing from PATH.
func Install ¶
Install replaces the execx runner with a new Fake for the duration of t. Tests using it must not run in parallel, since the runner is package-level.
type Process ¶ added in v0.5.0
Process is a fake background process. It runs until Kill, Exit or the cancellation of the context it was started with.
func (*Process) Done ¶ added in v0.5.0
Done reports whether the process has terminated for any reason.
func (*Process) Exit ¶ added in v0.5.0
Exit makes the process terminate on its own with err (nil for success).