exec

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExecutableNotFound = osexec.ErrNotFound

ErrExecutableNotFound is returned if the executable is not found.

Functions

This section is empty.

Types

type Cmd

type Cmd interface {
	// Run runs the command to the completion.
	Run() error
	// CombinedOutput runs the command and returns its combined standard output
	// and standard error. This follows the pattern of package os/exec.
	CombinedOutput() ([]byte, error)
	// Output runs the command and returns standard output, but not standard err
	Output() ([]byte, error)
	SetDir(dir string)
	SetStdin(in io.Reader)
	SetStdout(out io.Writer)
	SetStderr(out io.Writer)
	SetEnv(env []string)
	SetSysProcAttr(proc *syscall.SysProcAttr)

	// StdoutPipe and StderrPipe for getting the process' Stdout and Stderr as
	// Readers
	StdoutPipe() (io.ReadCloser, error)
	StderrPipe() (io.ReadCloser, error)

	// Start and Wait are for running a process non-blocking
	Start() error
	Wait() error

	// Stops the command by sending SIGTERM. It is not guaranteed the
	// process will stop before this function returns. If the process is not
	// responding, an internal timer function will send a SIGKILL to force
	// terminate after 10 seconds.
	Stop()
}

Cmd is an interface that presents an API that is very similar to Cmd from os/exec. As more functionality is needed, this can grow. Since Cmd is a struct, we will have to replace fields with get/set method pairs.

type CmdCombinedOutputExpectation added in v0.0.19

type CmdCombinedOutputExpectation struct {
	Returns CmdCombinedOutputReturns
}

type CmdCombinedOutputReturns added in v0.0.19

type CmdCombinedOutputReturns struct {
	Output []byte
	Err    error
}

type CmdOutputExpectation added in v0.0.19

type CmdOutputExpectation struct {
	Returns CmdOutputReturns
}

type CmdOutputReturns added in v0.0.19

type CmdOutputReturns struct {
	Output []byte
	Err    error
}

type CmdRunExpectation added in v0.0.19

type CmdRunExpectation struct {
	Returns CmdRunReturns
}

type CmdRunReturns added in v0.0.19

type CmdRunReturns struct {
	Err error
}

type CmdSetDirArgs added in v0.0.19

type CmdSetDirArgs struct {
	Dir         string
	DirAnything bool
}

type CmdSetDirExpectation added in v0.0.19

type CmdSetDirExpectation struct {
	Args CmdSetDirArgs
}

type CmdSetEnvArgs added in v0.0.19

type CmdSetEnvArgs struct {
	Env         []string
	EnvAnything bool
}

type CmdSetEnvExpectation added in v0.0.19

type CmdSetEnvExpectation struct {
	Args CmdSetEnvArgs
}

type CmdSetStderrArgs added in v0.0.19

type CmdSetStderrArgs struct {
	Out         io.Writer
	OutAnything bool
}

type CmdSetStderrExpectation added in v0.0.19

type CmdSetStderrExpectation struct {
	Args CmdSetStderrArgs
}

type CmdSetStdinArgs added in v0.0.19

type CmdSetStdinArgs struct {
	In         io.Reader
	InAnything bool
}

type CmdSetStdinExpectation added in v0.0.19

type CmdSetStdinExpectation struct {
	Args CmdSetStdinArgs
}

type CmdSetStdoutArgs added in v0.0.19

type CmdSetStdoutArgs struct {
	Out         io.Writer
	OutAnything bool
}

type CmdSetStdoutExpectation added in v0.0.19

type CmdSetStdoutExpectation struct {
	Args CmdSetStdoutArgs
}

type CmdSetSysProcAttrArgs added in v0.0.19

type CmdSetSysProcAttrArgs struct {
	Proc         *syscall.SysProcAttr
	ProcAnything bool
}

type CmdSetSysProcAttrExpectation added in v0.0.19

type CmdSetSysProcAttrExpectation struct {
	Args CmdSetSysProcAttrArgs
}

type CmdStartExpectation added in v0.0.19

type CmdStartExpectation struct {
	Returns CmdStartReturns
}

type CmdStartReturns added in v0.0.19

type CmdStartReturns struct {
	Err error
}

type CmdStderrPipeExpectation added in v0.0.19

type CmdStderrPipeExpectation struct {
	Returns CmdStderrPipeReturns
}

