Skip to content

Commit 633ea23

Browse files
committed
TestDeeplyNestedTransactionWithBlockAndWrappedCallback test Fix
1 parent fd83ff2 commit 633ea23

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

tests/transaction_test.go

Lines changed: 9 additions & 10 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,21 +353,21 @@ 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 {
356+
if err := tx.First(&User{}, "\"name\" = ?", user.Name).Error; err != nil {
358357
t.Fatalf("Should find saved record")
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 {
363+
if err := tx1.First(&User{}, "\"name\" = ?", user1.Name).Error; err != nil {
365364
t.Fatalf("Should find saved record")
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 {
370+
if err := tx2.First(&User{}, "\"name\" = ?", user2.Name).Error; err != nil {
372371
t.Fatalf("Should find saved record")
373372
}
374373

@@ -382,27 +381,27 @@ 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 {
384+
if err := tx.First(&User{}, "\"name\" = ?", user1.Name).Error; err == nil {
386385
t.Fatalf("Should not find rollbacked record")
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 saved record")
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 {
396+
if err := DB.First(&User{}, "\"name\" = ?", user.Name).Error; err != nil {
398397
t.Fatalf("Should find saved record")
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 {
404+
if err := DB.First(&User{}, "\"name\" = ?", user2.Name).Error; err == nil {
406405
t.Fatalf("Should not find rollbacked nested record")
407406
}
408407
}

0 commit comments

Comments
 (0)