From 1ea449aa3a61129870147b4443b1b62b10a1dc53 Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 10 Apr 2014 22:33:32 +0800 Subject: [PATCH] beego:add post test case --- router_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/router_test.go b/router_test.go index c1a7f213..2f500835 100644 --- a/router_test.go +++ b/router_test.go @@ -15,6 +15,10 @@ func (this *TestController) Get() { this.Ctx.Output.Body([]byte("ok")) } +func (this *TestController) Post() { + this.Ctx.Output.Body([]byte(this.Ctx.Input.Query(":name"))) +} + func (this *TestController) 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) { r, _ := http.NewRequest("GET", "/test/list", nil) w := httptest.NewRecorder()