exec

package
v0.0.0-...-96e1417 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Builder = RealBuilder()
)

Functions

func Command

func Command(cmd string, args ...string) *osexec.Cmd

Command creates a command with the global builder.

func CommandContext

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

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

type MockBuilder struct {
	Index   int
	Entries []MockEntry
	Helper  string
}

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

func (mb *MockBuilder) CommandContext(ctx context.Context, cmd string, args ...string) *osexec.Cmd

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

func (me *MockEntry) GetEnvVars() []string

GetEnvVars returns environment variables for the test process.

Jump to

Keyboard shortcuts

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