logger_test.go 616 B

123456789101112131415161718192021222324252627282930
  1. package tango
  2. import (
  3. "testing"
  4. "bytes"
  5. "net/http/httptest"
  6. "net/http"
  7. "github.com/lunny/log"
  8. )
  9. func TestLogger(t *testing.T) {
  10. buff := bytes.NewBufferString("")
  11. recorder := httptest.NewRecorder()
  12. n := NewWithLog(log.New(buff, "[tango] ", 0))
  13. n.Use(Logging())
  14. n.UseHandler(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
  15. rw.WriteHeader(http.StatusNotFound)
  16. }))
  17. req, err := http.NewRequest("GET", "http://localhost:3000/foobar", nil)
  18. if err != nil {
  19. t.Error(err)
  20. }
  21. n.ServeHTTP(recorder, req)
  22. expect(t, recorder.Code, http.StatusNotFound)
  23. refute(t, len(buff.String()), 0)
  24. }