mocknet

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2017 License: MPL-2.0 Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 have been closed!")

ErrListenerClosed is returned when a listener have 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