-
Notifications
You must be signed in to change notification settings - Fork 689
/
custom_verb_test.go
62 lines (56 loc) · 1.45 KB
/
custom_verb_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
62
package restful
import "testing"
func TestHasCustomVerb(t *testing.T) {
testCase := []struct {
path string
has bool
}{
{"/{userId}:init", true},
{"/{userId:init}", false},
{"/users/{id:init}:init", true},
{"/users/{id}", false},
}
for _, v := range testCase {
rs := hasCustomVerb(v.path)
if rs != v.has {
t.Errorf("path: %v should has no custom verb", v.path)
}
}
}
func TestRemoveCustomVerb(t *testing.T) {
testCase := []struct {
path string
expectedPath string
}{
{"/{userId}:init", "/{userId}"},
{"/{userId:init}", "/{userId:init}"},
{"/users/{id:init}:init", "/users/{id:init}"},
{"/users/{id}", "/users/{id}"},
{"/init/users/{id:init}:init", "/init/users/{id:init}"},
}
for _, v := range testCase {
rs := removeCustomVerb(v.path)
if rs != v.expectedPath {
t.Errorf("expected value: %v, actual: %v", v.expectedPath, rs)
}
}
}
func TestMatchCustomVerb(t *testing.T) {
testCase := []struct {
routeToken string
pathToken string
expected bool
}{
{"{userId:regex}:init", "creator-123456789gWe:init", true},
{"{userId:regex}:init", "creator-123456789gWe", false},
{"{userId:regex}", "creator-123456789gWe:init", false},
{"users:init", "users:init", true},
{"users:init", "tokens:init", true},
}
for idx, v := range testCase {
rs := isMatchCustomVerb(v.routeToken, v.pathToken)
if rs != v.expected {
t.Errorf("expected value: %v, actual: %v, index: [%v]", v.expected, rs, idx)
}
}
}