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

Function TestSync

enforcer_synced_test.go:33–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestSync(t *testing.T) {
34 e, _ := NewSyncedEnforcer("examples/basic_model.conf", "examples/basic_policy.csv")
35 // Start reloading the policy every 200 ms.
36 e.StartAutoLoadPolicy(time.Millisecond * 200)
37
38 testEnforceSync(t, e, "alice", "data1", "read", true)
39 testEnforceSync(t, e, "alice", "data1", "write", false)
40 testEnforceSync(t, e, "alice", "data2", "read", false)
41 testEnforceSync(t, e, "alice", "data2", "write", false)
42 testEnforceSync(t, e, "bob", "data1", "read", false)
43 testEnforceSync(t, e, "bob", "data1", "write", false)
44 testEnforceSync(t, e, "bob", "data2", "read", false)
45 testEnforceSync(t, e, "bob", "data2", "write", true)
46
47 // Simulate a policy change
48 e.ClearPolicy()
49 testEnforceSync(t, e, "bob", "data2", "write", false)
50
51 // Wait for at least one sync
52 time.Sleep(time.Millisecond * 300)
53
54 testEnforceSync(t, e, "bob", "data2", "write", true)
55
56 // Stop the reloading policy periodically.
57 e.StopAutoLoadPolicy()
58}
59
60func TestStopAutoLoadPolicy(t *testing.T) {
61 e, _ := NewSyncedEnforcer("examples/basic_model.conf", "examples/basic_policy.csv")

Callers

nothing calls this directly

Calls 5

StartAutoLoadPolicyMethod · 0.95
ClearPolicyMethod · 0.95
StopAutoLoadPolicyMethod · 0.95
NewSyncedEnforcerFunction · 0.85
testEnforceSyncFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…