You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/gateway/internal/descriptorsource_test.go

34 lines
961 B
Go

package internal
import (
"encoding/base64"
"io/ioutil"
"os"
"testing"
"github.com/fullstorydev/grpcurl"
"github.com/stretchr/testify/assert"
"github.com/zeromicro/go-zero/core/hash"
)
const b64pb = `CpgBCgtoZWxsby5wcm90bxIFaGVsbG8iHQoHUmVxdWVzdBISCgRwaW5nGAEgASgJUgRwaW5nIh4KCFJlc3BvbnNlEhIKBHBvbmcYASABKAlSBHBvbmcyMAoFSGVsbG8SJwoEUGluZxIOLmhlbGxvLlJlcXVlc3QaDy5oZWxsby5SZXNwb25zZUIJWgcuL2hlbGxvYgZwcm90bzM=`
func TestGetMethods(t *testing.T) {
tmpfile, err := ioutil.TempFile(os.TempDir(), hash.Md5Hex([]byte(b64pb)))
assert.Nil(t, err)
b, err := base64.StdEncoding.DecodeString(b64pb)
assert.Nil(t, err)
assert.Nil(t, ioutil.WriteFile(tmpfile.Name(), b, os.ModeTemporary))
defer os.Remove(tmpfile.Name())
source, err := grpcurl.DescriptorSourceFromProtoSets(tmpfile.Name())
assert.Nil(t, err)
methods, err := GetMethods(source)
assert.Nil(t, err)
assert.EqualValues(t, []Method{
{
RpcPath: "hello.Hello/Ping",
},
}, methods)
}