request_test.go 600 B

123456789101112131415161718192021222324252627282930313233343536
  1. package tango
  2. import (
  3. "testing"
  4. "bytes"
  5. "net/http/httptest"
  6. "net/http"
  7. )
  8. type ReqAction struct {
  9. Req
  10. }
  11. func (p *ReqAction) Get() string {
  12. return p.Request.FormValue("id")
  13. }
  14. func TestRequest(t *testing.T) {
  15. buff := bytes.NewBufferString("")
  16. recorder := httptest.NewRecorder()
  17. recorder.Body = buff
  18. o := Classic()
  19. o.Get("/", new(ReqAction))
  20. req, err := http.NewRequest("GET", "http://localhost:8000/?id=1", 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(), "1")
  28. }