stub

package
v3.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package stub has implementations of the shell package intended for use in tests where launching an external process is undesirable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(command string, handler shell.Target) shell.Target

Match returns a MatchTarget that compares the command and delegates to handler if it matches.

func OneOf

func OneOf(handlers ...shell.Target) shell.Target

OneOf returns a Delegate that uses the supplied handlers.

func Regex

func Regex(pattern string, handler shell.Target) shell.Target

Regex returns a RegexTarget that compares the command to the pattern and delegates to handler if it matches.

func Respond

func Respond(response string) shell.Target

Respond returns the simplest type of Response that just writes the response to the stdout.

func RespondTo

func RespondTo(command string, response string) shell.Target

RespondTo builds a target that matches the supplied command and writes the response to stdout 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.

func (*Delegate) Start

func (t *Delegate) Start(cmd shell.Cmd) (shell.Process, error)

func (Delegate) String

func (Delegate) String() string

type Echo

type Echo struct{}

Echo is an implementation of Target that acts like the echo command, printing the command arguments parameters to stdout.

func (Echo) Start

func (Echo) Start(cmd shell.Cmd) (shell.Process, error)

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.

func (*MatchTarget) Start

func (t *MatchTarget) Start(cmd shell.Cmd) (shell.Process, error)

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.

func (*RegexpTarget) Start

func (t *RegexpTarget) Start(cmd shell.Cmd) (shell.Process, error)

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.

func (*Response) Start

func (t *Response) Start(cmd shell.Cmd) (shell.Process, error)

type Sequence

type Sequence []shell.Target

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.

func (*Sequence) Start

func (s *Sequence) Start(cmd shell.Cmd) (shell.Process, error)

func (Sequence) String

func (Sequence) String() string

type UnhandledCmdError

type UnhandledCmdError shell.Cmd

This is the error type returned when a command is not handled by the stub target.

func (UnhandledCmdError) Error

func (u UnhandledCmdError) Error() string

Jump to

Keyboard shortcuts

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