-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_field_test.go
37 lines (33 loc) · 1.01 KB
/
handler_field_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
package rip
import "testing"
func TestGetEntityField(t *testing.T) {
cases := []struct {
path string
entityPath string
wantEntityID string
wantField string
}{
{"/ent/1", "/ent", "1", ""},
{"/ent/1/", "/ent", "1", ""},
{"/ent/1/name", "/ent", "1", "name"},
{"/users/123/addresses/2", "/users/123/addresses", "2", ""},
{"/users/123/addresses/2/", "/users/123/addresses", "2", ""},
{"/users/123/addresses/2/city", "/users/123/addresses", "2", "city"},
{"/ent///1", "/ent", "1", ""},
{"/ent///1", "/ent//", "1", ""},
{"/ent/1///", "/ent", "1", ""},
{"/ent/1////name", "/ent", "1", "name"},
{"/ent///1////name//", "/ent", "1", "name"},
}
for _, c := range cases {
t.Run(c.path, func(t *testing.T) {
gotEnt, gotField := getEntityField(c.entityPath, c.path)
if gotEnt != c.wantEntityID {
t.Errorf("wrong entity path:\nwant=%s, got=%s", c.wantEntityID, gotEnt)
}
if gotField != c.wantField {
t.Errorf("wrong field:\nwant=%s, got=%s", c.wantField, gotField)
}
})
}
}