exectest

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package exectest provides a scripted exec.Runner for unit tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call struct {
	Name  string
	Args  []string
	Dir   string
	Mode  exec.Mode
	Stdin string
}

Call records one invocation of the fake runner.

func (Call) String

func (c Call) String() string

String renders the call as a command line.

type Fake

type Fake struct {

	// Fallback handles commands no rule matches. By default it fails the
	// call with an "unexpected command" error.
	Fallback func(exec.Cmd) (exec.Result, error)
	// contains filtered or unexported fields
}

Fake is an exec.Runner that replays scripted results and records calls. Rules are matched by executable name and argument prefix; the most recently added matching rule wins.

func New

func New() *Fake

New returns an empty Fake.

func (*Fake) Calls

func (f *Fake) Calls() []Call

Calls returns every recorded call.

func (*Fake) CallsTo

func (f *Fake) CallsTo(name string) []Call

CallsTo returns the recorded calls for the given executable.

func (*Fake) On

func (f *Fake) On(name string, argPrefix ...string) *Stub

On registers a rule for name whose arguments start with argPrefix.

func (*Fake) Reset

func (f *Fake) Reset()

Reset forgets recorded calls but keeps the rules.

func (*Fake) Run

func (f *Fake) Run(_ context.Context, c exec.Cmd) (exec.Result, error)

Run implements exec.Runner.

type Stub

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

Stub configures the reply for one rule.

func (*Stub) Do

func (s *Stub) Do(fn func(exec.Cmd) (exec.Result, error)) *Stub

Do installs an arbitrary handler.

func (*Stub) Fail

func (s *Stub) Fail(code int, stderr string) *Stub

Fail makes the rule exit with code and the given stderr, returned as an *exec.ExitError like the real runner.

func (*Stub) NotFound

func (s *Stub) NotFound() *Stub

NotFound makes the rule report a missing executable.

func (*Stub) Reply

func (s *Stub) Reply(stdout string) *Stub

Reply makes the rule succeed with the given stdout.

Jump to

Keyboard shortcuts

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