github.com/xiaoshude/protoreflect@v1.16.1-0.20220310024924-8c94d7247598/grpcreflect/server_test.go (about)

     1  package grpcreflect
     2  
     3  import (
     4  	"testing"
     5  
     6  	"google.golang.org/grpc"
     7  
     8  	"github.com/xiaoshude/protoreflect/internal/testprotos"
     9  	"github.com/xiaoshude/protoreflect/internal/testutil"
    10  )
    11  
    12  type testService struct {
    13  	testprotos.TestServiceServer
    14  }
    15  
    16  func TestLoadServiceDescriptors(t *testing.T) {
    17  	s := grpc.NewServer()
    18  	testprotos.RegisterTestServiceServer(s, testService{})
    19  	sds, err := LoadServiceDescriptors(s)
    20  	testutil.Ok(t, err)
    21  	testutil.Eq(t, 1, len(sds))
    22  	sd := sds["testprotos.TestService"]
    23  
    24  	cases := []struct{ method, request, response string }{
    25  		{"DoSomething", "testprotos.TestRequest", "jhump.protoreflect.desc.Bar"},
    26  		{"DoSomethingElse", "testprotos.TestMessage", "testprotos.TestResponse"},
    27  		{"DoSomethingAgain", "jhump.protoreflect.desc.Bar", "testprotos.AnotherTestMessage"},
    28  		{"DoSomethingForever", "testprotos.TestRequest", "testprotos.TestResponse"},
    29  	}
    30  
    31  	testutil.Eq(t, len(cases), len(sd.GetMethods()))
    32  
    33  	for i, c := range cases {
    34  		md := sd.GetMethods()[i]
    35  		testutil.Eq(t, c.method, md.GetName())
    36  		testutil.Eq(t, c.request, md.GetInputType().GetFullyQualifiedName())
    37  		testutil.Eq(t, c.response, md.GetOutputType().GetFullyQualifiedName())
    38  	}
    39  }