improved tests

This commit is contained in:
Lunny Xiao 2014-01-16 11:26:24 +08:00
parent e456f59600
commit 84ebac71f3
3 changed files with 59 additions and 3 deletions

View File

@ -269,6 +269,16 @@ func insertTwoTable(engine *Engine, t *testing.T) {
} }
} }
type Article struct {
Id int32 `xorm:"pk INT autoincr`
Name string `xorm:"VARCHAR(45)"`
Img string `xorm:"VARCHAR(100)"`
Aside string `xorm:"VARCHAR(200)"`
Desc string `xorm:"VARCHAR(200)"`
Content string `xorm:"TEXT"`
Status int8 `xorm:"TINYINT(4)"`
}
type Condi map[string]interface{} type Condi map[string]interface{}
func update(engine *Engine, t *testing.T) { func update(engine *Engine, t *testing.T) {
@ -316,6 +326,38 @@ func update(engine *Engine, t *testing.T) {
panic(err) panic(err)
return return
} }
err = engine.Sync(&Article{})
if err != nil {
t.Error(err)
panic(err)
}
cnt, err = engine.Insert(&Article{0, "1", "2", "3", "4", "5", 2})
if err != nil {
t.Error(err)
panic(err)
}
if cnt != 1 {
err = errors.New("insert not returned 1")
t.Error(err)
panic(err)
return
}
cnt, err = engine.Id(1).Update(&Article{Name: "6"})
if err != nil {
t.Error(err)
panic(err)
}
if cnt != 1 {
err = errors.New("update not returned 1")
t.Error(err)
panic(err)
return
}
} }
func updateSameMapper(engine *Engine, t *testing.T) { func updateSameMapper(engine *Engine, t *testing.T) {
@ -353,8 +395,14 @@ func updateSameMapper(engine *Engine, t *testing.T) {
panic(err) panic(err)
} }
if cnt != 1 { total, err := engine.Count(&user)
err = errors.New("update not returned 1") if err != nil {
t.Error(err)
panic(err)
}
if cnt != total {
err = errors.New("insert not returned 1")
t.Error(err) t.Error(err)
panic(err) panic(err)
return return
@ -706,7 +754,7 @@ func orderSameMapper(engine *Engine, t *testing.T) {
func joinSameMapper(engine *Engine, t *testing.T) { func joinSameMapper(engine *Engine, t *testing.T) {
users := make([]Userinfo, 0) users := make([]Userinfo, 0)
err := engine.Join("LEFT", `"Userdetail"`, `"Userinfo"."id"="Userdetail"."Id"`).Find(&users) err := engine.Join("LEFT", "`Userdetail`", "`Userinfo`.`(id)`=`Userdetail`.`(id)`").Find(&users)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
panic(err) panic(err)

View File

@ -31,6 +31,7 @@ func TestMysql(t *testing.T) {
engine.ShowDebug = showTestSql engine.ShowDebug = showTestSql
testAll(engine, t) testAll(engine, t)
testAllSnakeMapper(engine, t)
testAll2(engine, t) testAll2(engine, t)
testAll3(engine, t) testAll3(engine, t)
} }
@ -55,6 +56,7 @@ func TestMysqlSameMapper(t *testing.T) {
engine.SetMapper(SameMapper{}) engine.SetMapper(SameMapper{})
testAll(engine, t) testAll(engine, t)
testAllSameMapper(engine, t)
testAll2(engine, t) testAll2(engine, t)
testAll3(engine, t) testAll3(engine, t)
} }
@ -79,6 +81,7 @@ func TestMysqlWithCache(t *testing.T) {
engine.ShowDebug = showTestSql engine.ShowDebug = showTestSql
testAll(engine, t) testAll(engine, t)
testAllSnakeMapper(engine, t)
testAll2(engine, t) testAll2(engine, t)
} }
@ -103,6 +106,7 @@ func TestMysqlWithCacheSameMapper(t *testing.T) {
engine.ShowDebug = showTestSql engine.ShowDebug = showTestSql
testAll(engine, t) testAll(engine, t)
testAllSameMapper(engine, t)
testAll2(engine, t) testAll2(engine, t)
} }

View File

@ -31,6 +31,7 @@ func TestSqlite3(t *testing.T) {
engine.ShowDebug = showTestSql engine.ShowDebug = showTestSql
testAll(engine, t) testAll(engine, t)
testAllSnakeMapper(engine, t)
testAll2(engine, t) testAll2(engine, t)
testAll3(engine, t) testAll3(engine, t)
} }
@ -49,6 +50,7 @@ func TestSqlite3WithCache(t *testing.T) {
engine.ShowDebug = showTestSql engine.ShowDebug = showTestSql
testAll(engine, t) testAll(engine, t)
testAllSnakeMapper(engine, t)
testAll2(engine, t) testAll2(engine, t)
} }
@ -66,6 +68,7 @@ func TestSqlite3SameMapper(t *testing.T) {
engine.ShowDebug = showTestSql engine.ShowDebug = showTestSql
testAll(engine, t) testAll(engine, t)
testAllSameMapper(engine, t)
testAll2(engine, t) testAll2(engine, t)
testAll3(engine, t) testAll3(engine, t)
} }
@ -85,6 +88,7 @@ func TestSqlite3WithCacheSameMapper(t *testing.T) {
engine.ShowDebug = showTestSql engine.ShowDebug = showTestSql
testAll(engine, t) testAll(engine, t)
testAllSameMapper(engine, t)
testAll2(engine, t) testAll2(engine, t)
} }