(t *testing.T)
| 54 | } |
| 55 | |
| 56 | func TestStripSlashesInRoute(t *testing.T) { |
| 57 | r := chi.NewRouter() |
| 58 | |
| 59 | r.NotFound(func(w http.ResponseWriter, r *http.Request) { |
| 60 | w.WriteHeader(404) |
| 61 | w.Write([]byte("nothing here")) |
| 62 | }) |
| 63 | |
| 64 | r.Get("/hi", func(w http.ResponseWriter, r *http.Request) { |
| 65 | w.Write([]byte("hi")) |
| 66 | }) |
| 67 | |
| 68 | r.Route("/accounts/{accountID}", func(r chi.Router) { |
| 69 | r.Use(StripSlashes) |
| 70 | r.Get("/", func(w http.ResponseWriter, r *http.Request) { |
| 71 | w.Write([]byte("accounts index")) |
| 72 | }) |
| 73 | r.Get("/query", func(w http.ResponseWriter, r *http.Request) { |
| 74 | accountID := chi.URLParam(r, "accountID") |
| 75 | w.Write([]byte(accountID)) |
| 76 | }) |
| 77 | }) |
| 78 | |
| 79 | ts := httptest.NewServer(r) |
| 80 | defer ts.Close() |
| 81 | |
| 82 | if _, resp := testRequest(t, ts, "GET", "/hi", nil); resp != "hi" { |
| 83 | t.Fatal(resp) |
| 84 | } |
| 85 | if _, resp := testRequest(t, ts, "GET", "/hi/", nil); resp != "nothing here" { |
| 86 | t.Fatal(resp) |
| 87 | } |
| 88 | if _, resp := testRequest(t, ts, "GET", "/accounts/admin", nil); resp != "accounts index" { |
| 89 | t.Fatal(resp) |
| 90 | } |
| 91 | if _, resp := testRequest(t, ts, "GET", "/accounts/admin/", nil); resp != "accounts index" { |
| 92 | t.Fatal(resp) |
| 93 | } |
| 94 | if _, resp := testRequest(t, ts, "GET", "/accounts/admin/query", nil); resp != "admin" { |
| 95 | t.Fatal(resp) |
| 96 | } |
| 97 | if _, resp := testRequest(t, ts, "GET", "/accounts/admin/query/", nil); resp != "admin" { |
| 98 | t.Fatal(resp) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | func TestRedirectSlashes(t *testing.T) { |
| 103 | r := chi.NewRouter() |
nothing calls this directly
no test coverage detected