Skip to content

Commit

Permalink
Add test for go-chi#426
Browse files Browse the repository at this point in the history
  • Loading branch information
moorereason committed Dec 21, 2019
1 parent 7fb3452 commit 38fb2bc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func TestMuxBasic(t *testing.T) {
w.Write([]byte("woop." + URLParam(r, "iidd")))
}

pingPoop := func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("poop." + URLParam(r, "id")))
}

catchAll := func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("catchall"))
Expand All @@ -114,6 +119,7 @@ func TestMuxBasic(t *testing.T) {
m.Get("/ping/{id}", pingWoop)
m.Get("/ping/{id}", pingOne) // expected to overwrite to pingOne handler
m.Get("/ping/{iidd}/woop", pingWoop)
m.Get("/ping/{id:(\\w+)}/poop", pingPoop)
m.HandleFunc("/admin/*", catchAll)
// m.Post("/admin/*", catchAll)

Expand Down Expand Up @@ -164,6 +170,12 @@ func TestMuxBasic(t *testing.T) {
t.Fatalf(body)
}

// GET /ping//poop
// Issue 426
if _, body := testRequest(t, ts, "GET", "/ping//poop", nil); body != "poop." {
t.Fatalf(body)
}

// HEAD /ping
resp, err := http.Head(ts.URL + "/ping")
if err != nil {
Expand Down Expand Up @@ -1110,7 +1122,6 @@ func TestMuxSubroutes(t *testing.T) {
if routePatterns[2] != expected {
t.Fatalf("routePattern, expected:%s got:%s", expected, routePatterns[2])
}

}

func TestSingleHandler(t *testing.T) {
Expand Down Expand Up @@ -1254,7 +1265,6 @@ func TestNestedGroups(t *testing.T) {
r.Get("/5", handlerPrintCounter)
// r.Handle(GET, "/6", Chain(mwIncreaseCounter).HandlerFunc(handlerPrintCounter))
r.With(mwIncreaseCounter).Get("/6", handlerPrintCounter)

})
})
})
Expand Down

0 comments on commit 38fb2bc

Please sign in to comment.