Skip to content

Commit f3c0155

Browse files
authored
Merge pull request #16997 from chaochn47/release-3.4-upgrade-grpc-1.52.0
Release 3.4 upgrade grpc 1.52.0
2 parents 6e6b615 + f549da3 commit f3c0155

8 files changed

Lines changed: 98 additions & 97 deletions

File tree

clientv3/integration/naming/resolver_test.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"go.etcd.io/etcd/clientv3/naming/endpoints"
2727
"go.etcd.io/etcd/clientv3/naming/resolver"
2828
"go.etcd.io/etcd/integration"
29-
grpctest "go.etcd.io/etcd/pkg/grpc_testing"
29+
"go.etcd.io/etcd/pkg/grpc_testing"
3030
"go.etcd.io/etcd/pkg/testutil"
3131
)
3232

@@ -35,14 +35,14 @@ import (
3535
func TestEtcdGrpcResolver(t *testing.T) {
3636
defer testutil.AfterTest(t)
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
}
@@ -111,16 +111,3 @@ func TestEtcdGrpcResolver(t *testing.T) {
111111
break
112112
}
113113
}
114-
115-
func newDummyStubServer(body []byte) *grpctest.StubServer {
116-
return &grpctest.StubServer{
117-
UnaryCallF: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
118-
return &testpb.SimpleResponse{
119-
Payload: &testpb.Payload{
120-
Type: testpb.PayloadType_COMPRESSABLE,
121-
Body: body,
122-
},
123-
}, nil
124-
},
125-
}
126-
}

clientv3/internal/endpoint/endpoint.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ func extractHostFromHostPort(ep string) string {
4141
return host
4242
}
4343

44-
func extractHostFromPath(pathStr string) string {
45-
return extractHostFromHostPort(path.Base(pathStr))
46-
}
47-
4844
// mustSplit2 returns the values from strings.SplitN(s, sep, 2).
4945
// If sep is not found, it returns ("", "", false) instead.
5046
func mustSplit2(s, sep string) (string, string) {
@@ -96,29 +92,29 @@ func translateEndpoint(ep string) (addr string, serverName string, requireCreds
9692
if strings.HasPrefix(ep, "unix:///") || strings.HasPrefix(ep, "unixs:///") {
9793
// absolute path case
9894
schema, absolutePath := mustSplit2(ep, "://")
99-
return "unix://" + absolutePath, extractHostFromPath(absolutePath), schemeToCredsRequirement(schema)
95+
return "unix://" + absolutePath, path.Base(absolutePath), schemeToCredsRequirement(schema)
10096
}
10197
if strings.HasPrefix(ep, "unix://") || strings.HasPrefix(ep, "unixs://") {
10298
// legacy etcd local path
10399
schema, localPath := mustSplit2(ep, "://")
104-
return "unix:" + localPath, extractHostFromPath(localPath), schemeToCredsRequirement(schema)
100+
return "unix:" + localPath, path.Base(localPath), schemeToCredsRequirement(schema)
105101
}
106102
schema, localPath := mustSplit2(ep, ":")
107-
return "unix:" + localPath, extractHostFromPath(localPath), schemeToCredsRequirement(schema)
103+
return "unix:" + localPath, path.Base(localPath), schemeToCredsRequirement(schema)
108104
}
109105

110106
if strings.Contains(ep, "://") {
111107
url, err := url.Parse(ep)
112108
if err != nil {
113-
return ep, extractHostFromHostPort(ep), CREDS_OPTIONAL
109+
return ep, ep, CREDS_OPTIONAL
114110
}
115111
if url.Scheme == "http" || url.Scheme == "https" {
116-
return url.Host, url.Hostname(), schemeToCredsRequirement(url.Scheme)
112+
return url.Host, url.Host, schemeToCredsRequirement(url.Scheme)
117113
}
118-
return ep, url.Hostname(), schemeToCredsRequirement(url.Scheme)
114+
return ep, url.Host, schemeToCredsRequirement(url.Scheme)
119115
}
120116
// Handles plain addresses like 10.0.0.44:437.
121-
return ep, extractHostFromHostPort(ep), CREDS_OPTIONAL
117+
return ep, ep, CREDS_OPTIONAL
122118
}
123119

