Browse Source

Add more tests about any (#64)

tags/v0.6.2
Lunny Xiao 1 month ago
parent
commit
af459469e0
1 changed files with 39 additions and 0 deletions
  1. +39
    -0
      router_test.go

+ 39
- 0
router_test.go View File

@@ -802,3 +802,42 @@ func TestRouter10(t *testing.T) {
expect(t, buff.String(), "test")
refute(t, len(buff.String()), 0)
}

type Route11Action struct {
}

func (Route11Action) Any() string {
return "any"
}

func TestRouter11(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff

r := Classic()
r.Get("/", new(Route11Action))
r.Post("/2", new(Route11Action))

req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}

r.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
expect(t, buff.String(), "any")
refute(t, len(buff.String()), 0)

buff.Reset()

req, err = http.NewRequest("POST", "http://localhost:8000/2", nil)
if err != nil {
t.Error(err)
}

r.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
expect(t, buff.String(), "any")
refute(t, len(buff.String()), 0)
}

Loading…
Cancel
Save