interactive

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package interactive provides common implementations of the expect.Expecter interface including oc, shell, and ssh.

Index

Constants

This section is empty.

Variables

View Source
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

func NewContext(expecter *expect.Expecter, errorChannel <-chan error) *Context

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

func SpawnShell(spawner *Spawner, timeout time.Duration, opts ...expect.Option) (*Context, error)

SpawnShell creates an interactive shell subprocess based on the value of $SHELL, spawning the appropriate underlying PTY.

func (*Context) GetErrorChannel

func (c *Context) GetErrorChannel() <-chan error

GetErrorChannel returns the error channel.

func (*Context) GetExpecter

func (c *Context) GetExpecter() *expect.Expecter

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) Start

func (e *ExecSpawnFunc) Start() error

Start wraps exec.Cmd.Start.

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

func (*ExecSpawnFunc) Wait

func (e *ExecSpawnFunc) Wait() error

Wait wraps exec.Cmd.Wait.

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

func (o *Oc) GetErrorChannel() <-chan error

GetErrorChannel returns the error channel for interactive monitoring.

func (*Oc) GetExpecter

func (o *Oc) GetExpecter() *expect.Expecter

GetExpecter returns a reference to the expect.Expecter reference used to control the OpenShift client.

func (*Oc) GetOptions

func (o *Oc) GetOptions() []expect.Option

GetOptions returns the options, such as verbosity.

func (*Oc) GetPodContainerName

func (o *Oc) GetPodContainerName() string

GetPodContainerName returns the name of the container.

func (*Oc) GetPodName

func (o *Oc) GetPodName() string

GetPodName returns the name of the pod.

func (*Oc) GetPodNamespace

func (o *Oc) GetPodNamespace() string

GetPodNamespace extracts the namespace of the pod.

func (*Oc) GetTimeout

func (o *Oc) GetTimeout() time.Duration

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.

Directories

Path Synopsis
Package mock_expect is a generated GoMock package.
Package mock_expect is a generated GoMock package.

Jump to

Keyboard shortcuts

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