1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 08:50:56 +00:00
This commit is contained in:
JessonChan 2016-03-25 10:56:15 +08:00
parent 94bde3a777
commit 2db8c753fd
8 changed files with 42 additions and 41 deletions

14
cache/cache_test.go vendored
View File

@ -26,7 +26,7 @@ func TestCache(t *testing.T) {
t.Error("init err")
}
timeoutDuration := 10 * time.Second
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
if err = bm.Put("astaxie", 1, timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie") {
@ -43,7 +43,7 @@ func TestCache(t *testing.T) {
t.Error("check err")
}
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
if err = bm.Put("astaxie", 1, timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
@ -68,7 +68,7 @@ func TestCache(t *testing.T) {
}
//test GetMulti
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
if err = bm.Put("astaxie", "author", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie") {
@ -78,7 +78,7 @@ func TestCache(t *testing.T) {
t.Error("get err")
}
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
if err = bm.Put("astaxie1", "author1", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie1") {
@ -103,7 +103,7 @@ func TestFileCache(t *testing.T) {
t.Error("init err")
}
timeoutDuration := 10 * time.Second
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
if err = bm.Put("astaxie", 1, timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie") {
@ -135,7 +135,7 @@ func TestFileCache(t *testing.T) {
}
//test string
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
if err = bm.Put("astaxie", "author", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie") {
@ -146,7 +146,7 @@ func TestFileCache(t *testing.T) {
}
//test GetMulti
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
if err = bm.Put("astaxie1", "author1", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie1") {

View File

@ -30,7 +30,7 @@ func TestMemcacheCache(t *testing.T) {
t.Error("init err")
}
timeoutDuration := 10 * time.Second
if err = bm.Put("astaxie", "1", timeoutDuration); err != nil {
if err = bm.Put("astaxie", "1", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie") {
@ -42,7 +42,7 @@ func TestMemcacheCache(t *testing.T) {
if bm.IsExist("astaxie") {
t.Error("check err")
}
if err = bm.Put("astaxie", "1", timeoutDuration); err != nil {
if err = bm.Put("astaxie", "1", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
@ -71,7 +71,7 @@ func TestMemcacheCache(t *testing.T) {
}
//test string
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
if err = bm.Put("astaxie", "author", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie") {
@ -83,7 +83,7 @@ func TestMemcacheCache(t *testing.T) {
}
//test GetMulti
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
if err = bm.Put("astaxie1", "author1", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie1") {

View File

@ -29,7 +29,7 @@ func TestRedisCache(t *testing.T) {
t.Error("init err")
}
timeoutDuration := 10 * time.Second
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
if err = bm.Put("astaxie", 1, timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie") {
@ -41,7 +41,7 @@ func TestRedisCache(t *testing.T) {
if bm.IsExist("astaxie") {
t.Error("check err")
}
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
if err = bm.Put("astaxie", 1, timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
@ -70,7 +70,7 @@ func TestRedisCache(t *testing.T) {
}
//test string
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
if err = bm.Put("astaxie", "author", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie") {
@ -82,7 +82,7 @@ func TestRedisCache(t *testing.T) {
}
//test GetMulti
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
if err = bm.Put("astaxie1", "author1", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie1") {

View File

@ -19,7 +19,7 @@ func TestSsdbcacheCache(t *testing.T) {
}
timeoutDuration := 10 * time.Second
//timeoutDuration := -10*time.Second if timeoutDuration is negtive,it means permanent
if err = ssdb.Put("ssdb", "ssdb", timeoutDuration); err != nil {
if err = ssdb.Put("ssdb", "ssdb", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if !ssdb.IsExist("ssdb") {
@ -27,7 +27,7 @@ func TestSsdbcacheCache(t *testing.T) {
}
// Get test done
if err = ssdb.Put("ssdb", "ssdb", timeoutDuration); err != nil {
if err = ssdb.Put("ssdb", "ssdb", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
@ -36,7 +36,7 @@ func TestSsdbcacheCache(t *testing.T) {
}
//inc/dec test done
if err = ssdb.Put("ssdb", "2", timeoutDuration); err != nil {
if err = ssdb.Put("ssdb", "2", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if err = ssdb.Incr("ssdb"); err != nil {
@ -52,7 +52,7 @@ func TestSsdbcacheCache(t *testing.T) {
}
// test del
if err = ssdb.Put("ssdb", "3", timeoutDuration); err != nil {
if err = ssdb.Put("ssdb", "3", timeoutDuration*time.Second); err != nil {
t.Error("set Error", err)
}
if v, err := strconv.Atoi(ssdb.Get("ssdb").(string)); err != nil || v != 3 {

View File

@ -100,7 +100,7 @@ func TestSubDomain(t *testing.T) {
/* TODO Fix this
r, _ = http.NewRequest("GET", "http://127.0.0.1/", nil)
beegoInput.Request = r
beegoInput.Context.Request = r
if beegoInput.SubDomains() != "" {
t.Fatal("Subdomain parse error, got " + beegoInput.SubDomains())
}

View File

@ -33,7 +33,7 @@ import (
"strings"
"time"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
)
@ -90,7 +90,7 @@ func (m *Migration) Reset() {
func (m *Migration) Exec(name, status string) error {
o := orm.NewOrm()
for _, s := range m.sqls {
beego.Info("exec sql:", s)
logs.Info("exec sql:", s)
r := o.Raw(s)
_, err := r.Exec()
if err != nil {
@ -144,20 +144,20 @@ func Upgrade(lasttime int64) error {
i := 0
for _, v := range sm {
if v.created > lasttime {
beego.Info("start upgrade", v.name)
logs.Info("start upgrade", v.name)
v.m.Reset()
v.m.Up()
err := v.m.Exec(v.name, "up")
if err != nil {
beego.Error("execute error:", err)
logs.Error("execute error:", err)
time.Sleep(2 * time.Second)
return err
}
beego.Info("end upgrade:", v.name)
logs.Info("end upgrade:", v.name)
i++
}
}
beego.Info("total success upgrade:", i, " migration")
logs.Info("total success upgrade:", i, " migration")
time.Sleep(2 * time.Second)
return nil
}
@ -165,20 +165,20 @@ func Upgrade(lasttime int64) error {
// Rollback rollback the migration by the name
func Rollback(name string) error {
if v, ok := migrationMap[name]; ok {
beego.Info("start rollback")
logs.Info("start rollback")
v.Reset()
v.Down()
err := v.Exec(name, "down")
if err != nil {
beego.Error("execute error:", err)
logs.Error("execute error:", err)
time.Sleep(2 * time.Second)
return err
}
beego.Info("end rollback")
logs.Info("end rollback")
time.Sleep(2 * time.Second)
return nil
}
beego.Error("not exist the migrationMap name:" + name)
logs.Error("not exist the migrationMap name:" + name)
time.Sleep(2 * time.Second)
return errors.New("not exist the migrationMap name:" + name)
}
@ -191,23 +191,23 @@ func Reset() error {
for j := len(sm) - 1; j >= 0; j-- {
v := sm[j]
if isRollBack(v.name) {
beego.Info("skip the", v.name)
logs.Info("skip the", v.name)
time.Sleep(1 * time.Second)
continue
}
beego.Info("start reset:", v.name)
logs.Info("start reset:", v.name)
v.m.Reset()
v.m.Down()
err := v.m.Exec(v.name, "down")
if err != nil {
beego.Error("execute error:", err)
logs.Error("execute error:", err)
time.Sleep(2 * time.Second)
return err
}
i++
beego.Info("end reset:", v.name)
logs.Info("end reset:", v.name)
}
beego.Info("total success reset:", i, " migration")
logs.Info("total success reset:", i, " migration")
time.Sleep(2 * time.Second)
return nil
}
@ -216,7 +216,7 @@ func Reset() error {
func Refresh() error {
err := Reset()
if err != nil {
beego.Error("execute error:", err)
logs.Error("execute error:", err)
time.Sleep(2 * time.Second)
return err
}
@ -265,7 +265,7 @@ func isRollBack(name string) bool {
var maps []orm.Params
num, err := o.Raw("select * from migrations where `name` = ? order by id_migration desc", name).Values(&maps)
if err != nil {
beego.Info("get name has error", err)
logs.Info("get name has error", err)
return false
}
if num <= 0 {

View File

@ -69,6 +69,7 @@ import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/cache"
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/utils"
)
@ -139,7 +140,7 @@ func (c *Captcha) Handler(ctx *context.Context) {
if err := c.store.Put(key, chars, c.Expiration); err != nil {
ctx.Output.SetStatus(500)
ctx.WriteString("captcha reload error")
beego.Error("Reload Create Captcha Error:", err)
logs.Error("Reload Create Captcha Error:", err)
return
}
} else {
@ -154,7 +155,7 @@ func (c *Captcha) Handler(ctx *context.Context) {
img := NewImage(chars, c.StdWidth, c.StdHeight)
if _, err := img.WriteTo(ctx.ResponseWriter); err != nil {
beego.Error("Write Captcha Image Error:", err)
logs.Error("Write Captcha Image Error:", err)
}
}
@ -162,7 +163,7 @@ func (c *Captcha) Handler(ctx *context.Context) {
func (c *Captcha) CreateCaptchaHTML() template.HTML {
value, err := c.CreateCaptcha()
if err != nil {
beego.Error("Create Captcha Error:", err)
logs.Error("Create Captcha Error:", err)
return ""
}

View File

@ -18,7 +18,7 @@ import (
"github.com/astaxie/beego/context"
)
// SetPaginator Instantiates a Paginator and assigns it to context.Input.Data["paginator"].
// SetPaginator Instantiates a Paginator and assigns it to context.Input.Data("paginator").
func SetPaginator(context *context.Context, per int, nums int64) (paginator *Paginator) {
paginator = NewPaginator(context.Request, per, nums)
context.Input.SetData("paginator", &paginator)