clair/vendor/github.com/codegangsta/negroni/logger_test.go
2016-06-07 10:08:50 +02:00

34 lines
649 B
Go

package negroni
import (
"bytes"
"log"
"net/http"
"net/http/httptest"
"testing"
)
func Test_Logger(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
l := NewLogger()
l.Logger = log.New(buff, "[negroni] ", 0)
n := New()
// replace log for testing
n.Use(l)
n.UseHandler(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
rw.WriteHeader(http.StatusNotFound)
}))
req, err := http.NewRequest("GET", "http://localhost:3000/foobar", nil)
if err != nil {
t.Error(err)
}
n.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusNotFound)
refute(t, len(buff.String()), 0)
}