mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
backport https://github.com/etcd-io/etcd/pull/12709 and https://github.com/etcd-io/etcd/pull/12801 to resolve gogo unmarshal errors
Signed-off-by: Chao Chen <chaochn@amazon.com>
This commit is contained in:
parent
1665b8ea4d
commit
f549da33de
@ -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
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
package v3rpc
|
||||
|
||||
import "github.com/gogo/protobuf/proto"
|
||||
import "github.com/golang/protobuf/proto"
|
||||
|
||||
type codec struct{}
|
||||
|
||||
|
@ -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})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user