func InitFakeCmd(fake *FakeCmd, cmd string, args ...string) exec.Cmd
InitFakeCmd is for creating a fake exec.Cmd
FakeAction is a function type
type FakeAction func() ([]byte, []byte, error)
FakeCmd is a simple scripted Cmd type.
type FakeCmd struct { Argv []string CombinedOutputScript []FakeAction CombinedOutputCalls int CombinedOutputLog [][]string OutputScript []FakeAction OutputCalls int OutputLog [][]string RunScript []FakeAction RunCalls int RunLog [][]string Dirs []string Stdin io.Reader Stdout io.Writer Stderr io.Writer Env []string StdoutPipeResponse FakeStdIOPipeResponse StderrPipeResponse FakeStdIOPipeResponse WaitResponse error StartResponse error DisableScripts bool }
func (fake *FakeCmd) CombinedOutput() ([]byte, error)
CombinedOutput returns the output from the command
func (fake *FakeCmd) Output() ([]byte, error)
Output is the response from the command
func (fake *FakeCmd) Run() error
Run runs the command
func (fake *FakeCmd) SetDir(dir string)
SetDir sets the directory
func (fake *FakeCmd) SetEnv(env []string)
SetEnv sets the environment variables
func (fake *FakeCmd) SetStderr(out io.Writer)
SetStderr sets the stderr
func (fake *FakeCmd) SetStdin(in io.Reader)
SetStdin sets the stdin
func (fake *FakeCmd) SetStdout(out io.Writer)
SetStdout sets the stdout
func (fake *FakeCmd) Start() error
Start mimicks starting the process (in the background) and returns the injected StartResponse
func (fake *FakeCmd) StderrPipe() (io.ReadCloser, error)
StderrPipe returns an injected ReadCloser & error (via StderrPipeResponse) to be able to inject an output stream on Stderr
func (fake *FakeCmd) StdoutPipe() (io.ReadCloser, error)
StdoutPipe returns an injected ReadCloser & error (via StdoutPipeResponse) to be able to inject an output stream on Stdout
func (fake *FakeCmd) Stop()
Stop is to stop the process
func (fake *FakeCmd) Wait() error
Wait mimicks waiting for the process to exit returns the injected WaitResponse
FakeCommandAction is the function to be executed
type FakeCommandAction func(cmd string, args ...string) exec.Cmd
FakeExec is a simple scripted Interface type.
type FakeExec struct { CommandScript []FakeCommandAction CommandCalls int LookPathFunc func(string) (string, error) // ExactOrder enforces that commands are called in the order they are scripted, // and with the exact same arguments ExactOrder bool // DisableScripts removes the requirement that CommandScripts be populated // before calling Command(). This makes Command() and subsequent calls to // Run() or CombinedOutput() always return success and empty output. DisableScripts bool // contains filtered or unexported fields }
func (fake *FakeExec) Command(cmd string, args ...string) exec.Cmd
Command returns the next unexecuted command in CommandScripts. This function is safe for concurrent access as long as the underlying FakeExec struct is not modified during execution.
func (fake *FakeExec) CommandContext(ctx context.Context, cmd string, args ...string) exec.Cmd
CommandContext wraps arguments into exec.Cmd
func (fake *FakeExec) LookPath(file string) (string, error)
LookPath is for finding the path of a file
FakeExitError is a simple fake ExitError type.
type FakeExitError struct { Status int }
func (fake FakeExitError) Error() string
func (fake FakeExitError) ExitStatus() int
ExitStatus returns the fake status
func (fake FakeExitError) Exited() bool
Exited always returns true
func (fake FakeExitError) String() string
FakeStdIOPipeResponse holds responses to use as fakes for the StdoutPipe and StderrPipe method calls
type FakeStdIOPipeResponse struct { ReadCloser io.ReadCloser Error error }