mocknet

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package mocknet implements a net.Listener interface that can reached with mocknet.Dial() and establishes connections using net.Pipe()

This is useful for testing things that needs net.Listener and net.Conn instances without creating a TCP listener on localhost.

Index

Constants

This section is empty.

Variables

View Source
var ErrAddressInUse = errors.New("address is already in use by another listener")

ErrAddressInUse is returned if the address already is in use

View Source
var ErrConnRefused = errors.New("connection refused, no listener for the given address")

ErrConnRefused is returned if the connection is refused

View Source
var ErrListenerClosed = errors.New("listener has been closed")

ErrListenerClosed is returned when a listener has been closed

Functions

func Dial

func Dial(addr string) (net.Conn, error)

Dial creates a new connection to mock network identified by addr

Types

type MockAddr

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

MockAddr is an net.Addr implementation for MockListener

func (*MockAddr) Network

func (a *MockAddr) Network() string

Network returns a network type identifier, like net.Addr.Network()

func (*MockAddr) String

func (a *MockAddr) String() string

String returns address on string form, like net.Addr.String()

type MockListener

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

MockListener is implementation of net.Listener that allowd for establishment of net.Pipe() connections pairs

func Listen

func Listen(addr string) (*MockListener, error)

Listen for new mock connections to addr

func (*MockListener) Accept

func (l *MockListener) Accept() (net.Conn, error)

Accept new connections, see net.Listener.Accept()

func (*MockListener) Addr

func (l *MockListener) Addr() net.Addr

Addr returns the listener's network address.

func (*MockListener) Close

func (l *MockListener) Close() error

Close closes the listener.

Jump to

Keyboard shortcuts

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