diff --git a/clientv3/integration/naming/resolver_test.go b/clientv3/integration/naming/resolver_test.go index 85951b568..bb6354d55 100644 --- a/clientv3/integration/naming/resolver_test.go +++ b/clientv3/integration/naming/resolver_test.go @@ -26,7 +26,7 @@ import ( "go.etcd.io/etcd/clientv3/naming/endpoints" "go.etcd.io/etcd/clientv3/naming/resolver" "go.etcd.io/etcd/integration" - grpctest "go.etcd.io/etcd/pkg/grpc_testing" + "go.etcd.io/etcd/pkg/grpc_testing" "go.etcd.io/etcd/pkg/testutil" ) @@ -35,14 +35,14 @@ import ( func TestEtcdGrpcResolver(t *testing.T) { defer testutil.AfterTest(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) } @@ -111,16 +111,3 @@ func TestEtcdGrpcResolver(t *testing.T) { break } } - -func newDummyStubServer(body []byte) *grpctest.StubServer { - return &grpctest.StubServer{ - UnaryCallF: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { - return &testpb.SimpleResponse{ - Payload: &testpb.Payload{ - Type: testpb.PayloadType_COMPRESSABLE, - Body: body, - }, - }, nil - }, - } -} diff --git a/etcdserver/api/v3rpc/codec.go b/etcdserver/api/v3rpc/codec.go index 17a2c87ae..d599ff63c 100644 --- a/etcdserver/api/v3rpc/codec.go +++ b/etcdserver/api/v3rpc/codec.go @@ -14,7 +14,7 @@ package v3rpc -import "github.com/gogo/protobuf/proto" +import "github.com/golang/protobuf/proto" type codec struct{} diff --git a/pkg/grpc_testing/stub_server.go b/pkg/grpc_testing/stub_server.go index b2892ef0d..ba7cb44c3 100644 --- a/pkg/grpc_testing/stub_server.go +++ b/pkg/grpc_testing/stub_server.go @@ -31,12 +31,7 @@ import ( // StubServer is a server that is easy to customize within individual test // cases. type StubServer struct { - // Guarantees we satisfy this interface; panics if unimplemented methods are called. - testpb.TestServiceServer - - 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 testpb.TestService_FullDuplexCallServer) error + testService testpb.TestServiceServer s *grpc.Server @@ -47,19 +42,8 @@ type StubServer struct { cleanups []func() // Lambdas executed in Stop(); populated by Start(). } -// EmptyCall is the handler for testpb.EmptyCall. -func (ss *StubServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) { - return ss.EmptyCallF(ctx, in) -} - -// UnaryCall is the handler for testpb.UnaryCall. -func (ss *StubServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { - return ss.UnaryCallF(ctx, in) -} - -// FullDuplexCall is the handler for testpb.FullDuplexCall. -func (ss *StubServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServer) error { - return ss.FullDuplexCallF(stream) +func New(testService testpb.TestServiceServer) *StubServer { + return &StubServer{testService: testService} } // Start starts the server and creates a client connected to it. @@ -79,7 +63,7 @@ func (ss *StubServer) Start(sopts []grpc.ServerOption, dopts ...grpc.DialOption) ss.cleanups = append(ss.cleanups, func() { lis.Close() }) s := grpc.NewServer(sopts...) - testpb.RegisterTestServiceServer(s, ss) + testpb.RegisterTestServiceServer(s, ss.testService) go s.Serve(lis) ss.cleanups = append(ss.cleanups, s.Stop) ss.s = s @@ -98,3 +82,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}) +}