Documentation ¶
Overview ¶
Package nettest provides an in-memory socket, Pipe. It can be used in place of net.Dial and net.Listen for faster and more hermetic tests.
Index ¶
- Variables
- type Pipe
- type PipeListener
- type RPCFactory
- func (f *RPCFactory) CreateInternodeGRPCConnection(rpcAddress string) *grpc.ClientConn
- func (f *RPCFactory) CreateLocalFrontendGRPCConnection() *grpc.ClientConn
- func (f *RPCFactory) CreateRemoteFrontendGRPCConnection(rpcAddress string) *grpc.ClientConn
- func (f *RPCFactory) GetFrontendGRPCServerOptions() ([]grpc.ServerOption, error)
- func (f *RPCFactory) GetGRPCListener() net.Listener
- func (f *RPCFactory) GetInternodeGRPCServerOptions() ([]grpc.ServerOption, error)
- func (f *RPCFactory) SetContextFactory(factory func() context.Context)
Constants ¶
This section is empty.
Variables ¶
var ErrCanceled = errors.New("pipe operation canceled by client")
ErrCanceled indicates that an operation was canceled by the client (e.g. via ctx.Done()).
Functions ¶
This section is empty.
Types ¶
type Pipe ¶
type Pipe struct {
// contains filtered or unexported fields
}
Pipe is an in-memory socket. It provides similar functionality to net.Listen and net.Dial via the Pipe.Accept and Pipe.Connect methods, respectively. It is useful for faster and more deterministic testing of netcode.
type PipeListener ¶ added in v1.22.0
type PipeListener struct { *Pipe // contains filtered or unexported fields }
PipeListener is a net.Listener which uses a Pipe to simulate a network connection.
func NewListener ¶ added in v1.22.0
func NewListener(pipe *Pipe) *PipeListener
NewListener returns a net.Listener which uses the given Pipe to simulate a network connection.
func (*PipeListener) Addr ¶ added in v1.22.0
func (t *PipeListener) Addr() net.Addr
func (*PipeListener) Close ¶ added in v1.22.0
func (t *PipeListener) Close() error
type RPCFactory ¶ added in v1.23.0
type RPCFactory struct {
// contains filtered or unexported fields
}
RPCFactory is a common.RPCFactory implementation that uses a PipeListener to create connections. It is useful for testing gRPC servers.
func NewRPCFactory ¶ added in v1.23.0
func NewRPCFactory(listener *PipeListener, dialOptions ...grpc.DialOption) *RPCFactory
NewRPCFactory creates a new RPCFactory backed by a PipeListener.
func (*RPCFactory) CreateInternodeGRPCConnection ¶ added in v1.23.0
func (f *RPCFactory) CreateInternodeGRPCConnection(rpcAddress string) *grpc.ClientConn
func (*RPCFactory) CreateLocalFrontendGRPCConnection ¶ added in v1.23.0
func (f *RPCFactory) CreateLocalFrontendGRPCConnection() *grpc.ClientConn
func (*RPCFactory) CreateRemoteFrontendGRPCConnection ¶ added in v1.23.0
func (f *RPCFactory) CreateRemoteFrontendGRPCConnection(rpcAddress string) *grpc.ClientConn
func (*RPCFactory) GetFrontendGRPCServerOptions ¶ added in v1.23.0
func (f *RPCFactory) GetFrontendGRPCServerOptions() ([]grpc.ServerOption, error)
func (*RPCFactory) GetGRPCListener ¶ added in v1.23.0
func (f *RPCFactory) GetGRPCListener() net.Listener
func (*RPCFactory) GetInternodeGRPCServerOptions ¶ added in v1.23.0
func (f *RPCFactory) GetInternodeGRPCServerOptions() ([]grpc.ServerOption, error)
func (*RPCFactory) SetContextFactory ¶ added in v1.23.0
func (f *RPCFactory) SetContextFactory(factory func() context.Context)
SetContextFactory sets the context factory used to create contexts for dialing connections. The default returns a background context on each call.