Documentation
¶
Index ¶
- Variables
- func TestExpectObserveFn(t *testing.T) expect.ExpectObserver
- func TestSendObserveFn(t *testing.T) func(string, int, error)
- type ConsoleProcess
- func (cp *ConsoleProcess) Close() error
- func (cp *ConsoleProcess) Cmd() *exec.Cmd
- func (cp *ConsoleProcess) Executable() string
- func (cp *ConsoleProcess) Expect(value string, timeout ...time.Duration) (string, error)
- func (cp *ConsoleProcess) ExpectCustom(opt expect.ExpectOpt, timeout ...time.Duration) (string, error)
- func (cp *ConsoleProcess) ExpectExitCode(exitCode int, timeout ...time.Duration) (string, error)
- func (cp *ConsoleProcess) ExpectLongString(value string, timeout ...time.Duration) (string, error)
- func (cp *ConsoleProcess) ExpectNotExitCode(exitCode int, timeout ...time.Duration) (string, error)
- func (cp *ConsoleProcess) ExpectRe(value string, timeout ...time.Duration) (string, error)
- func (cp *ConsoleProcess) MatchState() *expect.MatchState
- func (cp *ConsoleProcess) Send(value string)
- func (cp *ConsoleProcess) SendCtrlC()
- func (cp *ConsoleProcess) SendLine(value string)
- func (cp *ConsoleProcess) SendUnterminated(value string)
- func (cp *ConsoleProcess) Signal(sig os.Signal) error
- func (cp *ConsoleProcess) Snapshot() string
- func (cp *ConsoleProcess) Stop() error
- func (cp *ConsoleProcess) TrimmedSnapshot() string
- func (cp *ConsoleProcess) Wait(timeout ...time.Duration)
- func (cp *ConsoleProcess) WaitForInput(timeout ...time.Duration) (string, error)
- func (cp *ConsoleProcess) WorkDirectory() string
- type Options
- type SendObserver
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoProcess is returned when a process was expected to be running ErrNoProcess = errors.New("no command process seems to be running") )
var ErrWaitTimeout = errWaitTimeout{fmt.Errorf("timeout waiting for exit code")}
ErrWaitTimeout is returned when we time out waiting for the console process to exit
Functions ¶
func TestExpectObserveFn ¶
func TestExpectObserveFn(t *testing.T) expect.ExpectObserver
TestExpectObserveFn an example for a ExpectObserver function, it reports any error occurring durint expect calls to the supplied testing instance
Types ¶
type ConsoleProcess ¶
type ConsoleProcess struct {
// contains filtered or unexported fields
}
ConsoleProcess bonds a command with a pseudo-terminal for automation
func New ¶
func New(opts Options) (*ConsoleProcess, error)
New bonds a command process with a console pty.
func NewTest ¶ added in v0.5.0
func NewTest(t *testing.T, opts Options) (*ConsoleProcess, error)
NewTest bonds a command process with a console pty and sets it up for testing
func (*ConsoleProcess) Close ¶
func (cp *ConsoleProcess) Close() error
Close cleans up all the resources allocated by the ConsoleProcess If the underlying process is still running, it is terminated with a SIGTERM signal.
func (*ConsoleProcess) Cmd ¶ added in v0.7.2
func (cp *ConsoleProcess) Cmd() *exec.Cmd
Cmd returns the underlying command
func (*ConsoleProcess) Executable ¶
func (cp *ConsoleProcess) Executable() string
Executable returns the command name to be executed
func (*ConsoleProcess) Expect ¶
Expect listens to the terminal output and returns once the expected value is found or a timeout occurs Default timeout is 10 seconds
func (*ConsoleProcess) ExpectCustom ¶ added in v0.7.2
func (cp *ConsoleProcess) ExpectCustom(opt expect.ExpectOpt, timeout ...time.Duration) (string, error)
ExpectCustom listens to the terminal output and returns once the supplied condition is satisfied or a timeout occurs Default timeout is 10 seconds
func (*ConsoleProcess) ExpectExitCode ¶
ExpectExitCode waits for the program under test to terminate, and checks that the returned exit code meets expectations
func (*ConsoleProcess) ExpectLongString ¶ added in v0.5.5
ExpectLongString listens to the terminal output and returns once the expected value is found or a timeout occurs This function ignores mismatches caused by newline and space characters to account for wrappings at the maximum terminal width. Default timeout is 10 seconds
func (*ConsoleProcess) ExpectNotExitCode ¶
ExpectNotExitCode waits for the program under test to terminate, and checks that the returned exit code is not the value provide
func (*ConsoleProcess) ExpectRe ¶
ExpectRe listens to the terminal output and returns once the expected regular expression is matched or a timeout occurs Default timeout is 10 seconds
func (*ConsoleProcess) MatchState ¶ added in v0.5.0
func (cp *ConsoleProcess) MatchState() *expect.MatchState
MatchState returns the current state of the expect-matcher
func (*ConsoleProcess) Send ¶
func (cp *ConsoleProcess) Send(value string)
Send sends a new line to the terminal, as if a user typed it
func (*ConsoleProcess) SendCtrlC ¶
func (cp *ConsoleProcess) SendCtrlC()
SendCtrlC tries to emulate what would happen in an interactive shell, when the user presses Ctrl-C Note: On Windows the Ctrl-C event is only reliable caught when the receiving process is listening for os.Interrupt signals.
func (*ConsoleProcess) SendLine ¶
func (cp *ConsoleProcess) SendLine(value string)
SendLine sends a new line to the terminal, as if a user typed it, the newline sequence is OS aware
func (*ConsoleProcess) SendUnterminated ¶ added in v0.7.1
func (cp *ConsoleProcess) SendUnterminated(value string)
SendUnterminated sends a string to the terminal as if a user typed it
func (*ConsoleProcess) Signal ¶
func (cp *ConsoleProcess) Signal(sig os.Signal) error
Signal sends an arbitrary signal to the running process
func (*ConsoleProcess) Snapshot ¶
func (cp *ConsoleProcess) Snapshot() string
Snapshot returns a string containing a terminal snap-shot as a user would see it in a "real" terminal
func (*ConsoleProcess) Stop ¶
func (cp *ConsoleProcess) Stop() error
Stop sends an interrupt signal for the tested process and fails if no process has been started yet. Note: This is not supported on Windows
func (*ConsoleProcess) TrimmedSnapshot ¶
func (cp *ConsoleProcess) TrimmedSnapshot() string
TrimmedSnapshot displays the terminal output a user would see however the goroutine that creates this output is separate from this function so any output is not synced
func (*ConsoleProcess) Wait ¶
func (cp *ConsoleProcess) Wait(timeout ...time.Duration)
Wait waits for the program under test to terminate, not caring about the exit code at all
func (*ConsoleProcess) WaitForInput ¶
func (cp *ConsoleProcess) WaitForInput(timeout ...time.Duration) (string, error)
WaitForInput returns once a shell prompt is active on the terminal Default timeout is 10 seconds
func (*ConsoleProcess) WorkDirectory ¶
func (cp *ConsoleProcess) WorkDirectory() string
WorkDirectory returns the directory in which the command shall be run
type Options ¶
type Options struct { DefaultTimeout time.Duration WorkDirectory string RetainWorkDir bool Environment []string ObserveSend SendObserver ObserveExpect expect.ExpectObserver CmdName string Args []string HideCmdLine bool ExtraOpts []expect.ConsoleOpt }
Options contain optional values for ConsoleProcess construction and usage.
type SendObserver ¶
SendObserver is function that is called when text is send to the console Arguments are the message, number of bytes written and an error message See TestSendObserveFn for an example
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
conpty
module
|
|
expect
module
|
|
internal
|
|
test
|
|
helloworld
Module
|
|
pty
Module
|
|
pty_deadlock
Module
|
|
xpty
module
|