diff --git a/grpc_test.go b/grpc_test.go index 574058c..074d893 100644 --- a/grpc_test.go +++ b/grpc_test.go @@ -45,7 +45,7 @@ func TestGRPCClient(t *testing.T) { // register service r.Register(®istry.Service{ - Name: "test", + Name: "helloworld", Version: "test", Nodes: []*registry.Node{ ®istry.Node{ @@ -73,7 +73,7 @@ func TestGRPCClient(t *testing.T) { } for _, method := range testMethods { - req := c.NewRequest("test", method, &pb.HelloRequest{ + req := c.NewRequest("helloworld", method, &pb.HelloRequest{ Name: "John", }) diff --git a/request.go b/request.go index 94b44da..066577c 100644 --- a/request.go +++ b/request.go @@ -30,6 +30,10 @@ func methodToGRPC(service, method string) string { return method } + if len(service) == 0 { + return fmt.Sprintf("/%s/%s", mParts[0], mParts[1]) + } + // return /pkg.Foo/Bar return fmt.Sprintf("/%s.%s/%s", service, mParts[0], mParts[1]) } diff --git a/request_test.go b/request_test.go index eab3a3a..c73d675 100644 --- a/request_test.go +++ b/request_test.go @@ -2,45 +2,38 @@ package grpc import ( "testing" - - pb "google.golang.org/grpc/examples/helloworld/helloworld" ) func TestMethodToGRPC(t *testing.T) { testData := []struct { + service string method string expect string - request interface{} }{ { + "helloworld", "Greeter.SayHello", "/helloworld.Greeter/SayHello", - new(pb.HelloRequest), }, { + "helloworld", "/helloworld.Greeter/SayHello", "/helloworld.Greeter/SayHello", - new(pb.HelloRequest), }, { + "", + "/helloworld.Greeter/SayHello", + "/helloworld.Greeter/SayHello", + }, + { + "", "Greeter.SayHello", - "/helloworld.Greeter/SayHello", - pb.HelloRequest{}, - }, - { - "/helloworld.Greeter/SayHello", - "/helloworld.Greeter/SayHello", - pb.HelloRequest{}, - }, - { - "Greeter.SayHello", - "Greeter.SayHello", - nil, + "/Greeter/SayHello", }, } for _, d := range testData { - method := methodToGRPC(d.method, d.request) + method := methodToGRPC(d.service, d.method) if method != d.expect { t.Fatalf("expected %s got %s", d.expect, method) }