mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:30:56 +00:00
This commit is contained in:
parent
54fb49ed95
commit
ff1b8588e0
@ -27,6 +27,25 @@ func (this *TestController) GetUrl() {
|
|||||||
this.Ctx.Output.Body([]byte(this.UrlFor(".Myext")))
|
this.Ctx.Output.Body([]byte(this.UrlFor(".Myext")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ResStatus struct {
|
||||||
|
Code int
|
||||||
|
Msg string
|
||||||
|
}
|
||||||
|
|
||||||
|
type JsonController struct {
|
||||||
|
Controller
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *JsonController) Prepare() {
|
||||||
|
this.Data["json"] = "prepare"
|
||||||
|
this.ServeJson(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *JsonController) Get() {
|
||||||
|
this.Data["Username"] = "astaxie"
|
||||||
|
this.Ctx.Output.Body([]byte("ok"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestUrlFor(t *testing.T) {
|
func TestUrlFor(t *testing.T) {
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegistor()
|
||||||
handler.Add("/api/list", &TestController{}, "*:List")
|
handler.Add("/api/list", &TestController{}, "*:List")
|
||||||
@ -151,3 +170,15 @@ func TestStatic(t *testing.T) {
|
|||||||
t.Errorf("handler.Static failed to serve file")
|
t.Errorf("handler.Static failed to serve file")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrepare(t *testing.T) {
|
||||||
|
r, _ := http.NewRequest("GET", "/json/list", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
|
handler := NewControllerRegistor()
|
||||||
|
handler.Add("/json/list", &JsonController{})
|
||||||
|
handler.ServeHTTP(w, r)
|
||||||
|
if w.Body.String() != `"prepare"` {
|
||||||
|
t.Errorf(w.Body.String() + "user define func can't run")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user