123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package tango
- import (
- "testing"
- "bytes"
- "net/http/httptest"
- "net/http"
- )
- type ParamAction struct {
- Params
- }
- func (p *ParamAction) Get() string {
- return p.Params.Get(":name")
- }
- func TestParams1(t *testing.T) {
- buff := bytes.NewBufferString("")
- recorder := httptest.NewRecorder()
- recorder.Body = buff
- o := Classic()
- o.Get("/:name", new(ParamAction))
- req, err := http.NewRequest("GET", "http://localhost:8000/foobar", nil)
- if err != nil {
- t.Error(err)
- }
- o.ServeHTTP(recorder, req)
- expect(t, recorder.Code, http.StatusOK)
- refute(t, len(buff.String()), 0)
- expect(t, buff.String(), "foobar")
- }
- type Param2Action struct {
- Params
- }
- func (p *Param2Action) Get() string {
- return p.Params.Get(":0")
- }
- func TestParams2(t *testing.T) {
- buff := bytes.NewBufferString("")
- recorder := httptest.NewRecorder()
- recorder.Body = buff
- o := Classic()
- o.Get("/(.*)", new(Param2Action))
- req, err := http.NewRequest("GET", "http://localhost:8000/foobar", nil)
- if err != nil {
- t.Error(err)
- }
- o.ServeHTTP(recorder, req)
- expect(t, recorder.Code, http.StatusOK)
- refute(t, len(buff.String()), 0)
- expect(t, buff.String(), "foobar")
- }
|