Micro & pluggable web framework for Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
815B

  1. // Copyright 2015 The Tango Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package tango
  5. import (
  6. "bytes"
  7. "net/http"
  8. "net/http/httptest"
  9. "os"
  10. "testing"
  11. )
  12. func TestRecovery(t *testing.T) {
  13. buff := bytes.NewBufferString("")
  14. recorder := httptest.NewRecorder()
  15. recorder.Body = buff
  16. n := NewWithLog(NewLogger(os.Stdout))
  17. n.Use(Recovery(true))
  18. n.UseHandler(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
  19. panic("here is a panic!")
  20. }))
  21. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  22. if err != nil {
  23. t.Error(err)
  24. }
  25. n.ServeHTTP(recorder, req)
  26. expect(t, recorder.Code, http.StatusInternalServerError)
  27. refute(t, recorder.Body.Len(), 0)
  28. refute(t, len(buff.String()), 0)
  29. }