Skip to content

Commit b1530b9

Browse files
committed
fix TestDeeplyNestedTransactionWithBlockAndWrappedCallback test
1 parent 7c5ae82 commit b1530b9

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
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
}

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)