-
Notifications
You must be signed in to change notification settings - Fork 7
/
router_test.go
47 lines (43 loc) · 886 Bytes
/
router_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
package router
import "testing"
func TestRouter(t *testing.T) {
usersPath := "/users"
tt := []struct {
name string
route *Route
match string
expected bool
}{
{
"exact match positiive",
NewRoute(usersPath, nil, NewRouteOpts{ExactMatch: true}),
"/users",
true,
},
{
"exact match negative",
NewRoute(usersPath, nil, NewRouteOpts{ExactMatch: true}),
"/users/1",
false,
},
{
"loose match exact",
NewRoute(usersPath, nil, NewRouteOpts{ExactMatch: false}),
"/users",
true,
},
{
"loose match loose",
NewRoute(usersPath, nil, NewRouteOpts{ExactMatch: false}),
"/users/1",
true,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
if tc.route.p.MatchString(tc.match) != tc.expected {
t.Errorf("expected %v to have a %v match for %v", usersPath, tc.expected, tc.match)
}
})
}
}