Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
Builder = RealBuilder()
)
Functions ¶
func CommandContext ¶
CommandContext creates a command with the global builder using the given context.
func MockExecHelper ¶
func MockExecHelper()
MockExecHelper implements the logic for the helper process.
This function should be called from a test stub in your program used exclusively for creating processes. The test stub shouldn't do anything else.
Types ¶
type CmdBuilder ¶
type CmdBuilder interface { Command(cmd string, args ...string) *osexec.Cmd CommandContext(ctx context.Context, cmd string, args ...string) *osexec.Cmd }
CmdBuilder is an interface to a type which builds commands.
This is used to allow mocking exec.Command().Run().
func RealBuilder ¶
func RealBuilder() CmdBuilder
type MockBuilder ¶
MockBuilder is a CmdBuilder which builds test Cmd instances.
func NewMockBuilder ¶
func NewMockBuilder(helper string, entries ...MockEntry) *MockBuilder
NewMockBuilder creates a new builder which creates mock Commands.
func (*MockBuilder) Command ¶
func (mb *MockBuilder) Command(cmd string, args ...string) *osexec.Cmd
Command returns a test command with no context.
func (*MockBuilder) CommandContext ¶
CommandContext returns a test command with the given context.
func (*MockBuilder) Reset ¶
func (mb *MockBuilder) Reset(entries ...MockEntry)
Reset sets the index of the MockBuilder to 0 and changes the entry list.
type MockEntry ¶
type MockEntry struct { // ExitCode is the exit code the process should exit with ExitCode int // Sleep is how long the process should sleep to simulate a hang. Sleep time.Duration // Output is a string to write to os.Stdout Output string // Extra is an array of extra environment variables to pass. Extra []string }
MockEntry describes the execution of one mock subprocess.
func (*MockEntry) GetEnvVars ¶
GetEnvVars returns environment variables for the test process.