func TestHandlerNoPanic(t *testing.T) { mux, err := ctxmux.New( ctxmux.MuxPanicHandler( func(ctx context.Context, w http.ResponseWriter, r *http.Request, v interface{}) { panic("not reached") }), ) ensure.Nil(t, err) hw := httptest.NewRecorder() hr := &http.Request{ Method: "GET", URL: &url.URL{ Path: "/", }, } mux.GET(hr.URL.Path, func(context.Context, http.ResponseWriter, *http.Request) error { return nil }) mux.ServeHTTP(hw, hr) }
func TestHandlerPanic(t *testing.T) { var actualPanic interface{} mux, err := ctxmux.New( ctxmux.MuxPanicHandler( func(ctx context.Context, w http.ResponseWriter, r *http.Request, v interface{}) { actualPanic = v }), ) ensure.Nil(t, err) hw := httptest.NewRecorder() hr := &http.Request{ Method: "GET", URL: &url.URL{ Path: "/", }, } givenPanic := int(42) mux.GET(hr.URL.Path, func(context.Context, http.ResponseWriter, *http.Request) error { panic(givenPanic) }) mux.ServeHTTP(hw, hr) ensure.DeepEqual(t, actualPanic, givenPanic) }