-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute_test.go
More file actions
78 lines (67 loc) · 1.59 KB
/
route_test.go
File metadata and controls
78 lines (67 loc) · 1.59 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package dispatch
import (
"net/http"
"testing"
)
var methods = []string{
http.MethodGet,
http.MethodHead,
http.MethodPost,
http.MethodPut,
http.MethodPatch,
http.MethodDelete,
http.MethodConnect,
http.MethodOptions,
http.MethodTrace,
}
var pkgMethods = []HTTPMethod{
MethodGet,
MethodHead,
MethodPost,
MethodPut,
MethodPatch,
MethodDelete,
MethodConnect,
MethodOptions,
MethodTrace,
}
func TestRoute(t *testing.T) {
mt := new(middlewareTest)
mux := New()
mux.middleware = append(mux.middleware, fakeMiddleware(mt))
route := newRoute("/", fakeHandlerFunc(), mux)
if !mt.wrapped {
t.Fatal("middleware is not applied")
}
for _, method := range methods {
if !route.isAcceptMethod(method) {
t.Fatalf("default should be accept all methods but %s not accept", method)
}
}
expected := MethodPost | MethodPut
route.Methods(expected)
if route.method != expected {
t.Fatalf("accept methods is not update: expected %v, actual %v", expected, route.method)
}
for _, method := range methods {
if method == http.MethodPost || method == http.MethodPut {
continue
}
if route.isAcceptMethod(method) {
t.Fatalf("%s match to (MethodPost | MethodPut)", method)
}
}
}
func TestParseMethod(t *testing.T) {
for i := 0; i < len(methods); i++ {
actual := parseMethod(methods[i])
if actual != pkgMethods[i] {
t.Fatalf("parseMethod(%s): expected %v, actual %v", methods[i], pkgMethods[i], actual)
}
}
expected := MethodUnknown
actual := parseMethod("UNKNOWN")
if expected != actual {
t.Fatalf("parseMethod(\"UNKNOWN\"): expected %v, actual %v", expected, actual)
}
}