Documentation ¶
Overview ¶
Package stubserver is a stubbable implementation of google.golang.org/grpc/interop/grpc_testing for testing purposes.
Index ¶
- type StubServer
- func (ss *StubServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error)
- func (ss *StubServer) FullDuplexCall(stream testgrpc.TestService_FullDuplexCallServer) error
- func (ss *StubServer) NewServiceConfig(sc string)
- func (ss *StubServer) Start(sopts []grpc.ServerOption, dopts ...grpc.DialOption) error
- func (ss *StubServer) StartClient(dopts ...grpc.DialOption) error
- func (ss *StubServer) StartServer(sopts ...grpc.ServerOption) error
- func (ss *StubServer) Stop()
- func (ss *StubServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StubServer ¶
type StubServer struct { // Guarantees we satisfy this interface; panics if unimplemented methods are called. testgrpc.TestServiceServer // Customizable implementations of server handlers. EmptyCallF func(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) UnaryCallF func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) FullDuplexCallF func(stream testgrpc.TestService_FullDuplexCallServer) error // A client connected to this service the test may use. Created in Start(). Client testgrpc.TestServiceClient CC *grpc.ClientConn S *grpc.Server // Parameters for Listen and Dial. Defaults will be used if these are empty // before Start. Network string Address string Target string // Set automatically if Target == "" R *manual.Resolver // contains filtered or unexported fields }
StubServer is a server that is easy to customize within individual test cases.
func StartTestService ¶ added in v1.55.0
func StartTestService(t *testing.T, server *StubServer) *StubServer
StartTestService spins up a stub server exposing the TestService on a local port. If the passed in server is nil, a stub server that implements only the EmptyCall and UnaryCall RPCs is started.
func (*StubServer) FullDuplexCall ¶
func (ss *StubServer) FullDuplexCall(stream testgrpc.TestService_FullDuplexCallServer) error
FullDuplexCall is the handler for testpb.FullDuplexCall
func (*StubServer) NewServiceConfig ¶
func (ss *StubServer) NewServiceConfig(sc string)
NewServiceConfig applies sc to ss.Client using the resolver (if present).
func (*StubServer) Start ¶
func (ss *StubServer) Start(sopts []grpc.ServerOption, dopts ...grpc.DialOption) error
Start starts the server and creates a client connected to it.
func (*StubServer) StartClient ¶ added in v1.44.0
func (ss *StubServer) StartClient(dopts ...grpc.DialOption) error
StartClient creates a client connected to this service that the test may use. The newly created client will be available in the Client field of StubServer.
func (*StubServer) StartServer ¶ added in v1.44.0
func (ss *StubServer) StartServer(sopts ...grpc.ServerOption) error
StartServer only starts the server. It does not create a client to it.
func (*StubServer) Stop ¶
func (ss *StubServer) Stop()
Stop stops ss and cleans up all resources it consumed.
func (*StubServer) UnaryCall ¶
func (ss *StubServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error)
UnaryCall is the handler for testpb.UnaryCall