Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions tests/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ func TestNestedTransactionWithBlock(t *testing.T) {
}

func TestDeeplyNestedTransactionWithBlockAndWrappedCallback(t *testing.T) {
t.Skip()
transaction := func(ctx context.Context, db *gorm.DB, callback func(ctx context.Context, db *gorm.DB) error) error {
return db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
return callback(ctx, tx)
Expand All @@ -354,21 +353,21 @@ func TestDeeplyNestedTransactionWithBlockAndWrappedCallback(t *testing.T) {
if err := transaction(context.Background(), DB, func(ctx context.Context, tx *gorm.DB) error {
tx.Create(&user)

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

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

if err := tx1.First(&User{}, "name = ?", user1.Name).Error; err != nil {
if err := tx1.First(&User{}, "\"name\" = ?", user1.Name).Error; err != nil {
t.Fatalf("Should find saved record")
}

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

if err := tx2.First(&User{}, "name = ?", user2.Name).Error; err != nil {
if err := tx2.First(&User{}, "\"name\" = ?", user2.Name).Error; err != nil {
t.Fatalf("Should find saved record")
}

Expand All @@ -382,27 +381,27 @@ func TestDeeplyNestedTransactionWithBlockAndWrappedCallback(t *testing.T) {
t.Fatalf("nested transaction should returns error")
}

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

if err := tx.First(&User{}, "name = ?", user2.Name).Error; err != nil {
t.Fatalf("Should find saved record")
if err := tx.First(&User{}, "\"name\" = ?", user2.Name).Error; err == nil {
t.Fatalf("Should not find saved record")
}
return nil
}); err != nil {
t.Fatalf("no error should return, but got %v", err)
}

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

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

if err := DB.First(&User{}, "name = ?", user2.Name).Error; err != nil {
if err := DB.First(&User{}, "\"name\" = ?", user2.Name).Error; err == nil {
t.Fatalf("Should not find rollbacked nested record")
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/upsert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ func TestFindOrInitialize(t *testing.T) {
}

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