(t *testing.T)
| 74 | } |
| 75 | |
| 76 | func TestCancelTransaction(t *testing.T) { |
| 77 | ctx := context.Background() |
| 78 | ctx, cancelFunc := context.WithCancel(ctx) |
| 79 | cancelFunc() |
| 80 | |
| 81 | user := *GetUser("cancel_transaction", Config{}) |
| 82 | DB.Create(&user) |
| 83 | |
| 84 | err := DB.WithContext(ctx).Transaction(func(tx *gorm.DB) error { |
| 85 | var result User |
| 86 | tx.First(&result, user.ID) |
| 87 | return nil |
| 88 | }) |
| 89 | |
| 90 | if err == nil { |
| 91 | t.Fatalf("Transaction should get error when using cancelled context") |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | func TestTransactionWithBlock(t *testing.T) { |
| 96 | assertPanic := func(f func()) { |
nothing calls this directly
no test coverage detected