-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
GoMybatisProxy_test.go
61 lines (55 loc) · 1.57 KB
/
GoMybatisProxy_test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package GoMybatis
import (
"fmt"
"reflect"
"testing"
)
type TestMapper struct {
SelectByIds func(id string) (string, error) `args:"ids"`
}
func TestUseMapperValue(t *testing.T) {
var test = TestMapper{}
ProxyValue(reflect.ValueOf(&test), func(funcField reflect.StructField, field reflect.Value) func(arg ProxyArg) []reflect.Value {
return func(arg ProxyArg) []reflect.Value {
if len(arg.Args) <= 0 {
t.Fatal("AopProxy() args len = 0")
}
if len(arg.TagArgs) <= 0 {
t.Fatal("AopProxy() tagArgs len = 0")
}
var e error
var returns = make([]reflect.Value, 0)
returns = append(returns, reflect.ValueOf("yes return string="+arg.Args[0].Interface().(string)))
returns = append(returns, reflect.Zero(reflect.TypeOf(&e).Elem()))
return returns
}
})
var result, e = test.SelectByIds("1234")
fmt.Println(result, e)
if e != nil {
t.Fatal(e)
}
}
func TestUseMapper(t *testing.T) {
var test = TestMapper{}
Proxy(&test, func(funcField reflect.StructField, field reflect.Value) func(arg ProxyArg) []reflect.Value {
return func(arg ProxyArg) []reflect.Value {
if len(arg.Args) <= 0 {
t.Fatal("AopProxy() args len = 0")
}
if len(arg.TagArgs) <= 0 {
t.Fatal("AopProxy() tagArgs len = 0")
}
var e error
var returns = make([]reflect.Value, 0)
returns = append(returns, reflect.ValueOf("yes return string="+arg.Args[0].Interface().(string)))
returns = append(returns, reflect.Zero(reflect.TypeOf(&e).Elem()))
return returns
}
})
var result, e = test.SelectByIds("1234")
fmt.Println(result, e)
if e != nil {
t.Fatal(e)
}
}