Documentation
¶
Overview ¶
Package interactive provides common implementations of the expect.Expecter interface including oc, shell, and ssh.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var UnitTestMode = false
UnitTestMode is used to determine if the context is unit test oriented v.s. an actual CNF test run, so appropriate mock interfaces can be injected. This allows the spanFunc to be injected without complicating the Spawner interface.
Functions ¶
func SetSpawnFunc ¶
func SetSpawnFunc(sFunc *SpawnFunc)
SetSpawnFunc sets the SpawnFunc, allowing for the actual CNF tests to be run or mocked for unit test purposes.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents an interactive context. This abstraction is meant to be overloaded, and can represent something as simple as a shell, to as complex as an interactive OpenShift client or SSH session. Context follows the Container design pattern, and is a simple data transfer object.
func NewContext ¶
NewContext creates a Context.
func SpawnSSH ¶
func SpawnSSH(spawner *Spawner, user, host string, timeout time.Duration, opts ...expect.Option) (*Context, error)
SpawnSSH spawns an SSH session to a generic linux host using ssh provided by openssh-clients. Takes care of establishing the pseudo-terminal (PTY) through expect.SpawnGeneric(). TODO: This method currently relies upon passwordless SSH setup beforehand. Handle all types of auth.
func SpawnShell ¶
SpawnShell creates an interactive shell subprocess based on the value of $SHELL, spawning the appropriate underlying PTY.
func (*Context) GetErrorChannel ¶
GetErrorChannel returns the error channel.
func (*Context) GetExpecter ¶
GetExpecter returns the expect.Expecter Context.
type ExecSpawnFunc ¶
type ExecSpawnFunc struct {
// contains filtered or unexported fields
}
ExecSpawnFunc is an implementation of SpawnFunc using exec.Cmd.
func (*ExecSpawnFunc) Command ¶
func (e *ExecSpawnFunc) Command(name string, arg ...string) *SpawnFunc
Command wraps exec.Cmd.Command.
func (*ExecSpawnFunc) StdinPipe ¶
func (e *ExecSpawnFunc) StdinPipe() (io.WriteCloser, error)
StdinPipe wraps exec.Cmd.StdinPipe
func (*ExecSpawnFunc) StdoutPipe ¶
func (e *ExecSpawnFunc) StdoutPipe() (io.Reader, error)
StdoutPipe wraps exec.Cmd.Stdoutpipe
type GoExpectSpawner ¶
type GoExpectSpawner struct { }
GoExpectSpawner provides an implementation of a Spawner based on GoExpect. This was abstracted for testing purposes.
func NewGoExpectSpawner ¶
func NewGoExpectSpawner() *GoExpectSpawner
NewGoExpectSpawner creates a new GoExpectSpawner.
func (*GoExpectSpawner) Spawn ¶
func (g *GoExpectSpawner) Spawn(command string, args []string, timeout time.Duration, opts ...expect.Option) (*Context, error)
Spawn creates a subprocess, setting standard input and standard output appropriately. This is the base method to create any interactive PTY based process.
type Oc ¶
type Oc struct {
// contains filtered or unexported fields
}
Oc provides an OpenShift Client designed to wrap the "oc" CLI.
func SpawnOc ¶
func SpawnOc(spawner *Spawner, pod, container, namespace string, timeout time.Duration, opts ...expect.Option) (*Oc, <-chan error, error)
SpawnOc creates an OpenShift Client subprocess, spawning the appropriate underlying PTY.
func (*Oc) GetErrorChannel ¶
GetErrorChannel returns the error channel for interactive monitoring.
func (*Oc) GetExpecter ¶
GetExpecter returns a reference to the expect.Expecter reference used to control the OpenShift client.
func (*Oc) GetOptions ¶
GetOptions returns the options, such as verbosity.
func (*Oc) GetPodContainerName ¶
GetPodContainerName returns the name of the container.
func (*Oc) GetPodNamespace ¶
GetPodNamespace extracts the namespace of the pod.
func (*Oc) GetTimeout ¶
GetTimeout returns the timeout for the expect.Expecter.
type SpawnFunc ¶
type SpawnFunc interface { // Command consult exec.Cmd.Command Command(name string, arg ...string) *SpawnFunc // Start consult exec.Cmd.Start. Start() error // StdinPipe consult exec.Cmd.StdinPipe StdinPipe() (io.WriteCloser, error) // StdoutPipe consult exec.Cmd.StdoutPipe StdoutPipe() (io.Reader, error) // Wait consult exec.Cmd.Wait Wait() error }
SpawnFunc Abstracts a wrapper interface over the required methods of the exec.Cmd API for testing purposes.
type Spawner ¶
type Spawner interface { // Spawn creates the interactive session. Spawn(command string, args []string, timeout time.Duration, opts ...expect.Option) (*Context, error) }
Spawner provides an interface for creating interactive sessions such as oc, ssh, or shell.
func CreateGoExpectSpawner ¶
func CreateGoExpectSpawner() *Spawner
CreateGoExpectSpawner creates a GoExpectSpawner implementation and returns it as a *Spawner for type compatibility reasons.