@@ -10,21 +10,83 @@ import (
10
10
)
11
11
12
12
func TestResourcePathValues (t * testing.T ) {
13
+ index := resource .NewIndex ()
14
+ users := index .Bind ("users" , schema.Schema {
15
+ Fields : schema.Fields {
16
+ "id" : {
17
+ Validator : & schema.String {},
18
+ },
19
+ },
20
+ }, mem .NewHandler (), resource .DefaultConf )
21
+ posts := users .Bind ("posts" , "user" , schema.Schema {
22
+ Fields : schema.Fields {
23
+ "id" : {
24
+ Validator : & schema.Integer {},
25
+ },
26
+ "user" : {
27
+ Validator : & schema.Reference {Path : "users" },
28
+ },
29
+ },
30
+ }, mem .NewHandler (), resource .DefaultConf )
13
31
p := ResourcePath {
14
32
& ResourcePathComponent {
15
- Name : "users" ,
16
- Field : "user" ,
17
- Value : "john" ,
33
+ Name : "users" ,
34
+ Field : "user" ,
35
+ Value : "john" ,
36
+ Resource : users ,
18
37
},
19
38
& ResourcePathComponent {
20
- Name : "posts" ,
21
- Field : "id" ,
22
- Value : "123" ,
39
+ Name : "posts" ,
40
+ Field : "id" ,
41
+ Value : "123" ,
42
+ Resource : posts ,
23
43
},
24
44
}
25
45
assert .Equal (t , map [string ]interface {}{"id" : "123" , "user" : "john" }, p .Values ())
26
46
}
27
47
48
+ func TestResourcePathInvalidValues (t * testing.T ) {
49
+ index := resource .NewIndex ()
50
+ users := index .Bind ("users" , schema.Schema {
51
+ Fields : schema.Fields {
52
+ "id" : {
53
+ Validator : & schema.String {},
54
+ },
55
+ },
56
+ }, mem .NewHandler (), resource .DefaultConf )
57
+ posts := users .Bind ("posts" , "user" , schema.Schema {
58
+ Fields : schema.Fields {
59
+ "id" : {
60
+ Validator : & schema.Integer {},
61
+ },
62
+ "user" : {
63
+ Validator : & schema.Reference {Path : "users" },
64
+ },
65
+ },
66
+ }, mem .NewHandler (), resource .DefaultConf )
67
+ p := ResourcePath {
68
+ & ResourcePathComponent {
69
+ Name : "users" ,
70
+ Field : "user" ,
71
+ Value : "john" ,
72
+ Resource : users ,
73
+ },
74
+ & ResourcePathComponent {
75
+ Name : "posts" ,
76
+ Field : "id" ,
77
+ Value : "123" ,
78
+ Resource : posts ,
79
+ },
80
+ & ResourcePathComponent {
81
+ Name : "users1" ,
82
+ Field : "user1" ,
83
+ Value : "john1" ,
84
+ Resource : posts ,
85
+ },
86
+ }
87
+ assert .Equal (t , map [string ]interface {}{"id" : "123" }, p .Values ())
88
+ }
89
+
28
90
func TestResourcePathAppend (t * testing.T ) {
29
91
index := resource .NewIndex ()
30
92
users := index .Bind ("users" , schema.Schema {
0 commit comments