Documentation ¶
Index ¶
Constants ¶
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 ¶
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.