MCPcopy Index your code
hub / github.com/apache/casbin / TestIEnforcerContext_SelfMethods

Function TestIEnforcerContext_SelfMethods

enforcer_context_test.go:209–232  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

207}
208
209func TestIEnforcerContext_SelfMethods(t *testing.T) {
210 e, err := NewContextEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
211 if err != nil {
212 t.Fatalf("NewContextEnforcer failed: %v", err)
213 }
214
215 ctx := context.Background()
216
217 added, err := e.SelfAddPolicyCtx(ctx, "p", "p", []string{"eve", "data3", "read"})
218 if err != nil {
219 t.Fatalf("SelfAddPolicyCtx failed: %v", err)
220 }
221 if !added {
222 t.Error("SelfAddPolicyCtx should return true for new policy")
223 }
224
225 removed, err := e.SelfRemovePolicyCtx(ctx, "p", "p", []string{"eve", "data3", "read"})
226 if err != nil {
227 t.Fatalf("SelfRemovePolicyCtx failed: %v", err)
228 }
229 if !removed {
230 t.Error("SelfRemovePolicyCtx should return true for existing policy")
231 }
232}

Callers

nothing calls this directly

Calls 4

SelfAddPolicyCtxMethod · 0.95
SelfRemovePolicyCtxMethod · 0.95
NewContextEnforcerFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…