Documentation ¶
Overview ¶
Package stub has implementations of the shell package intended for use in tests where launching an external process is undesirable.
Index ¶
- func Match(command string, handler shell.Target) shell.Target
- func OneOf(handlers ...shell.Target) shell.Target
- func Regex(pattern string, handler shell.Target) shell.Target
- func Respond(response string) shell.Target
- func RespondTo(command string, response string) shell.Target
- type Delegate
- type Echo
- type MatchTarget
- type RegexpTarget
- type Response
- type Sequence
- type UnhandledCmdError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Match ¶
Match returns a MatchTarget that compares the command and delegates to handler if it matches.
func Regex ¶
Regex returns a RegexTarget that compares the command to the pattern and delegates to handler if it matches.
Types ¶
type Delegate ¶
type Delegate struct { // Handlers holds the set of possible command handlers. Handlers []shell.Target }
Delegate is an implementation of Target that passes all command requests to a the first child that accepts them. A child target refuses a command by returning nil,nil from it's Start method.
type Echo ¶
type Echo struct{}
Echo is an implementation of Target that acts like the echo command, printing the command arguments parameters to stdout.
type MatchTarget ¶
type MatchTarget struct { // Match is the command line to match Match string // Target is the underlying target to dispatch to if this target matches the command. Target shell.Target }
MatchTarget is an implementation of Target that passes the command to it's child target if it matches the supplied command.
type RegexpTarget ¶
type RegexpTarget struct { // Match is the regular expression for the command line to match Match *regexp.Regexp // Target is the underlying target to dispatch to if this target matches the command. Target shell.Target }
RegexpTarget is an implementation of Target that passes the command to it's child target if it matches the supplied regexp match pattern.
type Response ¶
type Response struct { // WaitSignal if set is waited on inside the Wait method of the process WaitSignal task.Signal // KillTask is invoked if it is non nil and the Kill method is called. KillTask task.Task // StartErr is returned by the target Start method if set. StartErr error // WaitErr is returned from the Wait method of the Process if set. WaitErr error // KillErr is returned from the Kill method of the Process if set. KillErr error // Stdout is the string to write as the standard output of the process. Stdout string // Stderr is the string to write as the standard error of the process. Stderr string }
Response is an implementation of Target that always gives exactly the same response.
type Sequence ¶
Sequence is an implementation of Target that holds a list of 'consumable' targets. Once a target's Start() returns an error that is not a UnhandledCmdError, the result is returned and the target it is removed from the Sequence list.
type UnhandledCmdError ¶
This is the error type returned when a command is not handled by the stub target.
func (UnhandledCmdError) Error ¶
func (u UnhandledCmdError) Error() string