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

Function TestExplainWithoutConfig

ai_api_test.go:27–40  ·  view source on GitHub ↗

TestExplainWithoutConfig tests that Explain returns error when config is not set.

(t *testing.T)

Source from the content-addressed store, hash-verified

25
26// TestExplainWithoutConfig tests that Explain returns error when config is not set.
27func TestExplainWithoutConfig(t *testing.T) {
28 e, err := NewEnforcer("examples/basic_model.conf", "examples/basic_policy.csv")
29 if err != nil {
30 t.Fatal(err)
31 }
32
33 _, err = e.Explain("alice", "data1", "read")
34 if err == nil {
35 t.Error("Expected error when AI config is not set")
36 }
37 if !strings.Contains(err.Error(), "AI config not set") {
38 t.Errorf("Expected 'AI config not set' error, got: %v", err)
39 }
40}
41
42// TestExplainWithMockAPI tests Explain with a mock OpenAI-compatible API.
43func TestExplainWithMockAPI(t *testing.T) {

Callers

nothing calls this directly

Calls 3

ExplainMethod · 0.95
NewEnforcerFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…