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 ¶
var ErrAddressInUse = errors.New("Address is already in use by another listener")
ErrAddressInUse is returned if the address already is in use
var ErrConnRefused = errors.New("Connection refused, no listener for the given address")
ErrConnRefused is returned if the connection is refused
var ErrListenerClosed = errors.New("Listener have been closed!")
ErrListenerClosed is returned when a listener have been closed
Functions ¶
Types ¶
type MockAddr ¶
type MockAddr struct {
// contains filtered or unexported fields
}
MockAddr is an net.Addr implementation for MockListener
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.