type CmdStderrPipeReturns added in v0.0.19

type CmdStderrPipeReturns struct {
	Output io.ReadCloser
	Err    error
}

type CmdStdoutPipeExpectation added in v0.0.19

type CmdStdoutPipeExpectation struct {
	Returns CmdStdoutPipeReturns
}

type CmdStdoutPipeReturns added in v0.0.19

type CmdStdoutPipeReturns struct {
	Output io.ReadCloser
	Err    error
}

type CmdStopExpectation added in v0.0.19

type CmdStopExpectation struct {
}

type CmdWaitExpectation added in v0.0.19

type CmdWaitExpectation struct {
	Returns CmdWaitReturns
}

type CmdWaitReturns added in v0.0.19

type CmdWaitReturns struct {
	Err error
}

type CodeExitError

type CodeExitError struct {
	Err  error
	Code int
}

CodeExitError is an implementation of ExitError consisting of an error object and an exit code (the upper bits of os.exec.ExitStatus).

func (CodeExitError) Error

func (e CodeExitError) Error() string

func (CodeExitError) ExitStatus

func (e CodeExitError) ExitStatus() int

ExitStatus is for checking the error code

func (CodeExitError) Exited

func (e CodeExitError) Exited() bool

Exited is to check if the process has finished

func (CodeExitError) String

func (e CodeExitError) String() string

type ExitError

type ExitError interface {
	String() string
	Error() string
	Exited() bool
	ExitStatus() int
}

ExitError is an interface that presents an API similar to os.ProcessState, which is what ExitError from os/exec is. This is designed to make testing a bit easier and probably loses some of the cross-platform properties of the underlying library.

type ExitErrorWrapper

type ExitErrorWrapper struct {
	*osexec.ExitError
}

ExitErrorWrapper is an implementation of ExitError in terms of os/exec ExitError. Note: standard exec.ExitError is type *os.ProcessState, which already implements Exited().

func (ExitErrorWrapper) ExitStatus

func (eew ExitErrorWrapper) ExitStatus() int

ExitStatus is part of the ExitError interface.

type Interface

type Interface interface {
	// Command returns a Cmd instance which can be used to run a single command.
	// This follows the pattern of package os/exec.
	Command(cmd string, args ...string) Cmd

	// CommandContext returns a Cmd instance which can be used to run a single command.
	//
	// The provided context is used to kill the process if the context becomes done
	// before the command completes on its own. For example, a timeout can be set in
	// the context.
	CommandContext(ctx context.Context, cmd string, args ...string) Cmd

	// LookPath wraps os/exec.LookPath
	LookPath(file string) (string, error)
}

Interface is an interface that presents a subset of the os/exec API. Use this when you want to inject fakeable/mockable exec behavior.

func New

func New() Interface

New returns a new Interface which will os/exec to run commands.

type InterfaceCommandArgs added in v0.0.19

type InterfaceCommandArgs struct {
	Cmd          string
	CmdAnything  bool
	Args         []string
	ArgsAnything bool
}

type InterfaceCommandContextArgs added in v0.0.19

type InterfaceCommandContextArgs struct {
	Ctx          context.Context
	CtxAnything  bool
	Cmd          string
	CmdAnything  bool
	Args         []string
	ArgsAnything bool
}

type InterfaceCommandContextExpectation added in v0.0.19

type InterfaceCommandContextExpectation struct {
	Args    InterfaceCommandContextArgs
	Returns InterfaceCommandContextReturns
}

type InterfaceCommandContextReturns added in v0.0.19

type InterfaceCommandContextReturns struct {
	Cmd func() Cmd
}

type InterfaceCommandExpectation added in v0.0.19

type InterfaceCommandExpectation struct {
	Args    InterfaceCommandArgs
	Returns InterfaceCommandReturns
}

type InterfaceCommandReturns added in v0.0.19

type InterfaceCommandReturns struct {
	Cmd func() Cmd
}

type InterfaceLookPathArgs added in v0.0.19

type InterfaceLookPathArgs struct {
	File         string
	FileAnything bool
}

type InterfaceLookPathExpectation added in v0.0.19

type InterfaceLookPathExpectation struct {
	Args    InterfaceLookPathArgs
	Returns InterfaceLookPathReturns
}

type InterfaceLookPathReturns added in v0.0.19

