feat: verify RpcPath on startup (#2159)
* feat: verify RpcPath on startup * feat: support http header Grpc-Timeout
This commit is contained in:
29
gateway/internal/descriptorsource_test.go
Normal file
29
gateway/internal/descriptorsource_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
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, []string{"hello.Hello/Ping"}, methods)
|
||||
}
|
||||
Reference in New Issue
Block a user