From d0962f10ae381f3dfbbfca481014930e2c6b59a5 Mon Sep 17 00:00:00 2001 From: Piotr Tabor Date: Wed, 24 Mar 2021 22:06:06 +0100 Subject: [PATCH] Adopt grpc_testing to grpc-1.36. --- pkg/grpc_testing/stub_server.go | 27 ++++++++++++++++--- .../clientv3/naming/resolver_test.go | 20 +++----------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/pkg/grpc_testing/stub_server.go b/pkg/grpc_testing/stub_server.go index c5d01bd36..e7e8c49d4 100644 --- a/pkg/grpc_testing/stub_server.go +++ b/pkg/grpc_testing/stub_server.go @@ -1,6 +1,7 @@ package grpc_testing import ( + "context" "fmt" "net" @@ -16,7 +17,7 @@ import ( // StubServer is a server that is easy to customize within individual test // cases. type StubServer struct { - testService *testpb.TestServiceService + testService testpb.TestServiceServer // Network and Address are parameters for Listen. Defaults will be used if these are empty before Start. Network string @@ -27,7 +28,7 @@ type StubServer struct { cleanups []func() // Lambdas executed in Stop(); populated by Start(). } -func New(testService *testpb.TestServiceService) *StubServer { +func New(testService testpb.TestServiceServer) *StubServer { return &StubServer{testService: testService} } @@ -48,7 +49,7 @@ func (ss *StubServer) Start(sopts []grpc.ServerOption, dopts ...grpc.DialOption) ss.cleanups = append(ss.cleanups, func() { lis.Close() }) s := grpc.NewServer(sopts...) - testpb.RegisterTestServiceService(s, ss.testService) + testpb.RegisterTestServiceServer(s, ss.testService) go s.Serve(lis) ss.cleanups = append(ss.cleanups, s.Stop) ss.s = s @@ -67,3 +68,23 @@ func (ss *StubServer) Stop() { func (ss *StubServer) Addr() string { return ss.Address } + +type dummyStubServer struct { + testpb.UnimplementedTestServiceServer + body []byte +} + +func (d dummyStubServer) UnaryCall(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { + return &testpb.SimpleResponse{ + Payload: &testpb.Payload{ + Type: testpb.PayloadType_COMPRESSABLE, + Body: d.body, + }, + }, nil +} + +// NewDummyStubServer creates a simple test server that serves Unary calls with +// responses with the given payload. +func NewDummyStubServer(body []byte) *StubServer { + return New(dummyStubServer{body: body}) +} diff --git a/tests/integration/clientv3/naming/resolver_test.go b/tests/integration/clientv3/naming/resolver_test.go index b7cc91a18..980580c16 100644 --- a/tests/integration/clientv3/naming/resolver_test.go +++ b/tests/integration/clientv3/naming/resolver_test.go @@ -22,7 +22,7 @@ import ( "go.etcd.io/etcd/client/v3/naming/endpoints" "go.etcd.io/etcd/client/v3/naming/resolver" - grpctest "go.etcd.io/etcd/pkg/v3/grpc_testing" + "go.etcd.io/etcd/pkg/v3/grpc_testing" "go.etcd.io/etcd/tests/v3/integration" "google.golang.org/grpc" @@ -35,14 +35,14 @@ func TestEtcdGrpcResolver(t *testing.T) { integration.BeforeTest(t) s1PayloadBody := []byte{'1'} - s1 := newDummyStubServer(s1PayloadBody) + s1 := grpc_testing.NewDummyStubServer(s1PayloadBody) if err := s1.Start(nil); err != nil { t.Fatal("failed to start dummy grpc server (s1)", err) } defer s1.Stop() s2PayloadBody := []byte{'2'} - s2 := newDummyStubServer(s2PayloadBody) + s2 := grpc_testing.NewDummyStubServer(s2PayloadBody) if err := s2.Start(nil); err != nil { t.Fatal("failed to start dummy grpc server (s2)", err) } @@ -112,17 +112,3 @@ func TestEtcdGrpcResolver(t *testing.T) { break } } - -func newDummyStubServer(body []byte) *grpctest.StubServer { - testService := &testpb.TestServiceService{ - UnaryCall: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { - return &testpb.SimpleResponse{ - Payload: &testpb.Payload{ - Type: testpb.PayloadType_COMPRESSABLE, - Body: body, - }, - }, nil - }, - } - return grpctest.New(testService) -}