Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithMockExecutor ¶
func WithMockExecutor(f func(MockExecutor), wrapped ...command.Executor)
WithMockExecutor will replace the default command.Executor with a MockExecutor and then call f. The executor is passed to f to be able to make assertions and control command return values. WithMockExecutor will restore the previous default executor after f returns or panics. Optionally another executor can be passed which will be used by the MockExecutor if passthrough of a command is explicitly requested.
Types ¶
type ExpectedCommand ¶
type ExpectedCommand struct {
// contains filtered or unexported fields
}
ExpectedCommand is used to configure expectations a the MockExecutor.
func (*ExpectedCommand) String ¶
func (e *ExpectedCommand) String() string
String implements fmt.Stringer.
func (*ExpectedCommand) WillExecute ¶
func (e *ExpectedCommand) WillExecute() *ExpectedCommand
WillExecute marks the expected command to be run with a command.Executor wrapped by the MockExecutor.
func (*ExpectedCommand) WillReturn ¶
func (e *ExpectedCommand) WillReturn(out string) *ExpectedCommand
WillReturn will configure the ExpectedCommand to return the string out.
func (*ExpectedCommand) WillReturnError ¶
func (e *ExpectedCommand) WillReturnError(err error) *ExpectedCommand
WillReturnError will configure the ExpectedCommand to return error err.
type MockExecutor ¶
type MockExecutor interface { command.Executor // ExpectedCommand creates a new expectation for command cmd. Cmd can be a // regular expression. ExpectCommand(cmd string) *ExpectedCommand // ExpectationsWereMet should be called after all test assertions have been // made. It returns an error if there are commands that where expected but // have not been called. ExpectationsWereMet() error }
MockExecutor is a command.Executor that allows to mock executed commands.
func NewMockExecutor ¶
func NewMockExecutor(executor command.Executor) MockExecutor
NewMockExecutor creates a new MockExecutor.