testing

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadProtoset

func LoadProtoset(path string) (protoreflect.FileDescriptor, error)

LoadProtoset loads the compiled protoset file at the given path. It returns the last file descriptor in the set. When generating a protoset for a single file, that file is always last (and its dependencies before it).

func StartServer

func StartServer(tb gotesting.TB, svr *grpc.Server, opts ...ServerOption) *grpc.ClientConn

StartServer serves the given server using an in-memory listener and returns a client connection to it. The connection is closed and the server stopped when the test completes.

Types

type ServerOption

type ServerOption func(*serverConfig)

ServerOption customizes the behavior of StartServer.

func WithDialOptions

func WithDialOptions(opts ...grpc.DialOption) ServerOption

WithDialOptions returns an option that adds the given options to those used to create the client connection.

func WithListenerWrapper

func WithListenerWrapper(wrap func(net.Listener) net.Listener) ServerOption

WithListenerWrapper returns an option that wraps the server's listener, such as to observe or tamper with accepted connections.

type TestService

type TestService struct {
	grpc.UnimplementedTestServiceServer
}

TestService is a very simple test service that just echos back request payloads

func (TestService) EmptyCall

func (TestService) EmptyCall(_ context.Context, _ *emptypb.Empty) (*emptypb.Empty, error)

EmptyCall satisfies the grpc.TestServiceServer interface. It always succeeds.

func (TestService) FullDuplexCall

FullDuplexCall satisfies the grpc.TestServiceServer interface. It only fails if the client cancels or disconnects (thus causing ss.Send to return an error). For each request message it receives, it sends back a response message with the same payload.

func (TestService) HalfDuplexCall

HalfDuplexCall satisfies the grpc.TestServiceServer interface. It only fails if the client cancels or disconnects (thus causing ss.Send to return an error). For each request message it receives, it sends back a response message with the same payload. But since it is half-duplex, all of the request payloads are buffered and responses will only be sent after the request stream is half-closed.

func (TestService) StreamingInputCall

StreamingInputCall satisfies the grpc.TestServiceServer interface. It always succeeds, sending back the total observed size of all request payloads.

func (TestService) StreamingOutputCall

StreamingOutputCall satisfies the grpc.TestServiceServer interface. It only fails if the client cancels or disconnects (thus causing ss.Send to return an error). It echoes a number of responses equal to the request's number of response parameters. The requested parameter details, however, ignored. The response payload is always an echo of the request payload.

func (TestService) UnaryCall

UnaryCall satisfies the grpc.TestServiceServer interface. It always succeeds, echoing back the payload present in the request.

Jump to

Keyboard shortcuts

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