29 lines
604 B
Go
29 lines
604 B
Go
|
package negroni
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
"net/http/httptest"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestRecovery(t *testing.T) {
|
||
|
buff := bytes.NewBufferString("")
|
||
|
recorder := httptest.NewRecorder()
|
||
|
|
||
|
rec := NewRecovery()
|
||
|
rec.Logger = log.New(buff, "[negroni] ", 0)
|
||
|
|
||
|
n := New()
|
||
|
// replace log for testing
|
||
|
n.Use(rec)
|
||
|
n.UseHandler(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||
|
panic("here is a panic!")
|
||
|
}))
|
||
|
n.ServeHTTP(recorder, (*http.Request)(nil))
|
||
|
expect(t, recorder.Code, http.StatusInternalServerError)
|
||
|
refute(t, recorder.Body.Len(), 0)
|
||
|
refute(t, len(buff.String()), 0)
|
||
|
}
|