MCPcopy Index your code
hub / github.com/expr-lang/expr / TestCrowdsec

Function TestCrowdsec

test/crowdsec/crowdsec_test.go:14–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestCrowdsec(t *testing.T) {
15 b, err := os.ReadFile("../../testdata/crowdsec.json")
16 require.NoError(t, err)
17
18 var examples []string
19 err = json.Unmarshal(b, &examples)
20 require.NoError(t, err)
21
22 env := map[string]any{
23 "evt": &crowdsec.Event{},
24 }
25
26 var opt = []expr.Option{
27 expr.Env(env),
28 }
29 for _, fn := range crowdsec.CustomFunctions {
30 opt = append(
31 opt,
32 expr.Function(
33 fn.Name,
34 func(params ...any) (any, error) {
35 return nil, nil
36 },
37 fn.Func...,
38 ),
39 )
40 }
41
42 for _, line := range examples {
43 t.Run(line, func(t *testing.T) {
44 _, err = expr.Compile(line, opt...)
45 require.NoError(t, err)
46 })
47 }
48}

Callers

nothing calls this directly

Calls 5

NoErrorFunction · 0.92
EnvStruct · 0.92
FunctionFunction · 0.92
CompileFunction · 0.92
RunMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…