1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-29 11:01:28 +00:00
This commit is contained in:
“fudali113” 2016-07-20 15:13:18 +08:00
parent 4b8ecced83
commit ec521ad166

View File

@ -2175,10 +2175,12 @@ func TestIgnoreCaseTag(t *testing.T) {
throwFail(t, AssertIs(info.fields.GetByName("Name03").column, "name")) throwFail(t, AssertIs(info.fields.GetByName("Name03").column, "name"))
} }
func TestInsertOrUpdate(t *testing.T) { func TestInsertOrUpdate(t *testing.T) {
RegisterModel(new(User))
user := User{UserName: "unique_username133", Status: 1, Password: "o"} user := User{UserName: "unique_username133", Status: 1, Password: "o"}
user1 := User{UserName: "unique_username133", Status: 2, Password: "o"} user1 := User{UserName: "unique_username133", Status: 2, Password: "o"}
user2 := User{UserName: "unique_username133", Status: 3, Password: "oo"} user2 := User{UserName: "unique_username133", Status: 3, Password: "oo"}
dORM.Insert(&user) dORM.Insert(&user)
test := User{UserName: "unique_username133"}
fmt.Println(dORM.Driver().Name()) fmt.Println(dORM.Driver().Name())
if dORM.Driver().Name() == "sqlite3" { if dORM.Driver().Name() == "sqlite3" {
fmt.Println("sqlite3 is nonsupport") fmt.Println("sqlite3 is nonsupport")
@ -2190,18 +2192,15 @@ func TestInsertOrUpdate(t *testing.T) {
fmt.Println(err) fmt.Println(err)
} else { } else {
throwFailNow(t, err) throwFailNow(t, err)
}
test := User{UserName: "unique_username133"}
time.Sleep(time.Second * 1)
dORM.Read(&test, "UserName") dORM.Read(&test, "UserName")
throwFailNow(t, AssertIs(user1.Status, test.Status)) throwFailNow(t, AssertIs(user1.Status, test.Status))
}
//test2 普通操作 //test2 普通操作
_, err = dORM.InsertOrUpdate(&user2, "UserName") _, err = dORM.InsertOrUpdate(&user2, "UserName")
if err != nil && (err.Error() == "postgres version must 9.5 or higher" || err.Error() == "`sqlite3` nonsupport insert or update in beego") { if err != nil && (err.Error() == "postgres version must 9.5 or higher" || err.Error() == "`sqlite3` nonsupport insert or update in beego") {
fmt.Println(err) fmt.Println(err)
} else { } else {
throwFailNow(t, err) throwFailNow(t, err)
time.Sleep(time.Second * 1)
dORM.Read(&test, "UserName") dORM.Read(&test, "UserName")
throwFailNow(t, AssertIs(user2.Status, test.Status)) throwFailNow(t, AssertIs(user2.Status, test.Status))
throwFailNow(t, AssertIs(user2.Password, strings.TrimSpace(test.Password))) throwFailNow(t, AssertIs(user2.Password, strings.TrimSpace(test.Password)))
@ -2212,7 +2211,6 @@ func TestInsertOrUpdate(t *testing.T) {
fmt.Println(err) fmt.Println(err)
} else { } else {
throwFailNow(t, err) throwFailNow(t, err)
time.Sleep(time.Second * 1)
dORM.Read(&test, "UserName") dORM.Read(&test, "UserName")
throwFailNow(t, AssertIs(user2.Status+1, test.Status)) throwFailNow(t, AssertIs(user2.Status+1, test.Status))
} }
@ -2222,7 +2220,6 @@ func TestInsertOrUpdate(t *testing.T) {
fmt.Println(err) fmt.Println(err)
} else { } else {
throwFailNow(t, err) throwFailNow(t, err)
time.Sleep(time.Second * 1)
dORM.Read(&test, "UserName") dORM.Read(&test, "UserName")
throwFailNow(t, AssertIs((user2.Status+1)-1, test.Status)) throwFailNow(t, AssertIs((user2.Status+1)-1, test.Status))
} }
@ -2232,7 +2229,6 @@ func TestInsertOrUpdate(t *testing.T) {
fmt.Println(err) fmt.Println(err)
} else { } else {
throwFailNow(t, err) throwFailNow(t, err)
time.Sleep(time.Second * 1)
dORM.Read(&test, "UserName") dORM.Read(&test, "UserName")
throwFailNow(t, AssertIs(((user2.Status+1)-1)*3, test.Status)) throwFailNow(t, AssertIs(((user2.Status+1)-1)*3, test.Status))
} }
@ -2242,7 +2238,6 @@ func TestInsertOrUpdate(t *testing.T) {
fmt.Println(err) fmt.Println(err)
} else { } else {
throwFailNow(t, err) throwFailNow(t, err)
time.Sleep(time.Second * 1)
dORM.Read(&test, "UserName") dORM.Read(&test, "UserName")
throwFailNow(t, AssertIs((((user2.Status+1)-1)*3)/3, test.Status)) throwFailNow(t, AssertIs((((user2.Status+1)-1)*3)/3, test.Status))
} }