Skip to content

Commit 2ea525f

Browse files
committed
fix TestDeeplyNestedTransactionWithBlockAndWrappedCallback test
1 parent 446138b commit 2ea525f

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

tests/passed-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ TestTransactionWithBlock
336336
TestTransactionRaiseErrorOnRollbackAfterCommit
337337
TestTransactionWithSavePoint
338338
TestNestedTransactionWithBlock
339-
#TestDeeplyNestedTransactionWithBlockAndWrappedCallback
339+
TestDeeplyNestedTransactionWithBlockAndWrappedCallback
340340
TestDisabledNestedTransaction
341341
TestTransactionOnClosedConn
342342
TestTransactionWithHooks

tests/transaction_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ func TestNestedTransactionWithBlock(t *testing.T) {
339339
}
340340

341341
func TestDeeplyNestedTransactionWithBlockAndWrappedCallback(t *testing.T) {
342-
t.Skip()
343342
transaction := func(ctx context.Context, db *gorm.DB, callback func(ctx context.Context, db *gorm.DB) error) error {
344343
return db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
345344
return callback(ctx, tx)
@@ -354,22 +353,22 @@ func TestDeeplyNestedTransactionWithBlockAndWrappedCallback(t *testing.T) {
354353
if err := transaction(context.Background(), DB, func(ctx context.Context, tx *gorm.DB) error {
355354
tx.Create(&user)
356355

357-
if err := tx.First(&User{}, "name = ?", user.Name).Error; err != nil {
358-
t.Fatalf("Should find saved record")
356+
if err := tx.First(&User{}, "\"name\" = ?", user.Name).Error; err != nil {
357+
t.Fatalf("Should find saved record (user)")
359358
}
360359

361360
if err := transaction(ctx, tx, func(ctx context.Context, tx1 *gorm.DB) error {
362361
tx1.Create(&user1)
363362

364-
if err := tx1.First(&User{}, "name = ?", user1.Name).Error; err != nil {
365-
t.Fatalf("Should find saved record")
363+
if err := tx1.First(&User{}, "\"name\" = ?", user1.Name).Error; err != nil {
364+
t.Fatalf("Should find saved record (user1 inside tx1)")
366365
}
367366

368367
if err := transaction(ctx, tx1, func(ctx context.Context, tx2 *gorm.DB) error {
369368
tx2.Create(&user2)
370369

371-
if err := tx2.First(&User{}, "name = ?", user2.Name).Error; err != nil {
372-
t.Fatalf("Should find saved record")
370+
if err := tx2.First(&User{}, "\"name\" = ?", user2.Name).Error; err != nil {
371+
t.Fatalf("Should find saved record (user2 inside tx2)")
373372
}
374373

375374
return errors.New("inner rollback")
@@ -382,28 +381,28 @@ func TestDeeplyNestedTransactionWithBlockAndWrappedCallback(t *testing.T) {
382381
t.Fatalf("nested transaction should returns error")
383382
}
384383

385-
if err := tx.First(&User{}, "name = ?", user1.Name).Error; err == nil {
386-
t.Fatalf("Should not find rollbacked record")
384+
if err := tx.First(&User{}, "\"name\" = ?", user1.Name).Error; err == nil {
385+
t.Fatalf("Should not find rollbacked record (user1)")
387386
}
388387

389-
if err := tx.First(&User{}, "name = ?", user2.Name).Error; err != nil {
390-
t.Fatalf("Should find saved record")
388+
if err := tx.First(&User{}, "\"name\" = ?", user2.Name).Error; err == nil {
389+
t.Fatalf("Should not find rollbacked record (user2)")
391390
}
392391
return nil
393392
}); err != nil {
394393
t.Fatalf("no error should return, but got %v", err)
395394
}
396395

397-
if err := DB.First(&User{}, "name = ?", user.Name).Error; err != nil {
398-
t.Fatalf("Should find saved record")
396+
if err := DB.First(&User{}, "\"name\" = ?", user.Name).Error; err != nil {
397+
t.Fatalf("Should find saved record (user)")
399398
}
400399

401-
if err := DB.First(&User{}, "name = ?", user1.Name).Error; err == nil {
400+
if err := DB.First(&User{}, "\"name\" = ?", user1.Name).Error; err == nil {
402401
t.Fatalf("Should not find rollbacked parent record")
403402
}
404403

405-
if err := DB.First(&User{}, "name = ?", user2.Name).Error; err != nil {
406-
t.Fatalf("Should not find rollbacked nested record")
404+
if err := DB.First(&User{}, "\"name\" = ?", user2.Name).Error; err == nil {
405+
t.Fatalf("Should not find rollbacked record (user2)")
407406
}
408407
}
409408

tests/upsert_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ func TestFindOrInitialize(t *testing.T) {
287287
}
288288

289289
func TestFindOrCreate(t *testing.T) {
290-
t.Skip()
291290
var user1, user2, user3, user4, user5, user6, user7, user8 User
292291
if err := DB.Where(&User{Name: "find or create", Age: 33}).FirstOrCreate(&user1).Error; err != nil {
293292
t.Errorf("no error should happen when FirstOrInit, but got %v", err)

0 commit comments

Comments
 (0)