Fix the grpc test
This commit is contained in:
parent
e83572b994
commit
7596a027d9
@ -45,7 +45,7 @@ func TestGRPCClient(t *testing.T) {
|
|||||||
|
|
||||||
// register service
|
// register service
|
||||||
r.Register(®istry.Service{
|
r.Register(®istry.Service{
|
||||||
Name: "test",
|
Name: "helloworld",
|
||||||
Version: "test",
|
Version: "test",
|
||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
®istry.Node{
|
®istry.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",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -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])
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user