(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestRunInTransaction(t *testing.T) { |
| 12 | app, _ := tests.NewTestApp() |
| 13 | defer app.Cleanup() |
| 14 | |
| 15 | t.Run("failed nested transaction", func(t *testing.T) { |
| 16 | app.RunInTransaction(func(txApp core.App) error { |
| 17 | superuser, _ := txApp.FindAuthRecordByEmail(core.CollectionNameSuperusers, "test@example.com") |
| 18 | |
| 19 | return txApp.RunInTransaction(func(tx2Dao core.App) error { |
| 20 | if err := tx2Dao.Delete(superuser); err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | return errors.New("test error") |
| 24 | }) |
| 25 | }) |
| 26 | |
| 27 | // superuser should still exist |
| 28 | superuser, _ := app.FindAuthRecordByEmail(core.CollectionNameSuperusers, "test@example.com") |
| 29 | if superuser == nil { |
| 30 | t.Fatal("Expected superuser test@example.com to not be deleted") |
| 31 | } |
| 32 | }) |
| 33 | |
| 34 | t.Run("successful nested transaction", func(t *testing.T) { |
| 35 | app.RunInTransaction(func(txApp core.App) error { |
| 36 | superuser, _ := txApp.FindAuthRecordByEmail(core.CollectionNameSuperusers, "test@example.com") |
| 37 | |
| 38 | return txApp.RunInTransaction(func(tx2Dao core.App) error { |
| 39 | return tx2Dao.Delete(superuser) |
| 40 | }) |
| 41 | }) |
| 42 | |
| 43 | // superuser should have been deleted |
| 44 | superuser, _ := app.FindAuthRecordByEmail(core.CollectionNameSuperusers, "test@example.com") |
| 45 | if superuser != nil { |
| 46 | t.Fatalf("Expected superuser test@example.com to be deleted, found %v", superuser) |
| 47 | } |
| 48 | }) |
| 49 | } |
| 50 | |
| 51 | func TestTransactionHooksCallsOnFailure(t *testing.T) { |
| 52 | app, _ := tests.NewTestApp() |
nothing calls this directly
no test coverage detected
searching dependent graphs…