Documentation
¶
Overview ¶
Package grpctest provides test utilities for projects that work with gRPC.
Index ¶
- type MockServer
- func (ms *MockServer) ConnectTestClient(ctx context.Context) (*grpc.ClientConn, testpb.TestServiceClient, error)
- func (ms *MockServer) EmptyCall(ctx context.Context, req *testpb.Empty) (*testpb.Empty, error)
- func (ms *MockServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServer) error
- func (ms *MockServer) HalfDuplexCall(stream testpb.TestService_HalfDuplexCallServer) error
- func (ms *MockServer) SetEmptyCallHandler(handler func(context.Context, *testpb.Empty) (*testpb.Empty, error))
- func (ms *MockServer) SetFullDuplexCallHandler(handler func(testpb.TestService_FullDuplexCallServer) error)
- func (ms *MockServer) SetHalfDuplexCallHandler(handler func(testpb.TestService_HalfDuplexCallServer) error)
- func (ms *MockServer) SetStreamingInputCallHandler(handler func(testpb.TestService_StreamingInputCallServer) error)
- func (ms *MockServer) SetStreamingOutputCallHandler(handler func(*testpb.StreamingOutputCallRequest, ...) error)
- func (ms *MockServer) SetUnaryCallHandler(...)
- func (ms *MockServer) Start(ctx context.Context) error
- func (ms *MockServer) Stop()
- func (ms *MockServer) StreamingInputCall(stream testpb.TestService_StreamingInputCallServer) error
- func (ms *MockServer) StreamingOutputCall(req *testpb.StreamingOutputCallRequest, ...) error
- func (ms *MockServer) UnaryCall(ctx context.Context, req *testpb.SimpleRequest) (*testpb.SimpleResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockServer ¶
type MockServer struct { testpb.UnimplementedTestServiceServer // contains filtered or unexported fields }
MockServer is a mock gRPC server that exposes the "grpc.testing" service.
func NewMockServer ¶
func NewMockServer(serverOptions []grpc.ServerOption, dialOptions []grpc.DialOption) *MockServer
NewMockServer returns a new MockServer.
func (*MockServer) ConnectTestClient ¶
func (ms *MockServer) ConnectTestClient(ctx context.Context) (*grpc.ClientConn, testpb.TestServiceClient, error)
ConnectTestClient connects to the mock server and returns a test client. The caller is responsible for closing the ClientConn when done.
func (*MockServer) EmptyCall ¶
EmptyCall calls the handler set with SetEmptyCallHandler. If that handler is nil, it delegates the call to the UnimplementedTestServiceServer.
func (*MockServer) FullDuplexCall ¶
func (ms *MockServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServer) error
FullDuplexCall calls the handler set with SetFullDuplexCallHandler. If that handler is nil, it delegates the call to the UnimplementedTestServiceServer.
func (*MockServer) HalfDuplexCall ¶
func (ms *MockServer) HalfDuplexCall(stream testpb.TestService_HalfDuplexCallServer) error
HalfDuplexCall calls the handler set with SetHalfDuplexCallHandler. If that handler is nil, it delegates the call to the UnimplementedTestServiceServer.
func (*MockServer) SetEmptyCallHandler ¶
func (ms *MockServer) SetEmptyCallHandler(handler func(context.Context, *testpb.Empty) (*testpb.Empty, error))
SetEmptyCallHandler sets the handler for the EmptyCall RPC.
func (*MockServer) SetFullDuplexCallHandler ¶
func (ms *MockServer) SetFullDuplexCallHandler(handler func(testpb.TestService_FullDuplexCallServer) error)
SetFullDuplexCallHandler sets the handler for the FullDuplexCall RPC.
func (*MockServer) SetHalfDuplexCallHandler ¶
func (ms *MockServer) SetHalfDuplexCallHandler(handler func(testpb.TestService_HalfDuplexCallServer) error)
SetHalfDuplexCallHandler sets the handler for the HalfDuplexCall RPC.
func (*MockServer) SetStreamingInputCallHandler ¶
func (ms *MockServer) SetStreamingInputCallHandler(handler func(testpb.TestService_StreamingInputCallServer) error)
SetStreamingInputCallHandler sets the handler for the StreamingInputCall RPC.
func (*MockServer) SetStreamingOutputCallHandler ¶
func (ms *MockServer) SetStreamingOutputCallHandler(handler func(*testpb.StreamingOutputCallRequest, testpb.TestService_StreamingOutputCallServer) error)
SetStreamingOutputCallHandler sets the handler for the StreamingOutputCall RPC.
func (*MockServer) SetUnaryCallHandler ¶
func (ms *MockServer) SetUnaryCallHandler(handler func(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error))
SetUnaryCallHandler sets the handler for the UnaryCall RPC.
func (*MockServer) Start ¶
func (ms *MockServer) Start(ctx context.Context) error
Start starts the mock server. The caller is responsible for stopping the server when done.
func (*MockServer) StreamingInputCall ¶
func (ms *MockServer) StreamingInputCall(stream testpb.TestService_StreamingInputCallServer) error
StreamingInputCall calls the handler set with SetStreamingInputCallHandler. If that handler is nil, it delegates the call to the UnimplementedTestServiceServer.
func (*MockServer) StreamingOutputCall ¶
func (ms *MockServer) StreamingOutputCall(req *testpb.StreamingOutputCallRequest, stream testpb.TestService_StreamingOutputCallServer) error
StreamingOutputCall calls the handler set with SetStreamingOutputCallHandler. If that handler is nil, it delegates the call to the UnimplementedTestServiceServer.
func (*MockServer) UnaryCall ¶
func (ms *MockServer) UnaryCall(ctx context.Context, req *testpb.SimpleRequest) (*testpb.SimpleResponse, error)
UnaryCall calls the handler set with SetUnaryCallHandler. If that handler is nil, it delegates the call to the UnimplementedTestServiceServer.