Documentation
¶
Overview ¶
Package gsrv creates a test gRPC server that is useful when mocking a gRPC service.
A complete example of mocking a gRPC service that leverges this package is available at https://github.com/weathersource/go-gsrv/tree/master/examples/foo
This package is based on Google's testutil.Server. Original code is found at https://github.com/GoogleCloudPlatform/google-cloud-go/blob/master/internal/testutil/server.go
Index ¶
Constants ¶
const ( // Initialized Server status means the server has been created, but not started. Initialized status = iota // Running Server status means the server has been started. Running // Closed Server status means the server has been closed Closed // ClosedWithError Server status means the server was closed because of an error. ClosedWithError )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct { Addr string Port int Gsrv *grpc.Server // contains filtered or unexported fields }
Server is an in-process gRPC server, listening on a system-chosen port on the local loopback interface. Servers are for testing only and are not intended to be used in production code.
To create a server, make a new Server, register your handlers, then call Start:
srv, err := NewServer() ... mypb.RegisterMyServiceServer(srv.Gsrv, &myHandler) .... srv.Start()
Clients should connect to the server with no security:
conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure()) ...
func NewServer ¶
func NewServer(opts ...grpc.ServerOption) (*Server, error)
NewServer creates a new Server. The server will be listening for gRPC connections at the address named by the Addr field, without TLS.
func NewServerWithPort ¶
func NewServerWithPort(port int, opts ...grpc.ServerOption) (*Server, error)
NewServerWithPort creates a new Server at a specific port. The server will be listening for gRPC connections at the address named by the Addr field, without TLS.
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
foo
command
|
|
foo/mockfoo
Package mockfoo mocks a server for the Foo service.
|
Package mockfoo mocks a server for the Foo service. |