expect: github.com/jamesharr/expect Index | Files | Directories

package expect

import "github.com/jamesharr/expect"


Package Files

expect.go log_manager.go logger.go logger_file.go logger_nil.go logger_tester.go


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.


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

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

type Expect Uses

type Expect struct {
    // contains filtered or unexported fields

Expect is a program interaction session.

func Create Uses

func Create(pty io.ReadWriteCloser, killer func()) (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 Uses

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 Uses

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 Uses

func (exp *Expect) Close() error

Kill & close off process.

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

func (*Expect) Expect Uses

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

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

func (*Expect) ExpectEOF Uses

func (exp *Expect) ExpectEOF() error

Wait for EOF

func (*Expect) ExpectRegexp Uses

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

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

func (*Expect) Send Uses

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

Send data to program

func (*Expect) SendLn Uses

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

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

func (*Expect) SendMasked Uses

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

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

func (*Expect) SetLogger Uses

func (exp *Expect) SetLogger(logger Logger)

Set up an I/O logger

func (*Expect) SetTimeout Uses

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 Uses

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

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

type Logger Uses

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

    // 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

func FileLogger Uses

func FileLogger(filename string) Logger

Create an appending file logger.

func StderrLogger Uses

func StderrLogger() Logger

func TestLogger Uses

func TestLogger(t *testing.T) Logger

Logging adapter for `testing.T` test cases

type Match Uses

type Match struct {
    Before string
    Groups []string

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

type NilLogger Uses

type NilLogger struct{}

func (*NilLogger) Close Uses

func (*NilLogger) Close(time.Time)

func (*NilLogger) EOF Uses

func (*NilLogger) EOF(time.Time)

func (*NilLogger) ExpectCall Uses

func (*NilLogger) ExpectCall(time.Time, *regexp.Regexp)

func (*NilLogger) ExpectReturn Uses

func (*NilLogger) ExpectReturn(time.Time, Match, error)

func (*NilLogger) Recv Uses

func (*NilLogger) Recv(time.Time, []byte)

func (*NilLogger) Send Uses

func (*NilLogger) Send(time.Time, []byte)

func (*NilLogger) SendMasked Uses

func (*NilLogger) SendMasked(time.Time, []byte)



Package expect imports 11 packages (graph) and is imported by 2 packages. Updated 2017-01-24. Refresh now. Tools for package owners.