ff1b8588 by astaxie

#313

1 parent 54fb49ed
...@@ -27,6 +27,25 @@ func (this *TestController) GetUrl() { ...@@ -27,6 +27,25 @@ func (this *TestController) GetUrl() {
27 this.Ctx.Output.Body([]byte(this.UrlFor(".Myext"))) 27 this.Ctx.Output.Body([]byte(this.UrlFor(".Myext")))
28 } 28 }
29 29
30 type ResStatus struct {
31 Code int
32 Msg string
33 }
34
35 type JsonController struct {
36 Controller
37 }
38
39 func (this *JsonController) Prepare() {
40 this.Data["json"] = "prepare"
41 this.ServeJson(true)
42 }
43
44 func (this *JsonController) Get() {
45 this.Data["Username"] = "astaxie"
46 this.Ctx.Output.Body([]byte("ok"))
47 }
48
30 func TestUrlFor(t *testing.T) { 49 func TestUrlFor(t *testing.T) {
31 handler := NewControllerRegistor() 50 handler := NewControllerRegistor()
32 handler.Add("/api/list", &TestController{}, "*:List") 51 handler.Add("/api/list", &TestController{}, "*:List")
...@@ -151,3 +170,15 @@ func TestStatic(t *testing.T) { ...@@ -151,3 +170,15 @@ func TestStatic(t *testing.T) {
151 t.Errorf("handler.Static failed to serve file") 170 t.Errorf("handler.Static failed to serve file")
152 } 171 }
153 } 172 }
173
174 func TestPrepare(t *testing.T) {
175 r, _ := http.NewRequest("GET", "/json/list", nil)
176 w := httptest.NewRecorder()
177
178 handler := NewControllerRegistor()
179 handler.Add("/json/list", &JsonController{})
180 handler.ServeHTTP(w, r)
181 if w.Body.String() != `"prepare"` {
182 t.Errorf(w.Body.String() + "user define func can't run")
183 }
184 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!