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

Function TestSelfModify

watcher_test.go:54–91  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

52}
53
54func TestSelfModify(t *testing.T) {
55 e, err := NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
56 if err != nil {
57 t.Fatal(err)
58 }
59
60 sampleWatcher := &SampleWatcher{}
61 err = e.SetWatcher(sampleWatcher)
62 if err != nil {
63 t.Fatal(err)
64 }
65
66 var called int
67
68 called = -1
69 _ = e.watcher.SetUpdateCallback(func(s string) {
70 called = 1
71 })
72 _, err = e.AddPolicy("eva", "data", "read") // calls watcher.Update()
73 if err != nil {
74 t.Fatal(err)
75 }
76 if called != 1 {
77 t.Fatal("callback should be called")
78 }
79
80 called = -1
81 _ = e.watcher.SetUpdateCallback(func(s string) {
82 called = 1
83 })
84 _, err = e.SelfAddPolicy("p", "p", []string{"eva", "data", "write"}) // calls watcher.Update()
85 if err != nil {
86 t.Fatal(err)
87 }
88 if called != -1 {
89 t.Fatal("callback should not be called")
90 }
91}

Callers

nothing calls this directly

Calls 5

SetWatcherMethod · 0.95
AddPolicyMethod · 0.95
SelfAddPolicyMethod · 0.95
NewEnforcerFunction · 0.85
SetUpdateCallbackMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…