cmdexec

package
v0.0.0-...-f459114 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMockbin

func IsMockbin() bool

func Mockbin

func Mockbin()

func NewTestExecutor

func NewTestExecutor() (CmdExecutor, *Recorder)

NewTestExecutor creates a command executor for testing purpose. Two ExecOpt are added to the executor options: 1. to prefix the command args to mock the command execution using Mockbin() and 2. to record all the command executed (before they're mutated by the first option).

Types

type CmdExecutor

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

func NewExecutor

func NewExecutor(opts ...ExecOpt) CmdExecutor

NewExecutor creates a new CmdExecutor with the given list of ExecOpt reversed. In this way, the first opt is executed at last.

func (CmdExecutor) Run

func (executor CmdExecutor) Run(name string, args ...string) error

Run creates a new exec.Cmd and applies the ExecOpt of the executor and then run the Cmd.

func (CmdExecutor) With

func (executor CmdExecutor) With(opts ...ExecOpt) CmdExecutor

With returns a new CmdExecutor with the given ExecOpt prepended to the list of ExecOpt of the current executor. In this way, the options added first are executed at last.

type ExecOpt

type ExecOpt func(*exec.Cmd)

func BaseDir

func BaseDir(basedir string) ExecOpt

BaseDir returns an ExecOpt that sets the Dir field of the exec.Cmd.

func ExtraEnv

func ExtraEnv(env []string) ExecOpt

ExtraEnv returns an ExecOpt that sets the Env field of the exec.Cmd.

func FakeExitCode

func FakeExitCode(exitCode int) ExecOpt

func FakeOn

func FakeOn(expectedArgs []string, opts ...ExecOpt) ExecOpt

func FakeStderr

func FakeStderr(err string) ExecOpt

func FakeStdout

func FakeStdout(out string) ExecOpt

func Stderr

func Stderr(w io.Writer) ExecOpt

Stderr returns an ExecOpt that sets the Stderr field of the exec.Cmd.

func Stdout

func Stdout(w io.Writer) ExecOpt

Stdout returns an ExecOpt that sets the Stdout field of the exec.Cmd.

type Recorder

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

type Tester

type Tester func(*testing.T, *Recorder)

func BuildTesters

func BuildTesters(testers ...Tester) Tester

func ExpectCommandArgs

func ExpectCommandArgs(expectedArgs []string) Tester

Jump to

Keyboard shortcuts

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