Skip to content

Commit d0962f1

Browse files
committed
Adopt grpc_testing to grpc-1.36.
1 parent a606766 commit d0962f1

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

pkg/grpc_testing/stub_server.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package grpc_testing
22

33
import (
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.
1819
type 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() {
6768
func (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+
}

tests/integration/clientv3/naming/resolver_test.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"go.etcd.io/etcd/client/v3/naming/endpoints"
2424
"go.etcd.io/etcd/client/v3/naming/resolver"
25-
grpctest "go.etcd.io/etcd/pkg/v3/grpc_testing"
25+
"go.etcd.io/etcd/pkg/v3/grpc_testing"
2626
"go.etcd.io/etcd/tests/v3/integration"
2727

2828
"google.golang.org/grpc"
@@ -35,14 +35,14 @@ func TestEtcdGrpcResolver(t *testing.T) {
3535
integration.BeforeTest(t)
3636

3737
s1PayloadBody := []byte{'1'}
38-
s1 := newDummyStubServer(s1PayloadBody)
38+
s1 := grpc_testing.NewDummyStubServer(s1PayloadBody)
3939
if err := s1.Start(nil); err != nil {
4040
t.Fatal("failed to start dummy grpc server (s1)", err)
4141
}
4242
defer s1.Stop()
4343

4444
s2PayloadBody := []byte{'2'}
45-
s2 := newDummyStubServer(s2PayloadBody)
45+
s2 := grpc_testing.NewDummyStubServer(s2PayloadBody)
4646
if err := s2.Start(nil); err != nil {
4747
t.Fatal("failed to start dummy grpc server (s2)", err)
4848
}
@@ -112,17 +112,3 @@ func TestEtcdGrpcResolver(t *testing.T) {
112112
break
113113
}
114114
}
115-
116-
func newDummyStubServer(body []byte) *grpctest.StubServer {
117-
testService := &testpb.TestServiceService{
118-
UnaryCall: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
119-
return &testpb.SimpleResponse{
120-
Payload: &testpb.Payload{
121-
Type: testpb.PayloadType_COMPRESSABLE,
122-
Body: body,
123-
},
124-
}, nil
125-
},
126-
}
127-
return grpctest.New(testService)
128-
}

0 commit comments

Comments
 (0)