forked from mirror/gorm
update tests
This commit is contained in:
parent
30e1b07f7e
commit
d8f7d4a243
20
gorm_test.go
20
gorm_test.go
|
@ -1471,34 +1471,34 @@ func TestSqlNullValue(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTransaction(t *testing.T) {
|
||||
d := db.Begin()
|
||||
tx := db.Begin()
|
||||
u := User{Name: "transcation"}
|
||||
if err := d.Save(&u).Error; err != nil {
|
||||
if err := tx.Save(&u).Error; err != nil {
|
||||
t.Errorf("No error should raise, but got", err)
|
||||
}
|
||||
|
||||
if err := d.First(&User{}, "name = ?", "transcation").Error; err != nil {
|
||||
if err := tx.First(&User{}, "name = ?", "transcation").Error; err != nil {
|
||||
t.Errorf("Should find saved record, but got", err)
|
||||
}
|
||||
|
||||
d.Rollback()
|
||||
tx.Rollback()
|
||||
|
||||
if err := d.First(&User{}, "name = ?", "transcation").Error; err == nil {
|
||||
if err := tx.First(&User{}, "name = ?", "transcation").Error; err == nil {
|
||||
t.Errorf("Should not find record after rollback")
|
||||
}
|
||||
|
||||
d2 := db.Begin()
|
||||
tx2 := db.Begin()
|
||||
u2 := User{Name: "transcation-2"}
|
||||
if err := d2.Save(&u2).Error; err != nil {
|
||||
if err := tx2.Save(&u2).Error; err != nil {
|
||||
t.Errorf("No error should raise, but got", err)
|
||||
}
|
||||
d2.Update("age", 90)
|
||||
tx2.Update("age", 90)
|
||||
|
||||
if err := d2.First(&User{}, "name = ?", "transcation-2").Error; err != nil {
|
||||
if err := tx2.First(&User{}, "name = ?", "transcation-2").Error; err != nil {
|
||||
t.Errorf("Should find saved record, but got", err)
|
||||
}
|
||||
|
||||
d2.Commit()
|
||||
tx2.Commit()
|
||||
|
||||
if err := db.First(&User{}, "name = ?", "transcation-2").Error; err != nil {
|
||||
t.Errorf("Should be able to find committed record")
|
||||
|
|
Loading…
Reference in New Issue