func TestRecoveryJson(t *testing.T) { buff := bytes.NewBufferString("") recorder := httptest.NewRecorder() recServer := &recoveryServer{} rec := NewRecoveryJson(log.New(buff, "[recoveryjson] ", 0), recServer) n := negroni.New() // replace log for testing n.Use(rec) n.UseHandler(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { panic(`some error`) })) n.ServeHTTP(recorder, (*http.Request)(nil)) util.Expect(t, recorder.Code, http.StatusInternalServerError) util.Refute(t, recorder.Body.Len(), 0) util.Refute(t, len(buff.String()), 0) util.Refute(t, len(recServer.Msgs), 0) }
func TestErrorWrapInternalError(t *testing.T) { recorder := httptest.NewRecorder() raven := &wrapServer{} wrap := NewErrorWrap(raven) router := httprouter.New() handler := negroni.New(negroni.Wrap(router)) router.GET("/hello-internal-error", wrap.Do(testHelloInternalError)) req, _ := http.NewRequest("GET", "/hello-internal-error", nil) handler.ServeHTTP(recorder, req) util.Expect(t, recorder.Code, http.StatusInternalServerError) util.Expect(t, strings.TrimSpace(recorder.Body.String()), `{"error":"Database error","error_code":"error-select"}`) util.Refute(t, len(raven.Msgs), 0) }