11package grpc_testing
22
33import (
4+ "context"
45 "fmt"
56 "net"
67
@@ -16,7 +17,7 @@ import (
1617// StubServer is a server that is easy to customize within individual test
1718// cases.
1819type StubServer struct {
19- testService * testpb.TestServiceService
20+ testService testpb.TestServiceServer
2021
2122 // Network and Address are parameters for Listen. Defaults will be used if these are empty before Start.
2223 Network string
@@ -27,7 +28,7 @@ type StubServer struct {
2728 cleanups []func () // Lambdas executed in Stop(); populated by Start().
2829}
2930
30- func New (testService * testpb.TestServiceService ) * StubServer {
31+ func New (testService testpb.TestServiceServer ) * StubServer {
3132 return & StubServer {testService : testService }
3233}
3334
@@ -48,7 +49,7 @@ func (ss *StubServer) Start(sopts []grpc.ServerOption, dopts ...grpc.DialOption)
4849 ss .cleanups = append (ss .cleanups , func () { lis .Close () })
4950
5051 s := grpc .NewServer (sopts ... )
51- testpb .RegisterTestServiceService (s , ss .testService )
52+ testpb .RegisterTestServiceServer (s , ss .testService )
5253 go s .Serve (lis )
5354 ss .cleanups = append (ss .cleanups , s .Stop )
5455 ss .s = s
@@ -67,3 +68,23 @@ func (ss *StubServer) Stop() {
6768func (ss * StubServer ) Addr () string {
6869 return ss .Address
6970}
71+
72+ type dummyStubServer struct {
73+ testpb.UnimplementedTestServiceServer
74+ body []byte
75+ }
76+
77+ func (d dummyStubServer ) UnaryCall (context.Context , * testpb.SimpleRequest ) (* testpb.SimpleResponse , error ) {
78+ return & testpb.SimpleResponse {
79+ Payload : & testpb.Payload {
80+ Type : testpb .PayloadType_COMPRESSABLE ,
81+ Body : d .body ,
82+ },
83+ }, nil
84+ }
85+
86+ // NewDummyStubServer creates a simple test server that serves Unary calls with
87+ // responses with the given payload.
88+ func NewDummyStubServer (body []byte ) * StubServer {
89+ return New (dummyStubServer {body : body })
90+ }
0 commit comments