conntest

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2017 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package conntest implements fakes for package conn.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errorf

func Errorf(format string, a ...interface{}) error

Errorf returns a new error that returns true with IsErr().

func IsErr

func IsErr(err error) bool

IsErr returns true if the error is from a conntest failure.

Types

type Discard

type Discard struct {
	D conn.Duplex
}

Discard implements conn.Conn and discards all writes and reads zeros. It never fails.

func (*Discard) Duplex

func (d *Discard) Duplex() conn.Duplex

Duplex implements conn.Conn.

func (*Discard) String

func (d *Discard) String() string

func (*Discard) Tx

func (d *Discard) Tx(w, r []byte) error

Tx implements conn.Conn.

type IO

type IO struct {
	W []byte
	R []byte
}

IO registers the I/O that happened on either a real or fake connection.

type Playback

type Playback struct {
	sync.Mutex
	Ops       []IO
	D         conn.Duplex
	Count     int
	DontPanic bool
}

Playback implements conn.Conn and plays back a recorded I/O flow.

While "replay" type of unit tests are of limited value, they still present an easy way to do basic code coverage.

Set DontPanic to true to return an error instead of panicking, which is the default.

func (*Playback) Close

func (p *Playback) Close() error

Close verifies that all the expected Ops have been consumed.

func (*Playback) Duplex

func (p *Playback) Duplex() conn.Duplex

Duplex implements conn.Conn.

func (*Playback) String

func (p *Playback) String() string

func (*Playback) Tx

func (p *Playback) Tx(w, r []byte) error

Tx implements conn.Conn.

type Record

type Record struct {
	sync.Mutex
	Conn conn.Conn // Conn can be nil if only writes are being recorded.
	Ops  []IO
}

Record implements conn.Conn that records everything written to it.

This can then be used to feed to Playback to do "replay" based unit tests.

func (*Record) Duplex

func (r *Record) Duplex() conn.Duplex

Duplex implements conn.Conn.

func (*Record) String

func (r *Record) String() string

func (*Record) Tx

func (r *Record) Tx(w, read []byte) error

Tx implements conn.Conn.

type RecordRaw

type RecordRaw struct {
	sync.Mutex
	W io.Writer
}

RecordRaw implements conn.Conn. It sends everything written to it to W.

func (*RecordRaw) Duplex

func (r *RecordRaw) Duplex() conn.Duplex

Duplex implements conn.Conn.

func (*RecordRaw) String

func (r *RecordRaw) String() string

func (*RecordRaw) Tx

func (r *RecordRaw) Tx(w, read []byte) error

Tx implements conn.Conn.

Jump to

Keyboard shortcuts

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