From ac076d648ca679d707da42fb2cd03c3990f61ef4 Mon Sep 17 00:00:00 2001 From: Cyrille Hemidy Date: Tue, 20 Feb 2018 22:35:16 +0100 Subject: [PATCH 1/7] fix golint --- cmd/grpcurl/grpcurl.go | 5 ++--- grpcurl.go | 34 ++++++++++++++-------------------- testing/test_server.go | 12 ++++++------ 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/cmd/grpcurl/grpcurl.go b/cmd/grpcurl/grpcurl.go index 57b714d..88cbab4 100644 --- a/cmd/grpcurl/grpcurl.go +++ b/cmd/grpcurl/grpcurl.go @@ -434,10 +434,9 @@ func (h *handler) getRequestData() ([]byte, error) { var msg json.RawMessage if err := h.dec.Decode(&msg); err != nil { return nil, err - } else { - h.reqCount++ - return msg, nil } + h.reqCount++ + return msg, nil } func (*handler) OnReceiveHeaders(md metadata.MD) { diff --git a/grpcurl.go b/grpcurl.go index 095ac88..d97662e 100644 --- a/grpcurl.go +++ b/grpcurl.go @@ -225,16 +225,16 @@ func ListMethods(source DescriptorSource, serviceName string) ([]string, error) if err != nil { return nil, err } - if sd, ok := dsc.(*desc.ServiceDescriptor); !ok { + sd, ok := dsc.(*desc.ServiceDescriptor) + if !ok { return nil, notFound("Service", serviceName) - } else { - methods := make([]string, 0, len(sd.GetMethods())) - for _, method := range sd.GetMethods() { - methods = append(methods, method.GetName()) - } - sort.Strings(methods) - return methods, nil } + methods := make([]string, 0, len(sd.GetMethods())) + for _, method := range sd.GetMethods() { + methods = append(methods, method.GetName()) + } + sort.Strings(methods) + return methods, nil } type notFoundError string @@ -304,9 +304,8 @@ func InvokeRpc(ctx context.Context, source DescriptorSource, cc *grpc.ClientConn if err != nil { if isNotFoundError(err) { return fmt.Errorf("target server does not expose service %q", svc) - } else { - return fmt.Errorf("failed to query for service descriptor %q: %v", svc, err) } + return fmt.Errorf("failed to query for service descriptor %q: %v", svc, err) } sd, ok := dsc.(*desc.ServiceDescriptor) if !ok { @@ -345,9 +344,8 @@ func InvokeRpc(ctx context.Context, source DescriptorSource, cc *grpc.ClientConn return invokeClientStream(ctx, stub, mtd, handler, requestData, req) } else if mtd.IsServerStreaming() { return invokeServerStream(ctx, stub, mtd, handler, requestData, req) - } else { - return invokeUnary(ctx, stub, mtd, handler, requestData, req) } + return invokeUnary(ctx, stub, mtd, handler, requestData, req) } func invokeUnary(ctx context.Context, stub grpcdynamic.Stub, md *desc.MethodDescriptor, handler InvocationEventHandler, @@ -765,9 +763,8 @@ func fullyConvertToDynamic(msgFact *dynamic.MessageFactory, msg proto.Message) ( newVal, err := fullyConvertToDynamic(msgFact, v.(proto.Message)) if err != nil { return nil, err - } else { - dm.PutMapField(fd, k, newVal) } + dm.PutMapField(fd, k, newVal) } } } else if fd.IsRepeated() { @@ -777,9 +774,8 @@ func fullyConvertToDynamic(msgFact *dynamic.MessageFactory, msg proto.Message) ( newVal, err := fullyConvertToDynamic(msgFact, e.(proto.Message)) if err != nil { return nil, err - } else { - dm.SetRepeatedField(fd, i, newVal) } + dm.SetRepeatedField(fd, i, newVal) } } } else { @@ -788,9 +784,8 @@ func fullyConvertToDynamic(msgFact *dynamic.MessageFactory, msg proto.Message) ( newVal, err := fullyConvertToDynamic(msgFact, v.(proto.Message)) if err != nil { return nil, err - } else { - dm.SetField(fd, newVal) } + dm.SetField(fd, newVal) } } } @@ -936,9 +931,8 @@ func BlockingDial(ctx context.Context, address string, creds credentials.Transpo case res := <-result: if conn, ok := res.(*grpc.ClientConn); ok { return conn, nil - } else { - return nil, res.(error) } + return nil, res.(error) case <-ctx.Done(): return nil, ctx.Err() } diff --git a/testing/test_server.go b/testing/test_server.go index 37a04d1..e55a7a8 100644 --- a/testing/test_server.go +++ b/testing/test_server.go @@ -17,7 +17,7 @@ import ( type TestServer struct{} -// One empty request followed by one empty response. +// EmptyCall is One empty request followed by one empty response. func (TestServer) EmptyCall(ctx context.Context, req *grpc_testing.Empty) (*grpc_testing.Empty, error) { headers, trailers, failEarly, failLate := processMetadata(ctx) grpc.SetHeader(ctx, headers) @@ -32,7 +32,7 @@ func (TestServer) EmptyCall(ctx context.Context, req *grpc_testing.Empty) (*grpc return req, nil } -// One request followed by one response. +// UnaryCall One request followed by one response. // The server returns the client payload as-is. func (TestServer) UnaryCall(ctx context.Context, req *grpc_testing.SimpleRequest) (*grpc_testing.SimpleResponse, error) { headers, trailers, failEarly, failLate := processMetadata(ctx) @@ -50,7 +50,7 @@ func (TestServer) UnaryCall(ctx context.Context, req *grpc_testing.SimpleRequest }, nil } -// One request followed by a sequence of responses (streamed download). +// StreamingOutputCall is One request followed by a sequence of responses (streamed download). // The server returns the payload with client desired type and sizes. func (TestServer) StreamingOutputCall(req *grpc_testing.StreamingOutputCallRequest, str grpc_testing.TestService_StreamingOutputCallServer) error { headers, trailers, failEarly, failLate := processMetadata(str.Context()) @@ -87,7 +87,7 @@ func (TestServer) StreamingOutputCall(req *grpc_testing.StreamingOutputCallReque return nil } -// A sequence of requests followed by one response (streamed upload). +// StreamingInputCall is A sequence of requests followed by one response (streamed upload). // The server returns the aggregated size of client payload as the result. func (TestServer) StreamingInputCall(str grpc_testing.TestService_StreamingInputCallServer) error { headers, trailers, failEarly, failLate := processMetadata(str.Context()) @@ -121,7 +121,7 @@ func (TestServer) StreamingInputCall(str grpc_testing.TestService_StreamingInput return nil } -// A sequence of requests with each request served by the server immediately. +// FullDuplexCall is A sequence of requests with each request served by the server immediately. // As one request could lead to multiple responses, this interface // demonstrates the idea of full duplexing. func (TestServer) FullDuplexCall(str grpc_testing.TestService_FullDuplexCallServer) error { @@ -163,7 +163,7 @@ func (TestServer) FullDuplexCall(str grpc_testing.TestService_FullDuplexCallServ return nil } -// A sequence of requests followed by a sequence of responses. +// HalfDuplexCall is A sequence of requests followed by a sequence of responses. // The server buffers all the client requests and then serves them in order. A // stream of responses are returned to the client when the server starts with // first request. From f81c1ab702048c7ce58f18e885c81b657947b9f7 Mon Sep 17 00:00:00 2001 From: Cyrille Hemidy Date: Tue, 20 Feb 2018 22:53:42 +0100 Subject: [PATCH 2/7] fix golint --- testing/test_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_server.go b/testing/test_server.go index e55a7a8..43542c8 100644 --- a/testing/test_server.go +++ b/testing/test_server.go @@ -32,7 +32,7 @@ func (TestServer) EmptyCall(ctx context.Context, req *grpc_testing.Empty) (*grpc return req, nil } -// UnaryCall One request followed by one response. +// UnaryCall is One request followed by one response. // The server returns the client payload as-is. func (TestServer) UnaryCall(ctx context.Context, req *grpc_testing.SimpleRequest) (*grpc_testing.SimpleResponse, error) { headers, trailers, failEarly, failLate := processMetadata(ctx) From 2ea74735a8dc67bd3ef48c476205a9219d9f0616 Mon Sep 17 00:00:00 2001 From: Cyrille Hemidy Date: Tue, 20 Feb 2018 23:06:57 +0100 Subject: [PATCH 3/7] fix golint --- testing/test_server.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/testing/test_server.go b/testing/test_server.go index 43542c8..2c6748f 100644 --- a/testing/test_server.go +++ b/testing/test_server.go @@ -17,7 +17,7 @@ import ( type TestServer struct{} -// EmptyCall is One empty request followed by one empty response. +// One empty request followed by one empty response. func (TestServer) EmptyCall(ctx context.Context, req *grpc_testing.Empty) (*grpc_testing.Empty, error) { headers, trailers, failEarly, failLate := processMetadata(ctx) grpc.SetHeader(ctx, headers) @@ -32,7 +32,7 @@ func (TestServer) EmptyCall(ctx context.Context, req *grpc_testing.Empty) (*grpc return req, nil } -// UnaryCall is One request followed by one response. +// One request followed by one response. // The server returns the client payload as-is. func (TestServer) UnaryCall(ctx context.Context, req *grpc_testing.SimpleRequest) (*grpc_testing.SimpleResponse, error) { headers, trailers, failEarly, failLate := processMetadata(ctx) @@ -50,7 +50,7 @@ func (TestServer) UnaryCall(ctx context.Context, req *grpc_testing.SimpleRequest }, nil } -// StreamingOutputCall is One request followed by a sequence of responses (streamed download). +// One request followed by a sequence of responses (streamed download). // The server returns the payload with client desired type and sizes. func (TestServer) StreamingOutputCall(req *grpc_testing.StreamingOutputCallRequest, str grpc_testing.TestService_StreamingOutputCallServer) error { headers, trailers, failEarly, failLate := processMetadata(str.Context()) @@ -87,7 +87,7 @@ func (TestServer) StreamingOutputCall(req *grpc_testing.StreamingOutputCallReque return nil } -// StreamingInputCall is A sequence of requests followed by one response (streamed upload). +// A sequence of requests followed by one response (streamed upload). // The server returns the aggregated size of client payload as the result. func (TestServer) StreamingInputCall(str grpc_testing.TestService_StreamingInputCallServer) error { headers, trailers, failEarly, failLate := processMetadata(str.Context()) @@ -102,14 +102,14 @@ func (TestServer) StreamingInputCall(str grpc_testing.TestService_StreamingInput if str.Context().Err() != nil { return str.Context().Err() } - if req, err := str.Recv(); err != nil { + req, err := str.Recv() + if err != nil { if err == io.EOF { break } return err - } else { - sz += len(req.Payload.Body) } + sz += len(req.Payload.Body) } if err := str.SendAndClose(&grpc_testing.StreamingInputCallResponse{AggregatedPayloadSize: int32(sz)}); err != nil { return err @@ -121,7 +121,7 @@ func (TestServer) StreamingInputCall(str grpc_testing.TestService_StreamingInput return nil } -// FullDuplexCall is A sequence of requests with each request served by the server immediately. +// A sequence of requests with each request served by the server immediately. // As one request could lead to multiple responses, this interface // demonstrates the idea of full duplexing. func (TestServer) FullDuplexCall(str grpc_testing.TestService_FullDuplexCallServer) error { @@ -163,7 +163,7 @@ func (TestServer) FullDuplexCall(str grpc_testing.TestService_FullDuplexCallServ return nil } -// HalfDuplexCall is A sequence of requests followed by a sequence of responses. +// A sequence of requests followed by a sequence of responses. // The server buffers all the client requests and then serves them in order. A // stream of responses are returned to the client when the server starts with // first request. @@ -180,14 +180,14 @@ func (TestServer) HalfDuplexCall(str grpc_testing.TestService_HalfDuplexCallServ if str.Context().Err() != nil { return str.Context().Err() } - if req, err := str.Recv(); err != nil { + req, err := str.Recv() + if err != nil { if err == io.EOF { break } return err - } else { - reqs = append(reqs, req) } + reqs = append(reqs, req) } rsp := &grpc_testing.StreamingOutputCallResponse{} for _, req := range reqs { From 01830654f7b42b8225559ac86041de90dbb7387b Mon Sep 17 00:00:00 2001 From: Cyrille Hemidy Date: Tue, 20 Feb 2018 23:16:37 +0100 Subject: [PATCH 4/7] fix golint --- testing/test_server.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/testing/test_server.go b/testing/test_server.go index 2c6748f..0cbc6b8 100644 --- a/testing/test_server.go +++ b/testing/test_server.go @@ -102,14 +102,16 @@ func (TestServer) StreamingInputCall(str grpc_testing.TestService_StreamingInput if str.Context().Err() != nil { return str.Context().Err() } - req, err := str.Recv() - if err != nil { - if err == io.EOF { - break + if req, err := str.Recv(); err != nil { + if err != nil { + if err == io.EOF { + break + } + return err } - return err + } else { + sz += len(req.Payload.Body) } - sz += len(req.Payload.Body) } if err := str.SendAndClose(&grpc_testing.StreamingInputCallResponse{AggregatedPayloadSize: int32(sz)}); err != nil { return err @@ -180,14 +182,14 @@ func (TestServer) HalfDuplexCall(str grpc_testing.TestService_HalfDuplexCallServ if str.Context().Err() != nil { return str.Context().Err() } - req, err := str.Recv() - if err != nil { + if req, err := str.Recv(); err != nil { if err == io.EOF { break } return err + } else { + reqs = append(reqs, req) } - reqs = append(reqs, req) } rsp := &grpc_testing.StreamingOutputCallResponse{} for _, req := range reqs { From 607b1db9545ae0aabde5d2c8b1b8c1dee9a06501 Mon Sep 17 00:00:00 2001 From: Cyrille Hemidy Date: Tue, 20 Feb 2018 23:17:51 +0100 Subject: [PATCH 5/7] rollback TestServer golint --- testing/test_server.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/testing/test_server.go b/testing/test_server.go index 0cbc6b8..37a04d1 100644 --- a/testing/test_server.go +++ b/testing/test_server.go @@ -103,12 +103,10 @@ func (TestServer) StreamingInputCall(str grpc_testing.TestService_StreamingInput return str.Context().Err() } if req, err := str.Recv(); err != nil { - if err != nil { - if err == io.EOF { - break - } - return err + if err == io.EOF { + break } + return err } else { sz += len(req.Payload.Body) } From cdd14fc200cf72a610143dc3464ea9a12b09fac5 Mon Sep 17 00:00:00 2001 From: Cyrille Hemidy Date: Wed, 21 Feb 2018 15:38:59 +0100 Subject: [PATCH 6/7] fix golint + update travis --- .travis.yml | 2 +- Makefile | 2 +- cmd/grpcurl/grpcurl.go | 6 ++++-- grpcurl.go | 4 ++-- grpcurl_test.go | 30 +++++++++++++++--------------- testing/test_server.go | 26 ++++++++++++++------------ 6 files changed, 37 insertions(+), 33 deletions(-) diff --git a/.travis.yml b/.travis.yml index 54c7d98..df24689 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,4 @@ matrix: script: # TODO: change to "make" when golint, errcheck, staticcheck pass - - make deps checkgofmt vet unused test + - make deps checkgofmt golint vet unused test diff --git a/Makefile b/Makefile index 48f25fc..20e1542 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ vet: .PHONY: errcheck: @go get github.com/kisielk/errcheck - errcheck $(PKGS) + errcheck -verbose $(PKGS) .PHONY: staticcheck staticcheck: diff --git a/cmd/grpcurl/grpcurl.go b/cmd/grpcurl/grpcurl.go index 88cbab4..930d8cc 100644 --- a/cmd/grpcurl/grpcurl.go +++ b/cmd/grpcurl/grpcurl.go @@ -244,7 +244,9 @@ func main() { refClient = nil } if cc != nil { - cc.Close() + if err := cc.Close(); err != nil { + fail(err, "Failed to close grpc Client") + } cc = nil } } @@ -343,7 +345,7 @@ func main() { } h := &handler{dec: dec, descSource: descSource} - err := grpcurl.InvokeRpc(ctx, descSource, cc, symbol, addlHeaders, h, h.getRequestData) + err := grpcurl.InvokeRPC(ctx, descSource, cc, symbol, addlHeaders, h, h.getRequestData) if err != nil { fail(err, "Error invoking method %q", symbol) } diff --git a/grpcurl.go b/grpcurl.go index d97662e..158a06f 100644 --- a/grpcurl.go +++ b/grpcurl.go @@ -276,7 +276,7 @@ type InvocationEventHandler interface { // the supplier has no more messages, it should return nil, io.EOF. type RequestMessageSupplier func() ([]byte, error) -// InvokeRpc uses te given GRPC connection to invoke the given method. The given descriptor source +// InvokeRPC uses te given GRPC connection to invoke the given method. The given descriptor source // is used to determine the type of method and the type of request and response message. The given // headers are sent as request metadata. Methods on the given event handler are called as the // invocation proceeds. @@ -291,7 +291,7 @@ type RequestMessageSupplier func() ([]byte, error) // be thread-safe. This is because the requestData function may be called from a different goroutine // than the one invoking event callbacks. (This only happens for bi-directional streaming RPCs, where // one goroutine sends request messages and another consumes the response messages). -func InvokeRpc(ctx context.Context, source DescriptorSource, cc *grpc.ClientConn, methodName string, +func InvokeRPC(ctx context.Context, source DescriptorSource, cc *grpc.ClientConn, methodName string, headers []string, handler InvocationEventHandler, requestData RequestMessageSupplier) error { md := MetadataFromHeaders(headers) diff --git a/grpcurl_test.go b/grpcurl_test.go index 453fcb2..e1de684 100644 --- a/grpcurl_test.go +++ b/grpcurl_test.go @@ -108,7 +108,7 @@ func TestServerDoesNotSupportReflection(t *testing.T) { t.Errorf("ListMethods should have returned ErrReflectionNotSupported; instead got %v", err) } - err = InvokeRpc(context.Background(), refSource, ccProtoset, "FooService/Method", nil, nil, nil) + err = InvokeRPC(context.Background(), refSource, ccProtoset, "FooService/Method", nil, nil, nil) // InvokeRpc wraps the error, so we just verify the returned error includes the right message if err == nil || !strings.Contains(err.Error(), ErrReflectionNotSupported.Error()) { t.Errorf("InvokeRpc should have returned ErrReflectionNotSupported; instead got %v", err) @@ -307,7 +307,7 @@ func TestUnaryReflect(t *testing.T) { func doTestUnary(t *testing.T, cc *grpc.ClientConn, source DescriptorSource) { // Success h := &handler{reqMessages: []string{payload1}} - err := InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/UnaryCall", makeHeaders(codes.OK), h, h.getRequestData) + err := InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/UnaryCall", makeHeaders(codes.OK), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } @@ -320,7 +320,7 @@ func doTestUnary(t *testing.T, cc *grpc.ClientConn, source DescriptorSource) { // Failure h = &handler{reqMessages: []string{payload1}} - err = InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/UnaryCall", makeHeaders(codes.NotFound), h, h.getRequestData) + err = InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/UnaryCall", makeHeaders(codes.NotFound), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } @@ -339,7 +339,7 @@ func TestClientStreamReflect(t *testing.T) { func doTestClientStream(t *testing.T, cc *grpc.ClientConn, source DescriptorSource) { // Success h := &handler{reqMessages: []string{payload1, payload2, payload3}} - err := InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/StreamingInputCall", makeHeaders(codes.OK), h, h.getRequestData) + err := InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/StreamingInputCall", makeHeaders(codes.OK), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } @@ -356,7 +356,7 @@ func doTestClientStream(t *testing.T, cc *grpc.ClientConn, source DescriptorSour // Fail fast (server rejects as soon as possible) h = &handler{reqMessages: []string{payload1, payload2, payload3}} - err = InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/StreamingInputCall", makeHeaders(codes.InvalidArgument), h, h.getRequestData) + err = InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/StreamingInputCall", makeHeaders(codes.InvalidArgument), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } @@ -365,7 +365,7 @@ func doTestClientStream(t *testing.T, cc *grpc.ClientConn, source DescriptorSour // Fail late (server waits until stream is complete to reject) h = &handler{reqMessages: []string{payload1, payload2, payload3}} - err = InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/StreamingInputCall", makeHeaders(codes.Internal, true), h, h.getRequestData) + err = InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/StreamingInputCall", makeHeaders(codes.Internal, true), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } @@ -395,7 +395,7 @@ func doTestServerStream(t *testing.T, cc *grpc.ClientConn, source DescriptorSour // Success h := &handler{reqMessages: []string{payload}} - err = InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/StreamingOutputCall", makeHeaders(codes.OK), h, h.getRequestData) + err = InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/StreamingOutputCall", makeHeaders(codes.OK), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } @@ -418,7 +418,7 @@ func doTestServerStream(t *testing.T, cc *grpc.ClientConn, source DescriptorSour // Fail fast (server rejects as soon as possible) h = &handler{reqMessages: []string{payload}} - err = InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/StreamingOutputCall", makeHeaders(codes.Aborted), h, h.getRequestData) + err = InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/StreamingOutputCall", makeHeaders(codes.Aborted), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } @@ -427,7 +427,7 @@ func doTestServerStream(t *testing.T, cc *grpc.ClientConn, source DescriptorSour // Fail late (server waits until stream is complete to reject) h = &handler{reqMessages: []string{payload}} - err = InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/StreamingOutputCall", makeHeaders(codes.AlreadyExists, true), h, h.getRequestData) + err = InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/StreamingOutputCall", makeHeaders(codes.AlreadyExists, true), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } @@ -448,7 +448,7 @@ func doTestHalfDuplexStream(t *testing.T, cc *grpc.ClientConn, source Descriptor // Success h := &handler{reqMessages: reqs} - err := InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/HalfDuplexCall", makeHeaders(codes.OK), h, h.getRequestData) + err := InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/HalfDuplexCall", makeHeaders(codes.OK), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } @@ -463,7 +463,7 @@ func doTestHalfDuplexStream(t *testing.T, cc *grpc.ClientConn, source Descriptor // Fail fast (server rejects as soon as possible) h = &handler{reqMessages: reqs} - err = InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/HalfDuplexCall", makeHeaders(codes.Canceled), h, h.getRequestData) + err = InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/HalfDuplexCall", makeHeaders(codes.Canceled), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } @@ -472,7 +472,7 @@ func doTestHalfDuplexStream(t *testing.T, cc *grpc.ClientConn, source Descriptor // Fail late (server waits until stream is complete to reject) h = &handler{reqMessages: reqs} - err = InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/HalfDuplexCall", makeHeaders(codes.DataLoss, true), h, h.getRequestData) + err = InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/HalfDuplexCall", makeHeaders(codes.DataLoss, true), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } @@ -504,7 +504,7 @@ func doTestFullDuplexStream(t *testing.T, cc *grpc.ClientConn, source Descriptor // Success h := &handler{reqMessages: reqs} - err := InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/FullDuplexCall", makeHeaders(codes.OK), h, h.getRequestData) + err := InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/FullDuplexCall", makeHeaders(codes.OK), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } @@ -535,7 +535,7 @@ func doTestFullDuplexStream(t *testing.T, cc *grpc.ClientConn, source Descriptor // Fail fast (server rejects as soon as possible) h = &handler{reqMessages: reqs} - err = InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/FullDuplexCall", makeHeaders(codes.PermissionDenied), h, h.getRequestData) + err = InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/FullDuplexCall", makeHeaders(codes.PermissionDenied), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } @@ -544,7 +544,7 @@ func doTestFullDuplexStream(t *testing.T, cc *grpc.ClientConn, source Descriptor // Fail late (server waits until stream is complete to reject) h = &handler{reqMessages: reqs} - err = InvokeRpc(context.Background(), source, cc, "grpc.testing.TestService/FullDuplexCall", makeHeaders(codes.ResourceExhausted, true), h, h.getRequestData) + err = InvokeRPC(context.Background(), source, cc, "grpc.testing.TestService/FullDuplexCall", makeHeaders(codes.ResourceExhausted, true), h, h.getRequestData) if err != nil { t.Fatalf("unexpected error during RPC: %v", err) } diff --git a/testing/test_server.go b/testing/test_server.go index 37a04d1..42fa86f 100644 --- a/testing/test_server.go +++ b/testing/test_server.go @@ -15,9 +15,10 @@ import ( "github.com/fullstorydev/grpcurl" ) +// TestServer is the testserver instance type TestServer struct{} -// One empty request followed by one empty response. +// EmptyCall is One empty request followed by one empty response. func (TestServer) EmptyCall(ctx context.Context, req *grpc_testing.Empty) (*grpc_testing.Empty, error) { headers, trailers, failEarly, failLate := processMetadata(ctx) grpc.SetHeader(ctx, headers) @@ -32,7 +33,7 @@ func (TestServer) EmptyCall(ctx context.Context, req *grpc_testing.Empty) (*grpc return req, nil } -// One request followed by one response. +// UnaryCall is One request followed by one response. // The server returns the client payload as-is. func (TestServer) UnaryCall(ctx context.Context, req *grpc_testing.SimpleRequest) (*grpc_testing.SimpleResponse, error) { headers, trailers, failEarly, failLate := processMetadata(ctx) @@ -50,7 +51,7 @@ func (TestServer) UnaryCall(ctx context.Context, req *grpc_testing.SimpleRequest }, nil } -// One request followed by a sequence of responses (streamed download). +// StreamingOutputCall is One request followed by a sequence of responses (streamed download). // The server returns the payload with client desired type and sizes. func (TestServer) StreamingOutputCall(req *grpc_testing.StreamingOutputCallRequest, str grpc_testing.TestService_StreamingOutputCallServer) error { headers, trailers, failEarly, failLate := processMetadata(str.Context()) @@ -87,7 +88,7 @@ func (TestServer) StreamingOutputCall(req *grpc_testing.StreamingOutputCallReque return nil } -// A sequence of requests followed by one response (streamed upload). +// StreamingInputCall is A sequence of requests followed by one response (streamed upload). // The server returns the aggregated size of client payload as the result. func (TestServer) StreamingInputCall(str grpc_testing.TestService_StreamingInputCallServer) error { headers, trailers, failEarly, failLate := processMetadata(str.Context()) @@ -103,10 +104,10 @@ func (TestServer) StreamingInputCall(str grpc_testing.TestService_StreamingInput return str.Context().Err() } if req, err := str.Recv(); err != nil { - if err == io.EOF { - break + if err != io.EOF { + return err } - return err + break } else { sz += len(req.Payload.Body) } @@ -121,7 +122,7 @@ func (TestServer) StreamingInputCall(str grpc_testing.TestService_StreamingInput return nil } -// A sequence of requests with each request served by the server immediately. +// FullDuplexCall is A sequence of requests with each request served by the server immediately. // As one request could lead to multiple responses, this interface // demonstrates the idea of full duplexing. func (TestServer) FullDuplexCall(str grpc_testing.TestService_FullDuplexCallServer) error { @@ -163,7 +164,7 @@ func (TestServer) FullDuplexCall(str grpc_testing.TestService_FullDuplexCallServ return nil } -// A sequence of requests followed by a sequence of responses. +// HalfDuplexCall is A sequence of requests followed by a sequence of responses. // The server buffers all the client requests and then serves them in order. A // stream of responses are returned to the client when the server starts with // first request. @@ -181,10 +182,10 @@ func (TestServer) HalfDuplexCall(str grpc_testing.TestService_HalfDuplexCallServ return str.Context().Err() } if req, err := str.Recv(); err != nil { - if err == io.EOF { - break + if err != io.EOF { + return err } - return err + break } else { reqs = append(reqs, req) } @@ -203,6 +204,7 @@ func (TestServer) HalfDuplexCall(str grpc_testing.TestService_HalfDuplexCallServ return nil } +// Metadata const const ( MetadataReplyHeaders = "reply-with-headers" MetadataReplyTrailers = "reply-with-trailers" From c78830ce37a29f9d5c364e825a2fd65e4ba3bff4 Mon Sep 17 00:00:00 2001 From: Cyrille Hemidy Date: Wed, 21 Feb 2018 15:45:44 +0100 Subject: [PATCH 7/7] add go 1.10 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index df24689..38cfdb5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ matrix: - go: 1.7 - go: 1.8 - go: 1.9 + - go: "1.10" - go: tip script: