commandtest

package
v0.0.0-...-35b42f4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: MIT Imports: 6 Imported by: 0

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.

Jump to

Keyboard shortcuts

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