Test basic transaction functionality.
(t *testing.T)
| 95 | |
| 96 | // Test basic transaction functionality. |
| 97 | func TestTransactionBasicOperations(t *testing.T) { |
| 98 | adapter := NewMockTransactionalAdapter() |
| 99 | e, err := NewTransactionalEnforcer("examples/rbac_model.conf", adapter) |
| 100 | if err != nil { |
| 101 | t.Fatalf("Failed to create transactional enforcer: %v", err) |
| 102 | } |
| 103 | adapter.Enforcer = e.Enforcer |
| 104 | |
| 105 | ctx := context.Background() |
| 106 | |
| 107 | // Begin transaction. |
| 108 | tx, err := e.BeginTransaction(ctx) |
| 109 | if err != nil { |
| 110 | t.Fatalf("Failed to begin transaction: %v", err) |
| 111 | } |
| 112 | |
| 113 | // Add policies in transaction. |
| 114 | ok, err := tx.AddPolicy("alice", "data1", "read") |
| 115 | if !ok || err != nil { |
| 116 | t.Fatalf("Failed to add policy in transaction: %v", err) |
| 117 | } |
| 118 | |
| 119 | ok, err = tx.AddPolicy("bob", "data2", "write") |
| 120 | if !ok || err != nil { |
| 121 | t.Fatalf("Failed to add policy in transaction: %v", err) |
| 122 | } |
| 123 | |
| 124 | // Commit transaction. |
| 125 | if err := tx.Commit(); err != nil { |
| 126 | t.Fatalf("Failed to commit transaction: %v", err) |
| 127 | } |
| 128 | |
| 129 | // Verify transaction was committed. |
| 130 | if !tx.IsCommitted() { |
| 131 | t.Error("Transaction should be committed") |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | // Test transaction rollback. |
| 136 | func TestTransactionRollback(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…