nettest

package
v1.32.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

func NewPipe

func NewPipe() *Pipe

NewPipe returns a Pipe.

func (*Pipe) Accept

func (p *Pipe) Accept(cancel <-chan struct{}) (net.Conn, error)

Accept returns a connection to the server for a client.

func (*Pipe) Connect

func (p *Pipe) Connect(cancel <-chan struct{}) (net.Conn, error)

Connect returns a connection to a client for the server.

type PipeListener

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

func NewListener(pipe *Pipe) *PipeListener

NewListener returns a net.Listener which uses the given Pipe to simulate a network connection.

func (*PipeListener) Accept

func (t *PipeListener) Accept() (net.Conn, error)

func (*PipeListener) Addr

func (t *PipeListener) Addr() net.Addr

func (*PipeListener) Close

func (t *PipeListener) Close() error

type RPCFactory

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

func NewRPCFactory(listener *PipeListener, dialOptions ...grpc.DialOption) *RPCFactory

NewRPCFactory creates a new RPCFactory backed by a PipeListener.

func (*RPCFactory) CreateHistoryGRPCConnection

func (f *RPCFactory) CreateHistoryGRPCConnection(rpcAddress string) grpc.ClientConnInterface

func (*RPCFactory) CreateLocalFrontendGRPCConnection

func (f *RPCFactory) CreateLocalFrontendGRPCConnection() grpc.ClientConnInterface

func (*RPCFactory) CreateLocalFrontendHTTPClient

func (f *RPCFactory) CreateLocalFrontendHTTPClient() (*common.FrontendHTTPClient, error)

func (*RPCFactory) CreateMatchingGRPCConnection

func (f *RPCFactory) CreateMatchingGRPCConnection(rpcAddress string) grpc.ClientConnInterface

func (*RPCFactory) CreateRemoteFrontendGRPCConnection

func (f *RPCFactory) CreateRemoteFrontendGRPCConnection(rpcAddress string) grpc.ClientConnInterface

func (*RPCFactory) GetFrontendGRPCServerOptions

func (f *RPCFactory) GetFrontendGRPCServerOptions() ([]grpc.ServerOption, error)

func (*RPCFactory) GetGRPCListener

func (f *RPCFactory) GetGRPCListener() net.Listener

func (*RPCFactory) GetInternodeGRPCServerOptions

func (f *RPCFactory) GetInternodeGRPCServerOptions() ([]grpc.ServerOption, error)

Jump to

Keyboard shortcuts

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