periph: periph.io/x/periph/conn/conntest Index | Files

package conntest

import "periph.io/x/periph/conn/conntest"

Package conntest implements fakes for package conn.

Index

Package Files

conntest.go

func Errorf Uses

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

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

func IsErr Uses

func IsErr(err error) bool

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

type Discard Uses

type Discard struct {
    D conn.Duplex
}

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

func (*Discard) Duplex Uses

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

Duplex implements conn.Conn.

func (*Discard) String Uses

func (d *Discard) String() string

func (*Discard) Tx Uses

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

Tx implements conn.Conn.

type IO Uses

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

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

type Playback Uses

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 Uses

func (p *Playback) Close() error

Close verifies that all the expected Ops have been consumed.

func (*Playback) Duplex Uses

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

Duplex implements conn.Conn.

func (*Playback) String Uses

func (p *Playback) String() string

func (*Playback) Tx Uses

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

Tx implements conn.Conn.

type Record Uses

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 Uses

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

Duplex implements conn.Conn.

func (*Record) String Uses

func (r *Record) String() string

func (*Record) Tx Uses

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

Tx implements conn.Conn.

type RecordRaw Uses

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

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

func (*RecordRaw) Duplex Uses

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

Duplex implements conn.Conn.

func (*RecordRaw) String Uses

func (r *RecordRaw) String() string

func (*RecordRaw) Tx Uses

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

Tx implements conn.Conn.

Package conntest imports 5 packages (graph) and is imported by 8 packages. Updated 2017-12-31. Refresh now. Tools for package owners.