| 448 | } |
| 449 | |
| 450 | func TestRouterPanicHandler(t *testing.T) { |
| 451 | router := New() |
| 452 | panicHandled := false |
| 453 | |
| 454 | router.PanicHandler = func(rw http.ResponseWriter, r *http.Request, p interface{}) { |
| 455 | panicHandled = true |
| 456 | } |
| 457 | |
| 458 | router.Handle(http.MethodPut, "/user/:name", func(_ http.ResponseWriter, _ *http.Request, _ Params) { |
| 459 | panic("oops!") |
| 460 | }) |
| 461 | |
| 462 | w := new(mockResponseWriter) |
| 463 | req, _ := http.NewRequest(http.MethodPut, "/user/gopher", nil) |
| 464 | |
| 465 | defer func() { |
| 466 | if rcv := recover(); rcv != nil { |
| 467 | t.Fatal("handling panic failed") |
| 468 | } |
| 469 | }() |
| 470 | |
| 471 | router.ServeHTTP(w, req) |
| 472 | |
| 473 | if !panicHandled { |
| 474 | t.Fatal("simulating failed") |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | func TestRouterLookup(t *testing.T) { |
| 479 | routed := false |