fakeexec

package
v0.0.0-...-56aa1ee Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package fakeexec is used to mock calls to exec.Command. The following function must be included in a *_test.go file.

func TestExecCommandHelper(t *testing.T) {
	if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
		return
	}
	fmt.Print(os.Getenv("STDOUT"))
	i, _ := strconv.Atoi(os.Getenv("EXIT_STATUS"))
	os.Exit(i)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type E

type E struct {
	// contains filtered or unexported fields
}

E represents a set of expected executions of a command

func New

func New(t testing.TB) *E

New create a new E

func (*E) Cmd

func (e *E) Cmd() func(command string, args ...string) *exec.Cmd

Cmd returns a function with a signiture that matches (os/exec).Command

func (*E) Expect

func (e *E) Expect(command string, args ...string) *Expect

Expect is adds a new expectation

func (*E) ExpectFunc

func (e *E) ExpectFunc(f func(t testing.TB, command string, args ...string)) *Expect

ExpectFunc adds a new expectation, command and args can be checked for correctness by the supplied function

func (*E) Finish

func (e *E) Finish()

Finish checks all expectations have been met

type Expect

type Expect struct {
	// contains filtered or unexported fields
}

Expect controls the expected execution of a command

func (*Expect) Exits

func (e *Expect) Exits(code int)

Exits set the exit code of the execution

func (*Expect) Outputs

func (e *Expect) Outputs(stdout string)

Outputs sets the executions standard output

Jump to

Keyboard shortcuts

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