expect

package
v0.0.0-...-ebe072c Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const READ_SIZE = 4094

READ_SIZE is the largest amount of data expect attempts to read in a single I/O operation. This likely needs some research and tuning.

Variables

View Source
var ErrTimeout = errors.New("Expect Timeout")

ErrTimeout is returned from exp.Expect*() when a timeout is reached.

Functions

This section is empty.

Types

type Expect

type Expect struct {
	Killer func()
	// contains filtered or unexported fields
}

Expect is a program interaction session.

func Create

func Create(pty io.ReadWriteCloser, killer func(), logger Logger, timeout time.Duration) (exp *Expect)

Create an Expect instance from something that we can do read/writes off of.

Note: Close() must be called to cleanup this process.

func Spawn

func Spawn(name string, args ...string) (*Expect, error)

Create an Expect instance from a command. Effectively the same as Create(pty.Start(exec.Command(name, args...)))

func (*Expect) Buffer

func (exp *Expect) Buffer() []byte

Return the current buffer.

Note: This is not all data received off the network, but data that has been received for processing.

func (*Expect) Close

func (exp *Expect) Close() error

Kill & close off process.

Note: This *must* be run to cleanup the process

func (*Expect) Expect

func (exp *Expect) Expect(expr string) (m Match, err error)

Expect(s string) is equivalent to exp.ExpectRegexp(regexp.MustCompile(s))

func (*Expect) ExpectEOF

func (exp *Expect) ExpectEOF() error

Wait for EOF

func (*Expect) ExpectRegexp

func (exp *Expect) ExpectRegexp(pat *regexp.Regexp) (Match, error)

ExpectRegexp searches the I/O read stream for a pattern within .Timeout()

func (*Expect) Send

func (exp *Expect) Send(s string) error

Send data to program

func (*Expect) SendLn

func (exp *Expect) SendLn(lines ...string) error

Send several lines data (separated by \n) to the process

func (*Expect) SendMasked

func (exp *Expect) SendMasked(s string) error

Send data, but mark it as masked to observers. Use this for passwords

func (*Expect) SetTimeout

func (exp *Expect) SetTimeout(d time.Duration)

SetTimeout(Duration) sets the amount of time an Expect() call will wait for the output to appear.

func (*Expect) Timeout

func (exp *Expect) Timeout() time.Duration

Timeout() returns amount of time an Expect() call will wait for the output to appear.

type Logger

type Logger interface {

	// API user sent an item
	Send(time.Time, []byte)

	// API user sent a masked item. The masked data is included, but the API user is advised to
	// not log this data in production.
	SendMasked(time.Time, []byte)

	// Data is received by the same goroutine as the API user.
	Recv(time.Time, []byte)

	// Data is received off the network
	RecvNet(time.Time, []byte)

	// EOF has been reached. Time is when the EOF was received off the network
	RecvEOF(time.Time)

	// API user ran some form of Expect* call
	ExpectCall(time.Time, *regexp.Regexp)

	// API user got a return back from an Expect* call
	ExpectReturn(time.Time, Match, error)

	// Close the log file / this is the last item
	Close(time.Time)
}

type Match

type Match struct {
	Before string
	Groups []string
}

Match is returned from exp.Expect*() when a match is found.

Jump to

Keyboard shortcuts

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