forked from aquasecurity/esquery
-
Notifications
You must be signed in to change notification settings - Fork 1
/
queries_test.go
82 lines (78 loc) · 1.59 KB
/
queries_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package osquery
import (
"testing"
)
func TestQueryMaps(t *testing.T) {
runMapTests(t, []mapTest{
{
"a simple match_all query",
Query(MatchAll()),
map[string]interface{}{
"query": map[string]interface{}{
"match_all": map[string]interface{}{},
},
},
},
{
"a complex query",
Query(
Bool().
Must(
Range("date").
Gt("some time in the past").
Lte("now").
Relation(RangeContains).
TimeZone("Asia/Jerusalem").
Boost(2.3),
Match("author").
Query("some guy").
Analyzer("analyzer?").
Fuzziness("fuzz"),
).
Boost(3.1),
),
map[string]interface{}{
"query": map[string]interface{}{
"bool": map[string]interface{}{
"must": []map[string]interface{}{
{
"range": map[string]interface{}{
"date": map[string]interface{}{
"gt": "some time in the past",
"lte": "now",
"relation": "CONTAINS",
"time_zone": "Asia/Jerusalem",
"boost": 2.3,
},
},
},
{
"match": map[string]interface{}{
"author": map[string]interface{}{
"query": "some guy",
"analyzer": "analyzer?",
"fuzziness": "fuzz",
},
},
},
},
"boost": 3.1,
},
},
},
},
})
}
func TestQueryJSONs(t *testing.T) {
runJSONTests(t, []jsonTest{
{
"simple query",
Query(
Bool().
Must(Term("account_id", "bla")),
),
`{"query":{"bool":{"must":[{"term":{"account_id":{"value":"bla"}}}]}}}`,
nil,
},
})
}