Test transaction rollback.
(t *testing.T)
| 134 | |
| 135 | // Test transaction rollback. |
| 136 | func TestTransactionRollback(t *testing.T) { |
| 137 | adapter := NewMockTransactionalAdapter() |
| 138 | e, err := NewTransactionalEnforcer("examples/rbac_model.conf", adapter) |
| 139 | if err != nil { |
| 140 | t.Fatalf("Failed to create transactional enforcer: %v", err) |
| 141 | } |
| 142 | adapter.Enforcer = e.Enforcer |
| 143 | |
| 144 | ctx := context.Background() |
| 145 | |
| 146 | // Begin transaction. |
| 147 | tx, err := e.BeginTransaction(ctx) |
| 148 | if err != nil { |
| 149 | t.Fatalf("Failed to begin transaction: %v", err) |
| 150 | } |
| 151 | |
| 152 | // Add policy in transaction. |
| 153 | ok, err := tx.AddPolicy("alice", "data1", "read") |
| 154 | if !ok || err != nil { |
| 155 | t.Fatalf("Failed to add policy in transaction: %v", err) |
| 156 | } |
| 157 | |
| 158 | // Rollback transaction. |
| 159 | if err := tx.Rollback(); err != nil { |
| 160 | t.Fatalf("Failed to rollback transaction: %v", err) |
| 161 | } |
| 162 | |
| 163 | // Verify transaction was rolled back. |
| 164 | if !tx.IsRolledBack() { |
| 165 | t.Error("Transaction should be rolled back") |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | // Test concurrent transactions. |
| 170 | func TestConcurrentTransactions(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…