1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 20:30:49 +00:00
Beego/fiter_test.go
2013-11-26 16:47:50 +08:00

25 lines
638 B
Go

package beego
import (
"github.com/astaxie/beego/context"
"net/http"
"net/http/httptest"
"testing"
)
var FilterUser = func(ctx *context.Context) {
ctx.Output.Body([]byte("i am " + ctx.Input.Params[":last"] + ctx.Input.Params[":first"]))
}
func TestFilter(t *testing.T) {
r, _ := http.NewRequest("GET", "/person/asta/Xie", nil)
w := httptest.NewRecorder()
handler := NewControllerRegistor()
handler.AddFilter("/person/:last/:first", "AfterStatic", FilterUser)
handler.Add("/person/:last/:first", &TestController{})
handler.ServeHTTP(w, r)
if w.Body.String() != "i am astaXie" {
t.Errorf("user define func can't run")
}
}