type InterfaceLookPathReturns struct {
	Path string
	Err  error
}

type MockCmd added in v0.0.19

type MockCmd struct {
	mock.Mock
}

func (*MockCmd) ApplyCombinedOutputExpectation added in v0.0.19

func (_m *MockCmd) ApplyCombinedOutputExpectation(e CmdCombinedOutputExpectation)

func (*MockCmd) ApplyCombinedOutputExpectations added in v0.0.19

func (_m *MockCmd) ApplyCombinedOutputExpectations(expectations []CmdCombinedOutputExpectation)

func (*MockCmd) ApplyOutputExpectation added in v0.0.19

func (_m *MockCmd) ApplyOutputExpectation(e CmdOutputExpectation)

func (*MockCmd) ApplyOutputExpectations added in v0.0.19

func (_m *MockCmd) ApplyOutputExpectations(expectations []CmdOutputExpectation)

func (*MockCmd) ApplyRunExpectation added in v0.0.19

func (_m *MockCmd) ApplyRunExpectation(e CmdRunExpectation)

func (*MockCmd) ApplyRunExpectations added in v0.0.19

func (_m *MockCmd) ApplyRunExpectations(expectations []CmdRunExpectation)

func (*MockCmd) ApplySetDirExpectation added in v0.0.19

func (_m *MockCmd) ApplySetDirExpectation(e CmdSetDirExpectation)

func (*MockCmd) ApplySetDirExpectations added in v0.0.19

func (_m *MockCmd) ApplySetDirExpectations(expectations []CmdSetDirExpectation)

func (*MockCmd) ApplySetEnvExpectation added in v0.0.19

func (_m *MockCmd) ApplySetEnvExpectation(e CmdSetEnvExpectation)

func (*MockCmd) ApplySetEnvExpectations added in v0.0.19

func (_m *MockCmd) ApplySetEnvExpectations(expectations []CmdSetEnvExpectation)

func (*MockCmd) ApplySetStderrExpectation added in v0.0.19

func (_m *MockCmd) ApplySetStderrExpectation(e CmdSetStderrExpectation)

func (*MockCmd) ApplySetStderrExpectations added in v0.0.19

func (_m *MockCmd) ApplySetStderrExpectations(expectations []CmdSetStderrExpectation)

func (*MockCmd) ApplySetStdinExpectation added in v0.0.19

func (_m *MockCmd) ApplySetStdinExpectation(e CmdSetStdinExpectation)

func (*MockCmd) ApplySetStdinExpectations added in v0.0.19

func (_m *MockCmd) ApplySetStdinExpectations(expectations []CmdSetStdinExpectation)

func (*MockCmd) ApplySetStdoutExpectation added in v0.0.19

func (_m *MockCmd) ApplySetStdoutExpectation(e CmdSetStdoutExpectation)

func (*MockCmd) ApplySetStdoutExpectations added in v0.0.19

func (_m *MockCmd) ApplySetStdoutExpectations(expectations []CmdSetStdoutExpectation)

func (*MockCmd) ApplySetSysProcAttrExpectation added in v0.0.19

func (_m *MockCmd) ApplySetSysProcAttrExpectation(e CmdSetSysProcAttrExpectation)

func (*MockCmd) ApplySetSysProcAttrExpectations added in v0.0.19

func (_m *MockCmd) ApplySetSysProcAttrExpectations(expectations []CmdSetSysProcAttrExpectation)

func (*MockCmd) ApplyStartExpectation added in v0.0.19

func (_m *MockCmd) ApplyStartExpectation(e CmdStartExpectation)

func (*MockCmd) ApplyStartExpectations added in v0.0.19

func (_m *MockCmd) ApplyStartExpectations(expectations []CmdStartExpectation)

func (*MockCmd) ApplyStderrPipeExpectation added in v0.0.19

func (_m *MockCmd) ApplyStderrPipeExpectation(e CmdStderrPipeExpectation)

func (*MockCmd) ApplyStderrPipeExpectations added in v0.0.19

func (_m *MockCmd) ApplyStderrPipeExpectations(expectations []CmdStderrPipeExpectation)

func (*MockCmd) ApplyStdoutPipeExpectation added in v0.0.19

func (_m *MockCmd) ApplyStdoutPipeExpectation(e CmdStdoutPipeExpectation)

func (*MockCmd) ApplyStdoutPipeExpectations added in v0.0.19

