-
Notifications
You must be signed in to change notification settings - Fork 3
/
tests_test.go
67 lines (59 loc) · 1.13 KB
/
tests_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
63
64
65
66
67
package tests_test
import (
"testing"
tests "github.com/fino-digital/json-rule-engine"
)
func TestNewTestWrongInput(t *testing.T) {
_, err := tests.NewTest(1.)
if err == nil {
t.Error("should have failed when non object was passed")
}
}
func TestNewTestCorrectInput(t *testing.T) {
_, err := tests.NewTest([]interface{}{1.})
if err != nil {
t.Errorf("test creation should have succeeded: %v", err)
}
}
func TestBuilder(t *testing.T) {
test, err := tests.NewObjectTest(map[string]interface{}{
"a": map[string]interface{}{
"aa": "a",
"bb": "b",
"cc": map[string]interface{}{
"aaa": "c",
},
},
"b": map[string]interface{}{
"$startsWith": "a",
},
"c": map[string]interface{}{
"$all": map[string]interface{}{"aa": "a"},
},
})
if err != nil {
t.Error(err)
return
}
err = test.Run(map[string]interface{}{
"a": map[string]interface{}{
"aa": "a",
"bb": "b",
"cc": map[string]interface{}{
"aaa": "c",
},
},
"b": "aa",
"c": []interface{}{
map[string]interface{}{
"aa": "a",
},
map[string]interface{}{
"aa": "a",
},
},
})
if err != nil {
t.Error(err)
}
}