-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexpr_test.go
62 lines (53 loc) · 1.06 KB
/
expr_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package expr
import "testing"
var exprExampleList = []struct {
control map[string]interface{}
expr string
result bool
}{
{
map[string]interface{}{"pType": 66, "pid": 317},
`pType > 36 && pid > 310`,
true,
},
{
map[string]interface{}{"pType": 66, "pid": 317},
`pType < 90 && pid == 310`,
false,
},
{
map[string]interface{}{"version": "11.0.1", "pid": 317},
`ver_compare(version, ">", "10.1.1")`,
true,
},
{
map[string]interface{}{"version": "11.0.1", "pid": 317},
`ver_compare(version, "<", "10.1.1")`,
false,
},
{
map[string]interface{}{"pid": 317},
`in_array(pid, []int{317, 318, 319})`,
true,
},
{
map[string]interface{}{"pid": "317"},
`in_array(pid, []string{"317", "318", "319"})`,
true,
},
}
func TestNewEngine(t *testing.T) {
for id, v := range exprExampleList {
engine, err := NewEngine(v.expr)
if err != nil {
t.Error(err)
}
result, err := engine.RunRule(v.control)
if err != nil {
t.Error(err)
}
if v.result != result {
t.Errorf("id %d failed test %v , result = %v", id, v, result)
}
}
}