Documentation
¶
Index ¶
- type CmdWorker
- type ExecError
- type Local
- type LocalCmd
- func (local *LocalCmd) CmdError() error
- func (cmd *LocalCmd) GetArgs() []string
- func (cmd *LocalCmd) Output() ([]byte, []byte, error)
- func (cmd *LocalCmd) Run() error
- func (cmd *LocalCmd) SetStderr(buffer io.Writer)
- func (cmd *LocalCmd) SetStdin(reader io.Reader)
- func (cmd *LocalCmd) SetStdout(buffer io.Writer)
- func (cmd *LocalCmd) Start() error
- func (cmd *LocalCmd) StderrPipe() (io.Reader, error)
- func (cmd *LocalCmd) StdinPipe() (io.WriteCloser, error)
- func (cmd *LocalCmd) StdoutPipe() (io.Reader, error)
- func (cmd *LocalCmd) Wait() error
- type MockRunner
- type MockRunnerWorker
- func (worker *MockRunnerWorker) CmdError() error
- func (worker *MockRunnerWorker) GetArgs() []string
- func (worker *MockRunnerWorker) Output() ([]byte, []byte, error)
- func (worker *MockRunnerWorker) Run() error
- func (worker *MockRunnerWorker) SetStderr(writer io.Writer)
- func (worker *MockRunnerWorker) SetStdin(reader io.Reader)
- func (worker *MockRunnerWorker) SetStdout(writer io.Writer)
- func (worker *MockRunnerWorker) Start() error
- func (worker *MockRunnerWorker) StderrPipe() (io.Reader, error)
- func (worker *MockRunnerWorker) StdinPipe() (io.WriteCloser, error)
- func (worker *MockRunnerWorker) StdoutPipe() (io.Reader, error)
- func (worker *MockRunnerWorker) Wait() error
- type Remote
- func NewRemoteAgentAuthRunner(user, host, agent string) (*Remote, error)
- func NewRemoteAgentAuthRunnerWithTimeouts(user, host, agent string, timeouts Timeouts) (*Remote, error)
- func NewRemoteKeyAuthRunner(user, host, key string) (*Remote, error)
- func NewRemoteKeyAuthRunnerWithTimeouts(user, host, key string, timeouts Timeouts) (*Remote, error)
- func NewRemotePassAuthRunner(user, host, password string) (*Remote, error)
- func NewRemotePassAuthRunnerWithTimeouts(user, host, password string, timeouts Timeouts) (*Remote, error)
- func NewRemoteRawKeyAuthRunnerWithTimeouts(user, host, key string, timeouts Timeouts) (*Remote, error)
- type RemoteCmd
- func (remote *RemoteCmd) CmdError() error
- func (cmd *RemoteCmd) GetArgs() []string
- func (cmd *RemoteCmd) Output() ([]byte, []byte, error)
- func (cmd *RemoteCmd) Run() error
- func (cmd *RemoteCmd) SetStderr(buffer io.Writer)
- func (cmd *RemoteCmd) SetStdin(buffer io.Reader)
- func (cmd *RemoteCmd) SetStdout(buffer io.Writer)
- func (cmd *RemoteCmd) Start() error
- func (cmd *RemoteCmd) StderrPipe() (io.Reader, error)
- func (cmd *RemoteCmd) StdinPipe() (io.WriteCloser, error)
- func (cmd *RemoteCmd) StdoutPipe() (io.Reader, error)
- func (cmd *RemoteCmd) Wait() (err error)
- type Runner
- type Timeouts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CmdWorker ¶
type CmdWorker interface {
Run() error
Output() ([]byte, []byte, error)
Start() error
Wait() error
StdinPipe() (io.WriteCloser, error)
StdoutPipe() (io.Reader, error)
StderrPipe() (io.Reader, error)
SetStdout(io.Writer)
SetStderr(io.Writer)
SetStdin(io.Reader)
GetArgs() []string
CmdError() error
}
CmdWorker executes commands.
type Local ¶
type Local struct{}
Local is implementation of Runner interface for local commands
func NewLocalRunner ¶
NewLocalRunner creates instance of local runner
type LocalCmd ¶
type LocalCmd struct {
// contains filtered or unexported fields
}
LocalCmd is implementation of CmdWorker interface for local commands
func (*LocalCmd) StderrPipe ¶
StderrPipe returns stderr of current worker
func (*LocalCmd) StdinPipe ¶
func (cmd *LocalCmd) StdinPipe() (io.WriteCloser, error)
StdinPipe returns stdin of current worker
func (*LocalCmd) StdoutPipe ¶
StdoutPipe returns stdout of current worker
type MockRunner ¶
type MockRunner struct {
// Stdout is a bytes slice which will be returned as program's mock stdout.
Stdout []byte
// Stdout is a bytes slice which will be returned as program's mock stderr.
Stderr []byte
// Error is a error which will be used to fail program's run.
Error error
// OnCommand is a callback which will be called on each Command() call with
// worker which will be similar to exec.Cmd.
OnCommand func(*MockRunnerWorker)
}
MockRunner represents runner which is suitable for writing tests for code that uses runcmd library.
type MockRunnerWorker ¶
type MockRunnerWorker struct {
MockRunner
Args []string
// contains filtered or unexported fields
}
func (*MockRunnerWorker) CmdError ¶
func (worker *MockRunnerWorker) CmdError() error
func (*MockRunnerWorker) GetArgs ¶
func (worker *MockRunnerWorker) GetArgs() []string
GetArgs returns original command line arguments.
func (*MockRunnerWorker) Output ¶
func (worker *MockRunnerWorker) Output() ([]byte, []byte, error)
Output returns mocked stdout, stderr and execution error.
func (*MockRunnerWorker) Run ¶
func (worker *MockRunnerWorker) Run() error
Run runs Start() and then Wait().
func (*MockRunnerWorker) SetStderr ¶
func (worker *MockRunnerWorker) SetStderr(writer io.Writer)
SetStderr sets writer which will be used to write mocked stderr.
func (*MockRunnerWorker) SetStdin ¶
func (worker *MockRunnerWorker) SetStdin(reader io.Reader)
SetStdin sets reader which will be fully read on Start() or Run() till Wait().
func (*MockRunnerWorker) SetStdout ¶
func (worker *MockRunnerWorker) SetStdout(writer io.Writer)
SetStdout sets writer which will be used to write mocked stdout.
func (*MockRunnerWorker) Start ¶
func (worker *MockRunnerWorker) Start() error
Start will read all incoming stdin (if any), write stdout and stderr to specified output streams (if any is set up with SetStdout() or SetStderr() methods) and then returns error if any.
func (*MockRunnerWorker) StderrPipe ¶
func (worker *MockRunnerWorker) StderrPipe() (io.Reader, error)
StderrPipe returns reader with mocked stderr.
func (*MockRunnerWorker) StdinPipe ¶
func (worker *MockRunnerWorker) StdinPipe() (io.WriteCloser, error)
StdinPipe returns no-op writer.
func (*MockRunnerWorker) StdoutPipe ¶
func (worker *MockRunnerWorker) StdoutPipe() (io.Reader, error)
StdoutPipe returns reader with mocked stdout.
func (*MockRunnerWorker) Wait ¶
func (worker *MockRunnerWorker) Wait() error
Wait waits stdin, stdout and stderr streams are processed and returns error if any.
type Remote ¶
type Remote struct {
// contains filtered or unexported fields
}
Remote is implementation of Runner interface for remote commands
func NewRemoteAgentAuthRunner ¶
NewRemoteAgenntAuthRunner is one of functions for creating remote runner
func NewRemoteAgentAuthRunnerWithTimeouts ¶
func NewRemoteAgentAuthRunnerWithTimeouts(user, host, agent string, timeouts Timeouts) (*Remote, error)
NewRemoteAgentAuthRunnerWithTimeouts is one of functions for creating remote runner Use this one instead of NewRemoteAgentAuthRunner if you need to setup nondefault timeouts for ssh connection
func NewRemoteKeyAuthRunner ¶
NewRemoteKeyAuthRunner is one of functions for creating remote runner
func NewRemoteKeyAuthRunnerWithTimeouts ¶
func NewRemoteKeyAuthRunnerWithTimeouts( user, host, key string, timeouts Timeouts, ) (*Remote, error)
NewRemoteKeyAuthRunnerWithTimeouts is one of functions for creating remote runner. Use this one instead of NewRemoteKeyAuthRunner if you need to setup nondefault timeouts for ssh connection
func NewRemotePassAuthRunner ¶
NewRemotePassAuthRunner is one of functions for creating remote runner
func NewRemotePassAuthRunnerWithTimeouts ¶
func NewRemotePassAuthRunnerWithTimeouts( user, host, password string, timeouts Timeouts, ) (*Remote, error)
NewRemotePassAuthRunnerWithTimeouts is one of functions for creating remote runner. Use this one instead of NewRemotePassAuthRunner if you need to setup nondefault timeouts for ssh connection
func NewRemoteRawKeyAuthRunnerWithTimeouts ¶
func NewRemoteRawKeyAuthRunnerWithTimeouts( user, host, key string, timeouts Timeouts, ) (*Remote, error)
NewRemoteRawKeyAuthRunnerWithTimeouts is same, as NewRemoteKeyAuthRunnerWithTimeouts, but key should be raw byte sequence instead of path.
func (*Remote) CloseConnection ¶
CloseConnection is method for closing ssh connection of current runner
type RemoteCmd ¶
type RemoteCmd struct {
// contains filtered or unexported fields
}
RemoteCmd is implementation of CmdWorker interface for remote commands
func (*RemoteCmd) StderrPipe ¶
StderrPipe returns stderr of current worker
func (*RemoteCmd) StdinPipe ¶
func (cmd *RemoteCmd) StdinPipe() (io.WriteCloser, error)
StdinPipe returns stdin of current worker
func (*RemoteCmd) StdoutPipe ¶
StdoutPipe returns stdout of current worker