Fix the grpc test

This commit is contained in:
Asim Aslam 2019-06-19 12:34:45 +01:00
parent e9c2df775a
commit 1c1dae0642
3 changed files with 17 additions and 20 deletions

View File

@ -45,7 +45,7 @@ func TestGRPCClient(t *testing.T) {
// register service // register service
r.Register(&registry.Service{ r.Register(&registry.Service{
Name: "test", Name: "helloworld",
Version: "test", Version: "test",
Nodes: []*registry.Node{ Nodes: []*registry.Node{
&registry.Node{ &registry.Node{
@ -73,7 +73,7 @@ func TestGRPCClient(t *testing.T) {
} }
for _, method := range testMethods { for _, method := range testMethods {
req := c.NewRequest("test", method, &pb.HelloRequest{ req := c.NewRequest("helloworld", method, &pb.HelloRequest{
Name: "John", Name: "John",
}) })

View File

@ -30,6 +30,10 @@ func methodToGRPC(service, method string) string {
return method return method
} }
if len(service) == 0 {
return fmt.Sprintf("/%s/%s", mParts[0], mParts[1])
}
// return /pkg.Foo/Bar // return /pkg.Foo/Bar
return fmt.Sprintf("/%s.%s/%s", service, mParts[0], mParts[1]) return fmt.Sprintf("/%s.%s/%s", service, mParts[0], mParts[1])
} }

View File

@ -2,45 +2,38 @@ package grpc
import ( import (
"testing" "testing"
pb "google.golang.org/grpc/examples/helloworld/helloworld"
) )
func TestMethodToGRPC(t *testing.T) { func TestMethodToGRPC(t *testing.T) {
testData := []struct { testData := []struct {
service string
method string method string
expect string expect string
request interface{}
}{ }{
{ {
"helloworld",
"Greeter.SayHello", "Greeter.SayHello",
"/helloworld.Greeter/SayHello", "/helloworld.Greeter/SayHello",
new(pb.HelloRequest),
}, },
{ {
"helloworld",
"/helloworld.Greeter/SayHello", "/helloworld.Greeter/SayHello",
"/helloworld.Greeter/SayHello", "/helloworld.Greeter/SayHello",
new(pb.HelloRequest),
}, },
{ {
"",
"/helloworld.Greeter/SayHello",
"/helloworld.Greeter/SayHello",
},
{
"",
"Greeter.SayHello", "Greeter.SayHello",
"/helloworld.Greeter/SayHello", "/Greeter/SayHello",
pb.HelloRequest{},
},
{
"/helloworld.Greeter/SayHello",
"/helloworld.Greeter/SayHello",
pb.HelloRequest{},
},
{
"Greeter.SayHello",
"Greeter.SayHello",
nil,
}, },
} }
for _, d := range testData { for _, d := range testData {
method := methodToGRPC(d.method, d.request) method := methodToGRPC(d.service, d.method)
if method != d.expect { if method != d.expect {
t.Fatalf("expected %s got %s", d.expect, method) t.Fatalf("expected %s got %s", d.expect, method)
} }