Documentation
¶
Overview ¶
Package fake is used to fake calls github.com/openconfig/kne/exec.
Typical Usage:
import "github.com/openconfig/kne/exec"
{
responses := []fake.Response{...}
cmds := fake.Commands(responses)
oCommand := kexec.Command
defer func() {
kexec.Command = oCommand
if err := cmds.Done(); err != nil {
// handle the error
}
}()
kexec.Command = cmds.Command
... test code ...
}
A Command is safe for concurrent use. Each call to Command returns an independent exec.Cmd, and the responses are consumed under a lock, so code under test may run commands from multiple goroutines. Note that responses are still matched in order by default: when the commands may be issued concurrently, the order they arrive in is not deterministic, so the corresponding responses must be marked OutOfOrder.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var LogCommand = func(string) {}
LogCommand is called with the string representation of the command that is running. The test program can optionally set this to their own function.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
Name string // if set it is included in errors
// contains filtered or unexported fields
}
A Command hands out exec.Cmd implementations that return predefined results when exec.Cmd.Run is called. The zero value is not useful; use Commands.
A Command is safe for concurrent use by multiple goroutines.
func Commands ¶
Commands returns a Command that is primed with the provided responses. It's Command method can be used to override exec.Command.
type DoneError ¶
type DoneError struct {
Source string
Unexpected []Response // Unexpected calls
Unused []Response // Unused calls
}
A DoneError is returned when the calls to a Command do not match the Responses.