expect

package module
v0.0.0-...-61b9061 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 6 Imported by: 0

README

conn-expect

A simple expect library designed around using net.Conn

GoDoc Build Status Code Coverage

The tests in expect_test.go are sufficient enough to get started.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BCallback

type BCallback struct {
	Callback func()
}

BCallback calls the callback, nothing more. Useful for regression testing.

func (*BCallback) Invoke

func (b *BCallback) Invoke(ctx context.Context, exp *Expect, timeout time.Duration, batchIdx int) error

Invoke fulfils the Batcher interface

type BRecv

type BRecv struct {
	//  Re is required, it's the regular expression to use for matching
	Re *regexp.Regexp
	// OnSuccess is optional, the first element is the entire matched pattern,
	// the subsequent elements are submatches. Returning an error from here will
	// stop the Batch operation and return with an error
	OnSuccess       func(matched []string) error
	OnSuccessInject func(matched []string) ([]Batcher, error)
}

BRecv allows regexps to be matched on input

func (*BRecv) Invoke

func (b *BRecv) Invoke(ctx context.Context, exp *Expect, timeout time.Duration, batchIdx int) error

Invoke fulfils the Batcher interface

type BSend

type BSend struct {
	// Data stores the string to be sent over the connection
	Data string
	// OnSuccess is optional, returning an error from here will
	// stop the Batch operation and return with an error
	OnSuccess func() error
}

BSend sends data through the net.Conn interface

func (*BSend) Invoke

func (b *BSend) Invoke(ctx context.Context, exp *Expect, timeout time.Duration, batchIdx int) error

Invoke fulfils the Batcher interface

type BSendDyn

type BSendDyn struct {
	Data      func() string // Data is required, the result is treated like BSend.Data
	OnSuccess func() error  // OnSuccess is like BSend.OnSuccess, it is optional
}

BSendDyn is like BSend however it determines what will be sent by calling the Data() callback

func (*BSendDyn) Invoke

func (b *BSendDyn) Invoke(ctx context.Context, exp *Expect, timeout time.Duration, batchIdx int) error

Invoke fulfils the Batcher interface

type BSwitch

type BSwitch []*BSwitchOption

BSwitch allows regexps to be matched on input, and provide different execution paths depending on the matches

func (BSwitch) Invoke

func (bs BSwitch) Invoke(ctx context.Context, exp *Expect, timeout time.Duration, batchIdx int) error

Invoke fulfils the Batcher interface

type BSwitchOption

type BSwitchOption struct {
	// BRecv
	BRecv
	// Child contains the actions to be run if the Re matches
	Child []Batcher
}

BSwitchOption holds each possibility stored in a BSwitch

type BWipeBuf

type BWipeBuf struct{}

BWipeBuf flushes any cached inbound data. You probably don't want to call this.

func (*BWipeBuf) Invoke

func (b *BWipeBuf) Invoke(ctx context.Context, exp *Expect, timeout time.Duration, batchIdx int) error

Invoke fulfils the Batcher interface

type Batcher

type Batcher interface {
	// Invoke
	//
	// batchIdx is the index of the batch object, starting at 0
	Invoke(ctx context.Context, exp *Expect, timeout time.Duration, batchIdx int) error
}

Batcher is the simple interface all batch records implement

type Error

type Error struct {
	BatchIdx int
	Orig     error
	Op       Batcher
}

Error is the struct that all errors returned by Batch/BatchContext are wrapped in

func (*Error) Error

func (err *Error) Error() string

func (*Error) Is

func (e *Error) Is(err error) bool

Support Is(error) and Unwrap() implicit interfaces for errors.Is/As

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Expect

type Expect struct {
	//Encoding Encoding
	Logger func(msg Log)
	Conn   net.Conn
	// contains filtered or unexported fields
}

func (*Expect) Batch

func (e *Expect) Batch(timeout time.Duration, batches ...Batcher) error

Batch calls Batcher with a context.Background() for context

func (*Expect) BatchContext

func (e *Expect) BatchContext(ctx context.Context, timeout time.Duration, ops ...Batcher) error

BatchContext allows multiple batched requests/responses. timeout operates on a per command basis, to limit the total time that can be used set a deadline on the passed in context.

type Log

type Log struct {
	Type MsgType
	Data string
}

Log is used in combination with the Logger method of the Expect type, to log all inbound/outbound network traffic

type MsgType

type MsgType string
const (
	MsgRecv MsgType = "recv"
	MsgSend MsgType = "send"
)

Jump to

Keyboard shortcuts

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