@@ -25,32 +25,33 @@ func TestErrorConditions(t *testing.T) {
25
25
tests := []struct {
26
26
desc string
27
27
filter string
28
- fields [] Field
28
+ fields map [ string ] FieldType
29
29
model map [string ]interface {}
30
30
}{
31
31
{
32
32
desc : "bad field type" ,
33
33
filter : `k == "match"` ,
34
- fields : []Field {
35
- {
36
- Name : "k" ,
37
- Type : 999 ,
38
- },
34
+ fields : map [string ]FieldType {
35
+ "k" : 999 ,
36
+ },
37
+ },
38
+ {
39
+ desc : "bad field name" ,
40
+ filter : `abc == "match"` ,
41
+ fields : map [string ]FieldType {
42
+ "k" : 999 ,
39
43
},
40
44
},
41
45
{
42
46
desc : "bad filter" ,
43
47
filter : `k xx "match"` ,
44
- fields : [] Field {},
48
+ fields : map [ string ] FieldType {},
45
49
},
46
50
{
47
51
desc : "bad filter result" ,
48
52
filter : `k` ,
49
- fields : []Field {
50
- {
51
- Name : "k" ,
52
- Type : String ,
53
- },
53
+ fields : map [string ]FieldType {
54
+ "k" : String ,
54
55
},
55
56
model : map [string ]interface {}{
56
57
"k" : "match" ,
@@ -59,11 +60,8 @@ func TestErrorConditions(t *testing.T) {
59
60
{
60
61
desc : "bad model" ,
61
62
filter : `k == "k"` ,
62
- fields : []Field {
63
- {
64
- Name : "k" ,
65
- Type : String ,
66
- },
63
+ fields : map [string ]FieldType {
64
+ "k" : String ,
67
65
},
68
66
model : nil ,
69
67
},
@@ -88,18 +86,15 @@ func TestFilter_Matches(t *testing.T) {
88
86
tests := []struct {
89
87
desc string
90
88
filter string
91
- fields [] Field
89
+ fields map [ string ] FieldType
92
90
positive map [string ]interface {}
93
91
negative map [string ]interface {}
94
92
}{
95
93
{
96
94
desc : "empty" ,
97
95
filter : `` ,
98
- fields : []Field {
99
- {
100
- Name : "k" ,
101
- Type : String ,
102
- },
96
+ fields : map [string ]FieldType {
97
+ "k" : String ,
103
98
},
104
99
positive : map [string ]interface {}{
105
100
"k" : "match" ,
@@ -109,11 +104,8 @@ func TestFilter_Matches(t *testing.T) {
109
104
{
110
105
desc : "equal to String" ,
111
106
filter : `k == "match"` ,
112
- fields : []Field {
113
- {
114
- Name : "k" ,
115
- Type : String ,
116
- },
107
+ fields : map [string ]FieldType {
108
+ "k" : String ,
117
109
},
118
110
positive : map [string ]interface {}{
119
111
"k" : "match" ,
@@ -125,11 +117,8 @@ func TestFilter_Matches(t *testing.T) {
125
117
{
126
118
desc : "equal to Int" ,
127
119
filter : `k == 123` ,
128
- fields : []Field {
129
- {
130
- Name : "k" ,
131
- Type : Int ,
132
- },
120
+ fields : map [string ]FieldType {
121
+ "k" : Int ,
133
122
},
134
123
positive : map [string ]interface {}{
135
124
"k" : 123 ,
@@ -141,11 +130,8 @@ func TestFilter_Matches(t *testing.T) {
141
130
{
142
131
desc : "less than Timestamp" ,
143
132
filter : `k < timestamp("2021-01-01T00:00:00Z")` ,
144
- fields : []Field {
145
- {
146
- Name : "k" ,
147
- Type : Timestamp ,
148
- },
133
+ fields : map [string ]FieldType {
134
+ "k" : Timestamp ,
149
135
},
150
136
positive : map [string ]interface {}{
151
137
"k" : time .Date (2020 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC ),
@@ -157,11 +143,8 @@ func TestFilter_Matches(t *testing.T) {
157
143
{
158
144
desc : "greater than Timestamp" ,
159
145
filter : `k > timestamp("2021-01-01T00:00:00Z")` ,
160
- fields : []Field {
161
- {
162
- Name : "k" ,
163
- Type : Timestamp ,
164
- },
146
+ fields : map [string ]FieldType {
147
+ "k" : Timestamp ,
165
148
},
166
149
positive : map [string ]interface {}{
167
150
"k" : time .Date (2022 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC ),
@@ -173,11 +156,8 @@ func TestFilter_Matches(t *testing.T) {
173
156
{
174
157
desc : "has StringMap key" ,
175
158
filter : `has(labels.match)` ,
176
- fields : []Field {
177
- {
178
- Name : "labels" ,
179
- Type : StringMap ,
180
- },
159
+ fields : map [string ]FieldType {
160
+ "labels" : StringMap ,
181
161
},
182
162
positive : map [string ]interface {}{
183
163
"labels" : map [string ]string {
@@ -193,11 +173,8 @@ func TestFilter_Matches(t *testing.T) {
193
173
{
194
174
desc : "in StringMap keys" ,
195
175
filter : `"match" in labels` ,
196
- fields : []Field {
197
- {
198
- Name : "labels" ,
199
- Type : StringMap ,
200
- },
176
+ fields : map [string ]FieldType {
177
+ "labels" : StringMap ,
201
178
},
202
179
positive : map [string ]interface {}{
203
180
"labels" : map [string ]string {
@@ -213,11 +190,8 @@ func TestFilter_Matches(t *testing.T) {
213
190
{
214
191
desc : "equal to StringMap value" ,
215
192
filter : `labels["k"] == "match"` ,
216
- fields : []Field {
217
- {
218
- Name : "labels" ,
219
- Type : StringMap ,
220
- },
193
+ fields : map [string ]FieldType {
194
+ "labels" : StringMap ,
221
195
},
222
196
positive : map [string ]interface {}{
223
197
"labels" : map [string ]string {
@@ -233,11 +207,8 @@ func TestFilter_Matches(t *testing.T) {
233
207
{
234
208
desc : "substring of StringMap value" ,
235
209
filter : `labels.k.contains("substring")` ,
236
- fields : []Field {
237
- {
238
- Name : "labels" ,
239
- Type : StringMap ,
240
- },
210
+ fields : map [string ]FieldType {
211
+ "labels" : StringMap ,
241
212
},
242
213
positive : map [string ]interface {}{
243
214
"labels" : map [string ]string {
@@ -253,11 +224,8 @@ func TestFilter_Matches(t *testing.T) {
253
224
{
254
225
desc : "in StringMap value split" ,
255
226
filter : `"match" in labels.k.split("_")` ,
256
- fields : []Field {
257
- {
258
- Name : "labels" ,
259
- Type : StringMap ,
260
- },
227
+ fields : map [string ]FieldType {
228
+ "labels" : StringMap ,
261
229
},
262
230
positive : map [string ]interface {}{
263
231
"labels" : map [string ]string {
0 commit comments