func (_m *MockCmd) ApplyStdoutPipeExpectations(expectations []CmdStdoutPipeExpectation)

func (*MockCmd) ApplyStopExpectation added in v0.0.19

func (_m *MockCmd) ApplyStopExpectation(e CmdStopExpectation)

func (*MockCmd) ApplyStopExpectations added in v0.0.19

func (_m *MockCmd) ApplyStopExpectations(expectations []CmdStopExpectation)

func (*MockCmd) ApplyWaitExpectation added in v0.0.19

func (_m *MockCmd) ApplyWaitExpectation(e CmdWaitExpectation)

func (*MockCmd) ApplyWaitExpectations added in v0.0.19

func (_m *MockCmd) ApplyWaitExpectations(expectations []CmdWaitExpectation)

func (*MockCmd) CombinedOutput added in v0.0.19

func (_m *MockCmd) CombinedOutput() ([]byte, error)

func (*MockCmd) Output added in v0.0.19

func (_m *MockCmd) Output() ([]byte, error)

func (*MockCmd) Run added in v0.0.19

func (_m *MockCmd) Run() error

func (*MockCmd) SetDir added in v0.0.19

func (_m *MockCmd) SetDir(dir string)

func (*MockCmd) SetEnv added in v0.0.19

func (_m *MockCmd) SetEnv(env []string)

func (*MockCmd) SetStderr added in v0.0.19

func (_m *MockCmd) SetStderr(out io.Writer)

func (*MockCmd) SetStdin added in v0.0.19

func (_m *MockCmd) SetStdin(in io.Reader)

func (*MockCmd) SetStdout added in v0.0.19

func (_m *MockCmd) SetStdout(out io.Writer)

func (*MockCmd) SetSysProcAttr added in v0.0.19

func (_m *MockCmd) SetSysProcAttr(proc *syscall.SysProcAttr)

func (*MockCmd) Start added in v0.0.19

func (_m *MockCmd) Start() error

func (*MockCmd) StderrPipe added in v0.0.19

func (_m *MockCmd) StderrPipe() (io.ReadCloser, error)

StderrPipe provides a mock function with given fields:

func (*MockCmd) StdoutPipe added in v0.0.19

func (_m *MockCmd) StdoutPipe() (io.ReadCloser, error)

StdoutPipe provides a mock function with given fields:

func (*MockCmd) Stop added in v0.0.19

func (_m *MockCmd) Stop()

Stop provides a mock function with given fields:

func (*MockCmd) Wait added in v0.0.19

func (_m *MockCmd) Wait() error

Wait provides a mock function with given fields:

type MockInterface added in v0.0.19

type MockInterface struct {
	mock.Mock
}

func (*MockInterface) ApplyCommandContextExpectation added in v0.0.19

func (_m *MockInterface) ApplyCommandContextExpectation(e InterfaceCommandContextExpectation)

func (*MockInterface) ApplyCommandContextExpectations added in v0.0.19

func (_m *MockInterface) ApplyCommandContextExpectations(expectations []InterfaceCommandContextExpectation)

func (*MockInterface) ApplyCommandExpectation added in v0.0.19

func (_m *MockInterface) ApplyCommandExpectation(e InterfaceCommandExpectation)

func (*MockInterface) ApplyCommandExpectations added in v0.0.19

func (_m *MockInterface) ApplyCommandExpectations(expectations []InterfaceCommandExpectation)

func (*MockInterface) ApplyLookPathExpectation added in v0.0.19

func (_m *MockInterface) ApplyLookPathExpectation(e InterfaceLookPathExpectation)

func (*MockInterface) ApplyLookPathExpectations added in v0.0.19

func (_m *MockInterface) ApplyLookPathExpectations(expectations []InterfaceLookPathExpectation)

func (*MockInterface) Command added in v0.0.19

func (_m *MockInterface) Command(cmd string, args ...string) Cmd

Command provides a mock function with given fields: cmd, args

func (*MockInterface) CommandContext added in v0.0.19

func (_m *MockInterface) CommandContext(ctx context.Context, cmd string, args ...string) Cmd

func (*MockInterface) LookPath added in v0.0.19

func (_m *MockInterface) LookPath(file string) (string, error)

LookPath provides a mock function with given fields: file

Jump to

Keyboard shortcuts

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