MCPcopy
hub / github.com/apache/casbin / TestTransactionRollback

Function TestTransactionRollback

transaction_test.go:136–167  ·  view source on GitHub ↗

Test transaction rollback.

(t *testing.T)

Source from the content-addressed store, hash-verified

134
135// Test transaction rollback.
136func 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.
170func TestConcurrentTransactions(t *testing.T) {

Callers

nothing calls this directly

Calls 7

BeginTransactionMethod · 0.95
NewTransactionalEnforcerFunction · 0.85
IsRolledBackMethod · 0.80
AddPolicyMethod · 0.65
RollbackMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…