-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler_test.go
41 lines (33 loc) · 961 Bytes
/
handler_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
package muxter
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestStdAdaptor(t *testing.T) {
mux := New()
mux.StandardHandle(
"/country/:country/city/:city",
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
p := Params(r)
if len(p) != 2 {
t.Errorf("expected params to have length 2 but got: %d", len(p))
}
expected := "ca"
if actual := Param(r, "country"); actual != expected {
t.Errorf("expected country to be %q but got %q", expected, actual)
}
expected = "mtl"
if actual := Param(r, "city"); actual != expected {
t.Errorf("expected city to be %q but got %q", expected, actual)
}
expected = "/country/:country/city/:city"
if actual := Pattern(r); actual != expected {
t.Errorf("expected matched path to be %q but got %q", expected, actual)
}
}),
)
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/country/ca/city/mtl", nil)
mux.ServeHTTP(w, r)
}