MCPcopy
hub / github.com/crowdsecurity/crowdsec / TestVisitor

Function TestVisitor

pkg/exprhelpers/exprlib_test.go:38–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

36}
37
38func TestVisitor(t *testing.T) {
39 err := Init(nil)
40 require.NoError(t, err)
41
42 tests := []struct {
43 name string
44 filter string
45 result bool
46 env map[string]any
47 err error
48 }{
49 {
50 name: "debug : no variable",
51 filter: "'crowdsec' startsWith 'crowdse'",
52 result: true,
53 err: nil,
54 env: map[string]any{},
55 },
56 {
57 name: "debug : simple variable",
58 filter: "'crowdsec' startsWith static_one && 1 == 1",
59 result: true,
60 err: nil,
61 env: map[string]any{"static_one": string("crowdse")},
62 },
63 {
64 name: "debug : simple variable re-used",
65 filter: "static_one.foo == 'bar' && static_one.foo != 'toto'",
66 result: true,
67 err: nil,
68 env: map[string]any{"static_one": map[string]string{"foo": "bar"}},
69 },
70 {
71 name: "debug : can't compile",
72 filter: "static_one.foo.toto == 'lol'",
73 result: false,
74 err: errors.New("bad syntax"),
75 env: map[string]any{"static_one": map[string]string{"foo": "bar"}},
76 },
77 {
78 name: "debug : can't compile #2",
79 filter: "static_one.f!oo.to/to == 'lol'",
80 result: false,
81 err: errors.New("bad syntax"),
82 env: map[string]any{"static_one": map[string]string{"foo": "bar"}},
83 },
84 {
85 name: "debug : can't compile #3",
86 filter: "",
87 result: false,
88 err: errors.New("bad syntax"),
89 env: map[string]any{"static_one": map[string]string{"foo": "bar"}},
90 },
91 }
92
93 log.SetLevel(log.DebugLevel)
94
95 for _, test := range tests {

Callers

nothing calls this directly

Calls 5

InitFunction · 0.85
GetExprOptionsFunction · 0.85
SetLevelMethod · 0.80
RunMethod · 0.65
CompileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…