1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 03:50:54 +00:00

beego:add post test case

This commit is contained in:
astaxie 2014-04-10 22:33:32 +08:00
parent 54b92e9599
commit 05e5baaa9f

View File

@ -15,6 +15,10 @@ func (this *TestController) Get() {
this.Ctx.Output.Body([]byte("ok")) this.Ctx.Output.Body([]byte("ok"))
} }
func (this *TestController) Post() {
this.Ctx.Output.Body([]byte(this.Ctx.Input.Query(":name")))
}
func (this *TestController) List() { func (this *TestController) List() {
this.Ctx.Output.Body([]byte("i am list")) this.Ctx.Output.Body([]byte("i am list"))
} }
@ -81,6 +85,18 @@ func TestUserFunc(t *testing.T) {
} }
} }
func TestPostFunc(t *testing.T) {
r, _ := http.NewRequest("POST", "/astaxie", nil)
w := httptest.NewRecorder()
handler := NewControllerRegistor()
handler.Add("/:name", &TestController{})
handler.ServeHTTP(w, r)
if w.Body.String() != "astaxie" {
t.Errorf("post func should astaxie")
}
}
func TestAutoFunc(t *testing.T) { func TestAutoFunc(t *testing.T) {
r, _ := http.NewRequest("GET", "/test/list", nil) r, _ := http.NewRequest("GET", "/test/list", nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()