mockconn

package module
v0.0.0-...-cb30d06 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func New

func New(received *bytes.Buffer, responseReader io.Reader) *Conn

func NewConn

func NewConn(received *bytes.Buffer, responseReader io.Reader, readError error, writeError error) *Conn

NewConn creates a new mock net.Conn.

func NewFailingOnRead

func NewFailingOnRead(received *bytes.Buffer, responseReader io.Reader, readError error) *Conn

NewFailingOnRead returns a connection that fails on read using a static error.

func NewFailingOnWrite

func NewFailingOnWrite(received *bytes.Buffer, responseReader io.Reader, writeError error) *Conn

NewFailingOnWrite returns a connection that fails on write using a static error.

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Closed

func (c *Conn) Closed() bool

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) Read

func (c *Conn) Read(b []byte) (n int, err error)

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

func (*Conn) Write

func (c *Conn) Write(b []byte) (n int, err error)

type Dialer

type Dialer interface {
	// Like net.Dial
	Dial(network, addr string) (net.Conn, error)

	// Like net.DialTimeout
	DialTimeout(network, addr string, timeout time.Duration) (net.Conn, error)

	// Like net.DialContext
	DialContext(ctx context.Context, network, addr string) (net.Conn, error)

	// Gets the last dialed address
	LastDialed() string

	// Gets all received data
	Received() []byte

	// Returns true if all dialed connections are closed
	AllClosed() bool
}

Dialer is a test dialer that provides a net.Dial and net.DialTimeout equivalent backed by an in-memory data structure, and that provides access to the received data via the Received() method.

func AutoClose

func AutoClose(d Dialer) Dialer

AutoClose wraps a dialer to close the connection automatically after writing response.

func FailingDialer

func FailingDialer(dialError error) Dialer

FailingDialer constructs a new Dialer that fails to dial with the given error.

func SlowDialer

func SlowDialer(d Dialer, delay time.Duration) Dialer

SlowDialer wraps a dialer to add a delay when dialing it.

func SlowResponder

func SlowResponder(d Dialer, delay time.Duration) Dialer

SlowResponder wraps a dialer to add a delay when writing response to the dialed connection.

func SucceedingDialer

func SucceedingDialer(responseData []byte) Dialer

SucceedingDialer constructs a new Dialer that responds with the given canned responseData.

Jump to

Keyboard shortcuts

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