1
1
package query
2
2
3
3
import (
4
- "github.com/cortexproject/cortex/pkg/util/validation"
5
- "github.com/stretchr/testify/assert"
6
4
"net/url"
7
5
"strconv"
8
6
"testing"
9
7
"time"
8
+
9
+ "github.com/stretchr/testify/assert"
10
+
11
+ "github.com/cortexproject/cortex/pkg/util/validation"
10
12
)
11
13
12
14
func Test_GetPriorityShouldReturnDefaultPriorityIfNotEnabledOrEmptyQueryString (t * testing.T ) {
@@ -23,21 +25,20 @@ func Test_GetPriorityShouldReturnDefaultPriorityIfNotEnabledOrEmptyQueryString(t
23
25
},
24
26
},
25
27
}
28
+ queryPriority := validation.QueryPriority {
29
+ Priorities : priorities ,
30
+ }
26
31
27
32
assert .Equal (t , int64 (0 ), GetPriority (url.Values {
28
33
"query" : []string {"sum(up)" },
29
34
"time" : []string {strconv .FormatInt (now .Unix (), 10 )},
30
- }, now , validation.QueryPriority {
31
- Priorities : priorities ,
32
- }))
35
+ }, now , & queryPriority , true ))
33
36
37
+ queryPriority .Enabled = true
34
38
assert .Equal (t , int64 (0 ), GetPriority (url.Values {
35
39
"query" : []string {"" },
36
40
"time" : []string {strconv .FormatInt (now .Unix (), 10 )},
37
- }, now , validation.QueryPriority {
38
- Enabled : true ,
39
- Priorities : priorities ,
40
- }))
41
+ }, now , & queryPriority , true ))
41
42
}
42
43
43
44
func Test_GetPriorityShouldConsiderRegex (t * testing.T ) {
@@ -54,72 +55,52 @@ func Test_GetPriorityShouldConsiderRegex(t *testing.T) {
54
55
},
55
56
},
56
57
}
57
- limits , _ := validation .NewOverrides (validation.Limits {
58
- QueryPriority : validation.QueryPriority {
59
- Enabled : true ,
60
- Priorities : priorities ,
61
- },
62
- }, nil )
58
+ queryPriority := validation.QueryPriority {
59
+ Enabled : true ,
60
+ Priorities : priorities ,
61
+ }
63
62
64
63
assert .Equal (t , int64 (1 ), GetPriority (url.Values {
65
64
"query" : []string {"sum(up)" },
66
65
"time" : []string {strconv .FormatInt (now .Unix (), 10 )},
67
- }, now , limits . QueryPriority ( "" ) ))
66
+ }, now , & queryPriority , true ))
68
67
assert .Equal (t , int64 (0 ), GetPriority (url.Values {
69
68
"query" : []string {"count(up)" },
70
69
"time" : []string {strconv .FormatInt (now .Unix (), 10 )},
71
- }, now , limits . QueryPriority ( "" ) ))
70
+ }, now , & queryPriority , false ))
72
71
73
- priorities [0 ].QueryAttributes [0 ].Regex = "(^sum$|c(.+)t)"
74
- limits , _ = validation .NewOverrides (validation.Limits {
75
- QueryPriority : validation.QueryPriority {
76
- Enabled : true ,
77
- Priorities : priorities ,
78
- },
79
- }, nil )
72
+ queryPriority .Priorities [0 ].QueryAttributes [0 ].Regex = "(^sum$|c(.+)t)"
80
73
81
74
assert .Equal (t , int64 (0 ), GetPriority (url.Values {
82
75
"query" : []string {"sum(up)" },
83
76
"time" : []string {strconv .FormatInt (now .Unix (), 10 )},
84
- }, now , limits . QueryPriority ( "" ) ))
77
+ }, now , & queryPriority , true ))
85
78
assert .Equal (t , int64 (1 ), GetPriority (url.Values {
86
79
"query" : []string {"count(up)" },
87
80
"time" : []string {strconv .FormatInt (now .Unix (), 10 )},
88
- }, now , limits . QueryPriority ( "" ) ))
81
+ }, now , & queryPriority , false ))
89
82
90
- priorities [0 ].QueryAttributes [0 ].Regex = ".*"
91
- limits , _ = validation .NewOverrides (validation.Limits {
92
- QueryPriority : validation.QueryPriority {
93
- Enabled : true ,
94
- Priorities : priorities ,
95
- },
96
- }, nil )
83
+ queryPriority .Priorities [0 ].QueryAttributes [0 ].Regex = ".*"
97
84
98
85
assert .Equal (t , int64 (1 ), GetPriority (url.Values {
99
86
"query" : []string {"sum(up)" },
100
87
"time" : []string {strconv .FormatInt (now .Unix (), 10 )},
101
- }, now , limits . QueryPriority ( "" ) ))
88
+ }, now , & queryPriority , true ))
102
89
assert .Equal (t , int64 (1 ), GetPriority (url.Values {
103
90
"query" : []string {"count(up)" },
104
91
"time" : []string {strconv .FormatInt (now .Unix (), 10 )},
105
- }, now , limits . QueryPriority ( "" ) ))
92
+ }, now , & queryPriority , false ))
106
93
107
- priorities [0 ].QueryAttributes [0 ].Regex = ""
108
- limits , _ = validation .NewOverrides (validation.Limits {
109
- QueryPriority : validation.QueryPriority {
110
- Enabled : true ,
111
- Priorities : priorities ,
112
- },
113
- }, nil )
94
+ queryPriority .Priorities [0 ].QueryAttributes [0 ].Regex = ""
114
95
115
96
assert .Equal (t , int64 (1 ), GetPriority (url.Values {
116
97
"query" : []string {"sum(up)" },
117
98
"time" : []string {strconv .FormatInt (now .Unix (), 10 )},
118
- }, now , limits . QueryPriority ( "" ) ))
99
+ }, now , & queryPriority , true ))
119
100
assert .Equal (t , int64 (1 ), GetPriority (url.Values {
120
101
"query" : []string {"count(up)" },
121
102
"time" : []string {strconv .FormatInt (now .Unix (), 10 )},
122
- }, now , limits . QueryPriority ( "" ) ))
103
+ }, now , & queryPriority , false ))
123
104
}
124
105
125
106
func Test_GetPriorityShouldConsiderStartAndEndTime (t * testing.T ) {
@@ -135,57 +116,55 @@ func Test_GetPriorityShouldConsiderStartAndEndTime(t *testing.T) {
135
116
},
136
117
},
137
118
}
138
- limits , _ := validation .NewOverrides (validation.Limits {
139
- QueryPriority : validation.QueryPriority {
140
- Enabled : true ,
141
- Priorities : priorities ,
142
- },
143
- }, nil )
119
+ queryPriority := validation.QueryPriority {
120
+ Enabled : true ,
121
+ Priorities : priorities ,
122
+ }
144
123
145
124
assert .Equal (t , int64 (0 ), GetPriority (url.Values {
146
125
"query" : []string {"sum(up)" },
147
126
"time" : []string {strconv .FormatInt (now .Unix (), 10 )},
148
- }, now , limits . QueryPriority ( "" ) ))
127
+ }, now , & queryPriority , true ))
149
128
assert .Equal (t , int64 (1 ), GetPriority (url.Values {
150
129
"query" : []string {"sum(up)" },
151
130
"time" : []string {strconv .FormatInt (now .Add (- 30 * time .Minute ).Unix (), 10 )},
152
- }, now , limits . QueryPriority ( "" ) ))
131
+ }, now , & queryPriority , false ))
153
132
assert .Equal (t , int64 (0 ), GetPriority (url.Values {
154
133
"query" : []string {"sum(up)" },
155
134
"time" : []string {strconv .FormatInt (now .Add (- 60 * time .Minute ).Unix (), 10 )},
156
- }, now , limits . QueryPriority ( "" ) ))
135
+ }, now , & queryPriority , false ))
157
136
assert .Equal (t , int64 (1 ), GetPriority (url.Values {
158
137
"query" : []string {"sum(up)" },
159
138
"time" : []string {strconv .FormatInt (now .Add (- 45 * time .Minute ).Unix (), 10 )},
160
- }, now , limits . QueryPriority ( "" ) ))
139
+ }, now , & queryPriority , false ))
161
140
assert .Equal (t , int64 (1 ), GetPriority (url.Values {
162
141
"query" : []string {"sum(up)" },
163
142
"time" : []string {strconv .FormatInt (now .Add (- 15 * time .Minute ).Unix (), 10 )},
164
- }, now , limits . QueryPriority ( "" ) ))
143
+ }, now , & queryPriority , false ))
165
144
166
145
assert .Equal (t , int64 (1 ), GetPriority (url.Values {
167
146
"query" : []string {"sum(up)" },
168
147
"start" : []string {strconv .FormatInt (now .Add (- 45 * time .Minute ).Unix (), 10 )},
169
148
"end" : []string {strconv .FormatInt (now .Add (- 15 * time .Minute ).Unix (), 10 )},
170
- }, now , limits . QueryPriority ( "" ) ))
149
+ }, now , & queryPriority , false ))
171
150
assert .Equal (t , int64 (0 ), GetPriority (url.Values {
172
151
"query" : []string {"sum(up)" },
173
152
"start" : []string {strconv .FormatInt (now .Add (- 50 * time .Minute ).Unix (), 10 )},
174
153
"end" : []string {strconv .FormatInt (now .Add (- 15 * time .Minute ).Unix (), 10 )},
175
- }, now , limits . QueryPriority ( "" ) ))
154
+ }, now , & queryPriority , false ))
176
155
assert .Equal (t , int64 (0 ), GetPriority (url.Values {
177
156
"query" : []string {"sum(up)" },
178
157
"start" : []string {strconv .FormatInt (now .Add (- 45 * time .Minute ).Unix (), 10 )},
179
158
"end" : []string {strconv .FormatInt (now .Add (- 10 * time .Minute ).Unix (), 10 )},
180
- }, now , limits . QueryPriority ( "" ) ))
159
+ }, now , & queryPriority , false ))
181
160
assert .Equal (t , int64 (0 ), GetPriority (url.Values {
182
161
"query" : []string {"sum(up)" },
183
162
"start" : []string {strconv .FormatInt (now .Add (- 60 * time .Minute ).Unix (), 10 )},
184
163
"end" : []string {strconv .FormatInt (now .Add (- 45 * time .Minute ).Unix (), 10 )},
185
- }, now , limits . QueryPriority ( "" ) ))
164
+ }, now , & queryPriority , false ))
186
165
assert .Equal (t , int64 (0 ), GetPriority (url.Values {
187
166
"query" : []string {"sum(up)" },
188
167
"start" : []string {strconv .FormatInt (now .Add (- 15 * time .Minute ).Unix (), 10 )},
189
168
"end" : []string {strconv .FormatInt (now .Add (- 1 * time .Minute ).Unix (), 10 )},
190
- }, now , limits . QueryPriority ( "" ) ))
169
+ }, now , & queryPriority , false ))
191
170
}
0 commit comments