This tests a http.Handler that is not chi.Router In these cases, the routeContext is nil
(t *testing.T)
| 201 | // This tests a http.Handler that is not chi.Router |
| 202 | // In these cases, the routeContext is nil |
| 203 | func TestStripSlashesWithNilContext(t *testing.T) { |
| 204 | r := http.NewServeMux() |
| 205 | |
| 206 | r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 207 | w.Write([]byte("root")) |
| 208 | }) |
| 209 | |
| 210 | r.HandleFunc("/accounts", func(w http.ResponseWriter, r *http.Request) { |
| 211 | w.Write([]byte("accounts")) |
| 212 | }) |
| 213 | |
| 214 | r.HandleFunc("/accounts/admin", func(w http.ResponseWriter, r *http.Request) { |
| 215 | w.Write([]byte("admin")) |
| 216 | }) |
| 217 | |
| 218 | ts := httptest.NewServer(StripSlashes(r)) |
| 219 | defer ts.Close() |
| 220 | |
| 221 | if _, resp := testRequest(t, ts, "GET", "/", nil); resp != "root" { |
| 222 | t.Fatal(resp) |
| 223 | } |
| 224 | if _, resp := testRequest(t, ts, "GET", "//", nil); resp != "root" { |
| 225 | t.Fatal(resp) |
| 226 | } |
| 227 | if _, resp := testRequest(t, ts, "GET", "/accounts", nil); resp != "accounts" { |
| 228 | t.Fatal(resp) |
| 229 | } |
| 230 | if _, resp := testRequest(t, ts, "GET", "/accounts/", nil); resp != "accounts" { |
| 231 | t.Fatal(resp) |
| 232 | } |
| 233 | if _, resp := testRequest(t, ts, "GET", "/accounts/admin", nil); resp != "admin" { |
| 234 | t.Fatal(resp) |
| 235 | } |
| 236 | if _, resp := testRequest(t, ts, "GET", "/accounts/admin/", nil); resp != "admin" { |
| 237 | t.Fatal(resp) |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | func TestStripPrefix(t *testing.T) { |
| 242 | r := chi.NewRouter() |
nothing calls this directly
no test coverage detected