package nettest

Import Path
	internal/nettest (on go.dev)

Dependency Relation
	imports 12 packages, and imported by one package


Package-Level Type Names (total 4)
/* sort by: | */
Conn is an in-memory test implementation of net.Conn. CanRead reports whether Read can proceed without blocking. Close closes the connection. CloseRead shuts down the reading side of the connection. CloseWrite shuts down the writing side of the connection. IsClosed reports whether the connection has been closed. A connection is closed if [CloseRead] and [CloseWrite] are both called, or if [Close] is called. To identify when the other side of the Conn has been closed, use Conn.Peer().IsClosed(). LocalAddr returns the (fake) local network address. Peer returns the other end of the connection. Read reads data from the connection. LocalAddr returns the (fake) remote network address. SetCloseError sets the error returned by Close. Close still closes the connection. A nil error restores the usual behavior. SetDeadline sets the read and write deadlines for the connection. SetLocalAddr sets the local address. To set the remote address, set the local address of Conn's peer. SetReadBufferSize sets the connection's read buffer. Writes to the other end of the connection will block so long as the buffer is full. Setting the size to 0 blocks all writes until the size is increased. SetReadDeadline sets the read deadline for the connection. SetReadError causes any currently blocked and future Read calls to return a net.OpError wrapping err. It does not affect the other half of the connection. Reads will return any buffered data before returning the error, including data written after the error is set and io.EOF after the other end is closed. A nil error restores the usual behavior. SetWriteDeadline sets the write deadline for the connection. SetWriteError causes any currently blocked and future Write calls to return a net.OpError wrapping err. It does not affect the other half of the connection. Writes will not write data to the connection buffer while an error is set. A nil error restores the usual behavior. Write writes data to the connection. *Conn : internal/bisect.Writer *Conn : github.com/miekg/dns.Writer *Conn : github.com/pion/datachannel.ReadDeadliner *Conn : github.com/pion/datachannel.WriteDeadliner *Conn : github.com/pion/stun.Connection *Conn : github.com/pion/stun/v3.Connection *Conn : github.com/prometheus/common/expfmt.Closer *Conn : io.Closer *Conn : io.ReadCloser *Conn : io.Reader *Conn : io.ReadWriteCloser *Conn : io.ReadWriter *Conn : io.WriteCloser *Conn : io.Writer *Conn : net.Conn func NewConnPair() (*Conn, *Conn) func NewConnPair() (*Conn, *Conn) func (*Conn).Peer() *Conn func (*Listener).NewConn() *Conn func (*Listener).NewConnConfig(f func(*Conn)) *Conn
Listener is an in-memory test implementation of net.Listener. Accept waits for and returns the next connection to the listener. The connections returned by Accept are always [*Conn]s. Addr returns the listener's network address. The address is always a *net.TCPAddr. Close closes the listener. Any blocked Accept operations will be unblocked and return errors. NewConn returns a new connection to the listener. Accept will return the other side of the conn. NewConnConfig returns a new connection to the listener. The function f is called with the new client connection. After f returns, Accept will return the other side of the connection. For example, to create a connection from a specific IP address: conn := li.NewConnConfig(func(conn *nettest.Conn) { conn.SetLocalAddr(net.TCPAddrFromAddrPort(netip.MustParseAddrPort("10.0.0.1:1234"))) }) SetAcceptError causes any currently blocked and future Accept calls to return a net.OpError wrapping err. Accept will return any available connections before returning the error, including connections created after the error is set. A nil error restores the usual behavior. SetAddr sets the listener's network address. SetCloseError sets the error returned by Close. Close still closes the listener. A nil error restores the usual behavior. *Listener : github.com/prometheus/common/expfmt.Closer *Listener : io.Closer *Listener : net.Listener func NewListener() *Listener
CanRead reports whether [ReadFrom] can return at least one byte or an error. If [ReadFrom] would block, CanRead returns false. Close closes the connection. IsClosed reports whether the connection has been closed. LocalAddr returns the (fake) local network address. ReadFrom reads a packet from the connection, copying the payload into b. SetCloseError sets the error returned by Close. Close still closes the connection. A nil error restores the usual behavior. SetReadDeadline sets the read deadline for the connection. PacketConns have no write deadline. SetReadDeadline sets the read deadline for the connection. SetReadError causes any currently blocked and future ReadFrom calls to return a net.OpError wrapping err. It does not affect the other half of the connection. Reads will return any buffered data before returning the error, including data written after the error is set. A nil error restores the usual behavior. SetWriteDeadline has no effect. Writes to PacketConns never block. SetWriteError causes any currently blocked and future WriteTo calls to return a net.OpError wrapping err. It does not affect the other half of the connection. Writes will not write data while an error is set. A nil error restores the usual behavior. WriteTo writes a packet with payload b to addr. addr must be a [*net.UDPAddr]. WriteTo appends the packet to the recipient's receive buffer. If no recipient is listening on addr or if the recipient's receive buffer is full, the packet is silently discarded. *PacketConn : github.com/pion/datachannel.ReadDeadliner *PacketConn : github.com/pion/datachannel.WriteDeadliner *PacketConn : github.com/prometheus/common/expfmt.Closer *PacketConn : io.Closer *PacketConn : net.PacketConn func (*PacketNet).NewConn(a net.Addr) (*PacketConn, error)
A PacketNet is a group of communicating [PacketConn]s. NewConn returns a new [PacketConn] listening on the given address. It returns an error if there is an existing listener on this address. func NewPacketNet() *PacketNet
Package-Level Functions (total 3)
NewConnPair returns a pair of connected Conns.
NewListener returns a new Listener.
NewPacketNet returns a new PacketNet.