Skip to content

Commit 7e8449b

Browse files
committed
test the transaction
1 parent da1a1f2 commit 7e8449b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

tests/transaction_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,16 +339,15 @@ 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)
346345
})
347346
}
348347
var (
349-
user = *GetUser("transaction-nested", Config{})
350-
user1 = *GetUser("transaction-nested-1", Config{})
351-
user2 = *GetUser("transaction-nested-2", Config{})
348+
user = *GetUser("transaction-nested-000", Config{})
349+
user1 = *GetUser("transaction-nested-001", Config{})
350+
user2 = *GetUser("transaction-nested-002", Config{})
352351
)
353352

354353
if err := transaction(context.Background(), DB, func(ctx context.Context, tx *gorm.DB) error {
@@ -386,7 +385,7 @@ func TestDeeplyNestedTransactionWithBlockAndWrappedCallback(t *testing.T) {
386385
t.Fatalf("Should not find rollbacked record")
387386
}
388387

389-
if err := tx.First(&User{}, "name = ?", user2.Name).Error; err != nil {
388+
if err := tx.First(&User{}, "name = ?", user2.Name).Error; err == nil {
390389
t.Fatalf("Should find saved record")
391390
}
392391
return nil
@@ -402,7 +401,7 @@ func TestDeeplyNestedTransactionWithBlockAndWrappedCallback(t *testing.T) {
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)