124120
// RequiresCredentials returns whether given endpoint requires

clientv3/internal/endpoint/endpoint_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,35 @@ func Test_interpret(t *testing.T) {
2727
}{
2828
{"127.0.0.1", "127.0.0.1", "127.0.0.1", CREDS_OPTIONAL},
2929
{"localhost", "localhost", "localhost", CREDS_OPTIONAL},
30-
{"localhost:8080", "localhost:8080", "localhost", CREDS_OPTIONAL},
30+
{"localhost:8080", "localhost:8080", "localhost:8080", CREDS_OPTIONAL},
3131

3232
{"unix:127.0.0.1", "unix:127.0.0.1", "127.0.0.1", CREDS_OPTIONAL},
33-
{"unix:127.0.0.1:8080", "unix:127.0.0.1:8080", "127.0.0.1", CREDS_OPTIONAL},
33+
{"unix:127.0.0.1:8080", "unix:127.0.0.1:8080", "127.0.0.1:8080", CREDS_OPTIONAL},
3434

3535
{"unix://127.0.0.1", "unix:127.0.0.1", "127.0.0.1", CREDS_OPTIONAL},
36-
{"unix://127.0.0.1:8080", "unix:127.0.0.1:8080", "127.0.0.1", CREDS_OPTIONAL},
36+
{"unix://127.0.0.1:8080", "unix:127.0.0.1:8080", "127.0.0.1:8080", CREDS_OPTIONAL},
3737

3838
{"unixs:127.0.0.1", "unix:127.0.0.1", "127.0.0.1", CREDS_REQUIRE},
39-
{"unixs:127.0.0.1:8080", "unix:127.0.0.1:8080", "127.0.0.1", CREDS_REQUIRE},
39+
{"unixs:127.0.0.1:8080", "unix:127.0.0.1:8080", "127.0.0.1:8080", CREDS_REQUIRE},
4040
{"unixs://127.0.0.1", "unix:127.0.0.1", "127.0.0.1", CREDS_REQUIRE},
41-
{"unixs://127.0.0.1:8080", "unix:127.0.0.1:8080", "127.0.0.1", CREDS_REQUIRE},
41+
{"unixs://127.0.0.1:8080", "unix:127.0.0.1:8080", "127.0.0.1:8080", CREDS_REQUIRE},
4242

4343
{"http://127.0.0.1", "127.0.0.1", "127.0.0.1", CREDS_DROP},
44-
{"http://127.0.0.1:8080", "127.0.0.1:8080", "127.0.0.1", CREDS_DROP},
44+
{"http://127.0.0.1:8080", "127.0.0.1:8080", "127.0.0.1:8080", CREDS_DROP},
4545
{"https://127.0.0.1", "127.0.0.1", "127.0.0.1", CREDS_REQUIRE},
46-
{"https://127.0.0.1:8080", "127.0.0.1:8080", "127.0.0.1", CREDS_REQUIRE},
47-
{"https://localhost:20000", "localhost:20000", "localhost", CREDS_REQUIRE},
46+
{"https://127.0.0.1:8080", "127.0.0.1:8080", "127.0.0.1:8080", CREDS_REQUIRE},
47+
{"https://localhost:20000", "localhost:20000", "localhost:20000", CREDS_REQUIRE},
4848

4949
{"unix:///tmp/abc", "unix:///tmp/abc", "abc", CREDS_OPTIONAL},
5050
{"unixs:///tmp/abc", "unix:///tmp/abc", "abc", CREDS_REQUIRE},
51-
{"unix:///tmp/abc:1234", "unix:///tmp/abc:1234", "abc", CREDS_OPTIONAL},
52-
{"unixs:///tmp/abc:1234", "unix:///tmp/abc:1234", "abc", CREDS_REQUIRE},
51+
{"unix:///tmp/abc:1234", "unix:///tmp/abc:1234", "abc:1234", CREDS_OPTIONAL},
52+
{"unixs:///tmp/abc:1234", "unix:///tmp/abc:1234", "abc:1234", CREDS_REQUIRE},
5353
{"etcd.io", "etcd.io", "etcd.io", CREDS_OPTIONAL},
5454
{"http://etcd.io/abc", "etcd.io", "etcd.io", CREDS_DROP},
5555
{"dns://something-other", "dns://something-other", "something-other", CREDS_OPTIONAL},
5656

57-
{"http://[2001:db8:1f70::999:de8:7648:6e8]:100/", "[2001:db8:1f70::999:de8:7648:6e8]:100", "2001:db8:1f70::999:de8:7648:6e8", CREDS_DROP},
58-
{"[2001:db8:1f70::999:de8:7648:6e8]:100", "[2001:db8:1f70::999:de8:7648:6e8]:100", "2001:db8:1f70::999:de8:7648:6e8", CREDS_OPTIONAL},
57+
{"http://[2001:db8:1f70::999:de8:7648:6e8]:100/", "[2001:db8:1f70::999:de8:7648:6e8]:100", "[2001:db8:1f70::999:de8:7648:6e8]:100", CREDS_DROP},
58+
{"[2001:db8:1f70::999:de8:7648:6e8]:100", "[2001:db8:1f70::999:de8:7648:6e8]:100", "[2001:db8:1f70::999:de8:7648:6e8]:100", CREDS_OPTIONAL},
5959
{"unix:unexpected-file_name#123$456", "unix:unexpected-file_name#123$456", "unexpected-file_name#123$456", CREDS_OPTIONAL},
6060
}
6161
for _, tt := range tests {

etcdserver/api/v3rpc/codec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package v3rpc
1616

17-
import "github.com/gogo/protobuf/proto"
17+
import "github.com/golang/protobuf/proto"
1818

1919
type codec struct{}
2020

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/gogo/protobuf v1.3.2
1414
github.com/golang-jwt/jwt v3.2.1+incompatible
1515
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903
16-
github.com/golang/protobuf v1.4.3
16+
github.com/golang/protobuf v1.5.2
1717
github.com/google/btree v1.0.0
1818
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4
1919
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
@@ -38,7 +38,7 @@ require (
3838
golang.org/x/sync v0.1.0
3939
golang.org/x/sys v0.13.0
4040
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2
41-
google.golang.org/grpc v1.29.1
41+
google.golang.org/grpc v1.52.0
4242
gopkg.in/cheggaaa/pb.v1 v1.0.25
4343
gopkg.in/yaml.v2 v2.4.0
4444
sigs.k8s.io/yaml v1.1.0
@@ -64,7 +64,7 @@ require (
6464
go.uber.org/atomic v1.3.2 // indirect
6565
go.uber.org/multierr v1.1.0 // indirect
6666
golang.org/x/text v0.13.0 // indirect
67-
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect
68-
google.golang.org/protobuf v1.26.0-rc.1 // indirect
67+
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect
68+
google.golang.org/protobuf v1.28.1 // indirect
6969
gopkg.in/yaml.v3 v3.0.1 // indirect
7070
)

go.sum

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
3333
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4 h1:qk/FSDDxo05wdJH28W+p5yivv7LuLYLRXPPD8KQCtZs=
3434
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
3535
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
36+
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
3637
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
3738
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
3839
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
@@ -63,9 +64,13 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x
6364
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
6465
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
6566
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
67+
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
6668
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
6769
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
6870
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
71+
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
72+
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
73+
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
6974
github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
7075
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
7176
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -266,19 +271,35 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
266271
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
267272
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE=
268273
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
274+
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
275+
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
276+
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 h1:a2S6M0+660BgMNl++4JPlcAO/CjkqYItDEZwkoDQK7c=
277+
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg=
269278
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
270279
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
271280
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
281+
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
272282
google.golang.org/grpc v1.29.1 h1:EC2SB8S04d2r73uptxphDSUG+kTKVgjRPF+N3xpxRB4=
273283
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
284+
google.golang.org/grpc v1.51.0 h1:E1eGv1FTqoLIdnBCZufiSHgKjlqG6fKFf6pPWtMTh8U=
285+
google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww=
286+
google.golang.org/grpc v1.52.0 h1:kd48UiU7EHsV4rnLyOJRuP/Il/UHE7gdDAQ+SZI7nZk=
287+
google.golang.org/grpc v1.52.0/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY=
274288
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
275289
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
276290
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
277291
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
278292
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
293+
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
279294
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
295+
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
280296
google.golang.org/protobuf v1.26.0-rc.1 h1:7QnIQpGRHE5RnLKnESfDoxm2dTapTZua5a0kS0A+VXQ=
281297
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
298+
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
299+
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
300+
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
301+
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
302+
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
282303
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
283304
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
284305
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

pkg/grpc_testing/stub_server.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ import (
3131
// StubServer is a server that is easy to customize within individual test
3232
// cases.
3333
type StubServer struct {
34-
// Guarantees we satisfy this interface; panics if unimplemented methods are called.
35-
testpb.TestServiceServer
36-
37-
EmptyCallF func(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error)
38-
UnaryCallF func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error)
39-
FullDuplexCallF func(stream testpb.TestService_FullDuplexCallServer) error
34+
testService testpb.TestServiceServer
4035

4136
s *grpc.Server
4237

@@ -47,19 +42,8 @@ type StubServer struct {
4742
cleanups []func() // Lambdas executed in Stop(); populated by Start().
4843
}
4944

50-
// EmptyCall is the handler for testpb.EmptyCall.
51-
func (ss *StubServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) {
52-
return ss.EmptyCallF(ctx, in)
53-
}
54-
55-
// UnaryCall is the handler for testpb.UnaryCall.
56-
func (ss *StubServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
57-
return ss.UnaryCallF(ctx, in)
58-
}
59-
60-
// FullDuplexCall is the handler for testpb.FullDuplexCall.
61-
func (ss *StubServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServer) error {
62-
return ss.FullDuplexCallF(stream)
45+
func New(testService testpb.TestServiceServer) *StubServer {
46+
return &StubServer{testService: testService}
6347
}
6448

6549
// 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)
7963
ss.cleanups = append(ss.cleanups, func() { lis.Close() })
8064

8165
s := grpc.NewServer(sopts...)
82-
testpb.RegisterTestServiceServer(s, ss)
66+
testpb.RegisterTestServiceServer(s, ss.testService)
8367
go s.Serve(lis)
8468
ss.cleanups = append(ss.cleanups, s.Stop)
8569
ss.s = s
@@ -98,3 +82,23 @@ func (ss *StubServer) Stop() {
9882
func (ss *StubServer) Addr() string {
9983
return ss.Address
10084
}
85+
86+
type dummyStubServer struct {
87+
testpb.UnimplementedTestServiceServer
88+
body []byte
89+
}
90+
91+
func (d dummyStubServer) UnaryCall(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
92+
return &testpb.SimpleResponse{
93+
Payload: &testpb.Payload{
94+
Type: testpb.PayloadType_COMPRESSABLE,
95+
Body: d.body,
96+
},
97+
}, nil
98+
}
99+
100+
// NewDummyStubServer creates a simple test server that serves Unary calls with
101+
// responses with the given payload.
102+
func NewDummyStubServer(body []byte) *StubServer {
103+
return New(dummyStubServer{body: body})
104+
}

0 commit comments

Comments
 (0)