-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspecial_test.go
69 lines (59 loc) · 1.51 KB
/
special_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
63
64
65
66
67
68
69
package nchi_test
import (
"fmt"
"net/http"
"testing"
"github.com/muir/nchi"
)
func TestGlobalOPTIONS(t *testing.T) {
mux := nchi.NewRouter()
mux.Use("")
mux.Use(makeDown("a"))
mux.Options("/go1", makeDown("b"), bottom)
mux.GlobalOPTIONS(makeDown("c"), bottom)
mux.Get("/go2", makeDown("d"), bottom)
doTestMethod(t, mux, "OPTIONS", []testCase{
{path: "/go1", want: "ab"},
{path: "/go2", want: "ac"},
{path: "/go3", want: "404 page not found\n"},
})
}
func TestNotFound(t *testing.T) {
mux := nchi.NewRouter()
mux.Use("")
mux.Use(makeDown("a"))
mux.Get("/nf1", makeDown("b"), bottom)
mux.NotFound(makeDown("c"), bottom)
doTest(t, mux, []testCase{
{path: "/nf1", want: "ab"},
{path: "/nf2", want: "ac"},
})
}
func TestMethodNotAllowed(t *testing.T) {
mux := nchi.NewRouter()
mux.Use("")
mux.Use(makeDown("a"))
mux.Post("/mna1", makeDown("b"), bottom)
mux.MethodNotAllowed(makeDown("c"), bottom)
doTest(t, mux, []testCase{
{path: "/mna1", want: "ac"},
{path: "/mna2", want: "404 page not found\n"},
})
}
func TestPanicHandler(t *testing.T) {
mux := nchi.NewRouter()
mux.Use("")
mux.Use(makeUp1("a"))
mux.Get("/ph2", func(w http.ResponseWriter) {
x := make([]int, 3)
_, _ = w.Write([]byte(fmt.Sprint(x[5])))
})
mux.PanicHandler(func(w http.ResponseWriter, r nchi.RecoverInterface) {
_, _ = w.Write([]byte(fmt.Sprintf("recover %T-", r)))
})
mux.Get("/ph1", bottom)
doTest(t, mux, []testCase{
{path: "/ph1", want: "a"},
{path: "/ph2", want: "recover runtime.boundsError-a"},
})
}