response_test.go 616 B

123456789101112131415161718192021222324252627282930313233343536
  1. package tango
  2. import (
  3. "bytes"
  4. "net/http"
  5. "net/http/httptest"
  6. "testing"
  7. )
  8. type MyResponse struct {
  9. Resp
  10. }
  11. func (m MyResponse) Get() {
  12. m.ResponseWriter.Write([]byte("my response"))
  13. }
  14. func TestResponse(t *testing.T) {
  15. buff := bytes.NewBufferString("")
  16. recorder := httptest.NewRecorder()
  17. recorder.Body = buff
  18. o := Classic()
  19. o.Get("/", new(MyResponse))
  20. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  21. if err != nil {
  22. t.Error(err)
  23. }
  24. o.ServeHTTP(recorder, req)
  25. expect(t, recorder.Code, http.StatusOK)
  26. refute(t, len(buff.String()), 0)
  27. expect(t, buff.String(), "my response")
  28. }