Documentation ¶
Overview ¶
Package exectest provides a means of mocking [os/exec.Cmd]s allowing injection of arbitrary behavior into an external executable from a test.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Actor ¶
type Actor struct {
// contains filtered or unexported fields
}
Actor defines a fake behavior (or act) for an external executable. Build these with Act.
func Act ¶
Act builds an actor that acts as specified in the given function.
Because of how this operates:
- call this near the top of a test function
- avoid non-determistic code before this function is called
- do not call this inside subtests
func (*Actor) CommandContext ¶ added in v0.5.0
CommandContext builds an exec.Cmd that will run this Actor as an external executable with the provided arguments.
This operates by re-running the test executable to run only the current test, and hijacking that test execution to run the main function.
actor := exectest.Act(t, func() { fmt.Println("hello") }) cmd := actor.CommandContext(ctx, args) got, err := cmd.Output() ... fmt.Println(string(got) == "hello\n") // true
Click to show internal directories.
Click to hide internal directories.