bufconn

package
v0.12.8 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Endpoint = "passthrough://bufnet"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DialOption

type DialOption func(*Listener)

DialOption -- optional arguments for constructing a Listener.

func WithBuffer

func WithBuffer(sock *bufconn.Listener) DialOption

Allows you to pass an already instantiated grpc bufconn.Listener into the Listener.

func WithBufferSize

func WithBufferSize(size int) DialOption

The default buffer size is 1MiB -- if ou need a larger buffer to send larger messages then specify this dial option with a larger size.

func WithTarget

func WithTarget(target string) DialOption

WithTarget allows the user to change the "endpoint" of the connection from "bufnet" to some other endpoint. This is useful for tests that include mTLS to ensure that TLS certificate handling is correct.

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

Listener handles gRPC connections using an in-memory buffer that is useful for testing to prevent actual TCP network requests. Using a bufconn connection provides the most realistic gRPC server for tests that include serialization and deserialization of protocol buffers and an actual wire transfer between client and server. We prefer to use the bufconn over simply making method calls to the handlers.

func New

func New(opts ...DialOption) *Listener

New creates a bufconn listener ready to attach servers and clients to. To provide a different target name (e.g. for mTLS buffers) use the WithTarget() dial option. You can also specify a different buffer size using WithBufferSize() or pass in an already instantiated bufconn.Listener using WithBuffer().

func (*Listener) Close

func (l *Listener) Close() error

Close the bufconn listener and prevent either clients or servers from communicating.

func (*Listener) Connect

func (l *Listener) Connect(opts ...grpc.DialOption) (cc *grpc.ClientConn, err error)

Connect returns the client side of the bufconn connection.

func (*Listener) Dialer

func (l *Listener) Dialer(context.Context, string) (net.Conn, error)

Dialer implements the ContextDialer interface for use with grpc.DialOptions

func (*Listener) Sock

func (l *Listener) Sock() net.Listener

Sock returns the server side of the bufconn connection.

Jump to

Keyboard shortcuts

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