-
Notifications
You must be signed in to change notification settings - Fork 23
/
test_util.go
40 lines (35 loc) · 966 Bytes
/
test_util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package proto
import (
"context"
"fmt"
"github.com/cloudwego/dynamicgo/internal/util_test"
)
// GetFnDescFromFile get a fucntion descriptor from idl path (relative to your git root) and
// the function name
func GetFnDescFromFile(filePath, fnName string, opts Options, includeDirs ...string) *MethodDescriptor {
svc, err := opts.NewDescriptorFromPath(context.Background(), util_test.MustGitPath(filePath), includeDirs...)
if err != nil {
panic(fmt.Errorf("%s:%s", util_test.MustGitPath(filePath), err))
}
fn := svc.LookupMethodByName(fnName)
if fn == nil {
return nil
}
return fn
}
// FnRequest get the normal requestDescriptor
func FnRequest(fn *MethodDescriptor) *TypeDescriptor {
request := fn.Input()
if request == nil {
return nil
}
return request
}
// FnResponse get hte normal responseDescriptor
func FnResponse(fn *MethodDescriptor) *TypeDescriptor {
response := fn.Output()
if response == nil {
return nil
}
return response
}