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 ...
}
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 is an implementation of exec.Cmd that is used to return predefined results when exec.Cmd.Run is called.
func Commands ¶
Commands returns a Command that is primed with the provided responses. It's Command method can be used to override exec.Command.
func (*Command) Done ¶
Done returns an error if there were any unexpected commands called on c or if there are any non-optional responses left.
Done should be called once the test has finished calling c.Command.
func (*Command) Run ¶
Run runs the command. It expects there to be a corresponding Response to the command. If the command does not match the first remaining response Run searches for a matching Response that has OutOfOrder set to true. It also calls LogCommand with a string representation of a Response that matches this command.
Run returns nil if no matching response is found. Use c.Done to detect these errors.
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.