beego:add post test case
Showing
1 changed file
with
16 additions
and
0 deletions
| ... | @@ -15,6 +15,10 @@ func (this *TestController) Get() { | ... | @@ -15,6 +15,10 @@ func (this *TestController) Get() { |
| 15 | this.Ctx.Output.Body([]byte("ok")) | 15 | this.Ctx.Output.Body([]byte("ok")) |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | func (this *TestController) Post() { | ||
| 19 | this.Ctx.Output.Body([]byte(this.Ctx.Input.Query(":name"))) | ||
| 20 | } | ||
| 21 | |||
| 18 | func (this *TestController) List() { | 22 | func (this *TestController) List() { |
| 19 | this.Ctx.Output.Body([]byte("i am list")) | 23 | this.Ctx.Output.Body([]byte("i am list")) |
| 20 | } | 24 | } |
| ... | @@ -81,6 +85,18 @@ func TestUserFunc(t *testing.T) { | ... | @@ -81,6 +85,18 @@ func TestUserFunc(t *testing.T) { |
| 81 | } | 85 | } |
| 82 | } | 86 | } |
| 83 | 87 | ||
| 88 | func TestPostFunc(t *testing.T) { | ||
| 89 | r, _ := http.NewRequest("POST", "/astaxie", nil) | ||
| 90 | w := httptest.NewRecorder() | ||
| 91 | |||
| 92 | handler := NewControllerRegistor() | ||
| 93 | handler.Add("/:name", &TestController{}) | ||
| 94 | handler.ServeHTTP(w, r) | ||
| 95 | if w.Body.String() != "astaxie" { | ||
| 96 | t.Errorf("post func should astaxie") | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 84 | func TestAutoFunc(t *testing.T) { | 100 | func TestAutoFunc(t *testing.T) { |
| 85 | r, _ := http.NewRequest("GET", "/test/list", nil) | 101 | r, _ := http.NewRequest("GET", "/test/list", nil) |
| 86 | w := httptest.NewRecorder() | 102 | w := httptest.NewRecorder() | ... | ... |
-
Please register or sign in to post a comment