-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataGenerate_test.go
55 lines (52 loc) · 1.15 KB
/
dataGenerate_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
package tool
import (
"fmt"
"reflect"
"testing"
)
type user struct {
role
Name string `json:"name" comment:"用户名称"`
// Role *role `json:"role" comment:"角色信息"`
// Role role `json:"role" comment:"角色信息"`
// Role []role `json:"role" comment:"角色信息"`
// Role []*role `json:"role" comment:"角色信息"`
// Role *[]role `json:"role" comment:"角色信息"`
Role interface{} `json:"role" comment:"角色信息"`
}
type role struct {
Age int `json:"age" comment:"年龄"`
}
func TestDataGenerate(t *testing.T) {
ds := []data{}
u1 := &user{}
u1.Role = &[]role{}
u2 := user{}
u3 := []user{}
u4 := []*user{}
u5 := &[]user{}
ds = append(ds, data{
Type: reflect.TypeOf(u1),
Value: reflect.ValueOf(u1),
})
ds = append(ds, data{
Type: reflect.TypeOf(u2),
Value: reflect.ValueOf(u2),
})
ds = append(ds, data{
Type: reflect.TypeOf(u3),
Value: reflect.ValueOf(u3),
})
ds = append(ds, data{
Type: reflect.TypeOf(u4),
Value: reflect.ValueOf(u4),
})
ds = append(ds, data{
Type: reflect.TypeOf(u5),
Value: reflect.ValueOf(u5),
})
for i, d := range ds {
fmt.Println(i)
fmt.Println(DataGenerate(2, d))
}
}