@@ -11,22 +11,6 @@ import (
11
11
"github.com/cortexproject/cortex/pkg/util/validation"
12
12
)
13
13
14
- func Test_IsHighPriority_DefaultValues (t * testing.T ) {
15
- now := time .Now ()
16
- config := []validation.HighPriorityQuery {
17
- {}, // By default, it should match all queries happened at "now"
18
- }
19
-
20
- assert .True (t , IsHighPriority (url.Values {
21
- "query" : []string {"count(up)" },
22
- "time" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
23
- }, config ))
24
- assert .False (t , IsHighPriority (url.Values {
25
- "query" : []string {"count(up)" },
26
- "time" : []string {strconv .FormatInt (now .Add (- 1 * time .Second ).UnixMilli (), 10 )},
27
- }, config ))
28
- }
29
-
30
14
func Test_IsHighPriority_ShouldMatchRegex (t * testing.T ) {
31
15
now := time .Now ()
32
16
config := []validation.HighPriorityQuery {
@@ -38,11 +22,11 @@ func Test_IsHighPriority_ShouldMatchRegex(t *testing.T) {
38
22
assert .True (t , IsHighPriority (url.Values {
39
23
"query" : []string {"sum(up)" },
40
24
"time" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
41
- }, config ))
25
+ }, now , config ))
42
26
assert .False (t , IsHighPriority (url.Values {
43
27
"query" : []string {"count(up)" },
44
28
"time" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
45
- }, config ))
29
+ }, now , config ))
46
30
47
31
config = []validation.HighPriorityQuery {
48
32
{
@@ -53,11 +37,11 @@ func Test_IsHighPriority_ShouldMatchRegex(t *testing.T) {
53
37
assert .True (t , IsHighPriority (url.Values {
54
38
"query" : []string {"sum(up)" },
55
39
"time" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
56
- }, config ))
40
+ }, now , config ))
57
41
assert .True (t , IsHighPriority (url.Values {
58
42
"query" : []string {"count(up)" },
59
43
"time" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
60
- }, config ))
44
+ }, now , config ))
61
45
62
46
config = []validation.HighPriorityQuery {
63
47
{
@@ -71,11 +55,11 @@ func Test_IsHighPriority_ShouldMatchRegex(t *testing.T) {
71
55
assert .True (t , IsHighPriority (url.Values {
72
56
"query" : []string {"sum(up)" },
73
57
"time" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
74
- }, config ))
58
+ }, now , config ))
75
59
assert .True (t , IsHighPriority (url.Values {
76
60
"query" : []string {"count(up)" },
77
61
"time" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
78
- }, config ))
62
+ }, now , config ))
79
63
80
64
config = []validation.HighPriorityQuery {
81
65
{
@@ -89,11 +73,11 @@ func Test_IsHighPriority_ShouldMatchRegex(t *testing.T) {
89
73
assert .False (t , IsHighPriority (url.Values {
90
74
"query" : []string {"sum(up)" },
91
75
"time" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
92
- }, config ))
76
+ }, now , config ))
93
77
assert .False (t , IsHighPriority (url.Values {
94
78
"query" : []string {"count(up)" },
95
79
"time" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
96
- }, config ))
80
+ }, now , config ))
97
81
98
82
config = []validation.HighPriorityQuery {
99
83
{
@@ -104,11 +88,26 @@ func Test_IsHighPriority_ShouldMatchRegex(t *testing.T) {
104
88
assert .True (t , IsHighPriority (url.Values {
105
89
"query" : []string {"sum(up)" },
106
90
"time" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
107
- }, config ))
91
+ }, now , config ))
92
+ assert .True (t , IsHighPriority (url.Values {
93
+ "query" : []string {"count(up)" },
94
+ "time" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
95
+ }, now , config ))
96
+
97
+ config = []validation.HighPriorityQuery {
98
+ {
99
+ Regex : "" ,
100
+ },
101
+ }
102
+
103
+ assert .True (t , IsHighPriority (url.Values {
104
+ "query" : []string {"sum(up)" },
105
+ "time" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
106
+ }, now , config ))
108
107
assert .True (t , IsHighPriority (url.Values {
109
108
"query" : []string {"count(up)" },
110
109
"time" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
111
- }, config ))
110
+ }, now , config ))
112
111
}
113
112
114
113
func Test_IsHighPriority_ShouldBeBetweenStartAndEndTime (t * testing.T ) {
@@ -123,32 +122,32 @@ func Test_IsHighPriority_ShouldBeBetweenStartAndEndTime(t *testing.T) {
123
122
assert .False (t , IsHighPriority (url.Values {
124
123
"query" : []string {"sum(up)" },
125
124
"time" : []string {strconv .FormatInt (now .Add (- 2 * time .Hour ).UnixMilli (), 10 )},
126
- }, config ))
125
+ }, now , config ))
127
126
assert .True (t , IsHighPriority (url.Values {
128
127
"query" : []string {"sum(up)" },
129
128
"time" : []string {strconv .FormatInt (now .Add (- 1 * time .Hour ).UnixMilli (), 10 )},
130
- }, config ))
129
+ }, now , config ))
131
130
assert .True (t , IsHighPriority (url.Values {
132
131
"query" : []string {"sum(up)" },
133
132
"time" : []string {strconv .FormatInt (now .Add (- 30 * time .Minute ).UnixMilli (), 10 )},
134
- }, config ))
133
+ }, now , config ))
135
134
assert .False (t , IsHighPriority (url.Values {
136
135
"query" : []string {"sum(up)" },
137
136
"time" : []string {strconv .FormatInt (now .Add (- 1 * time .Minute ).UnixMilli (), 10 )},
138
- }, config ))
137
+ }, now , config ))
139
138
assert .False (t , IsHighPriority (url.Values {
140
139
"query" : []string {"sum(up)" },
141
140
"start" : []string {strconv .FormatInt (now .Add (- 2 * time .Hour ).UnixMilli (), 10 )},
142
141
"end" : []string {strconv .FormatInt (now .Add (- 30 * time .Minute ).UnixMilli (), 10 )},
143
- }, config ))
142
+ }, now , config ))
144
143
assert .True (t , IsHighPriority (url.Values {
145
144
"query" : []string {"sum(up)" },
146
145
"start" : []string {strconv .FormatInt (now .Add (- 1 * time .Hour ).UnixMilli (), 10 )},
147
146
"end" : []string {strconv .FormatInt (now .Add (- 30 * time .Minute ).UnixMilli (), 10 )},
148
- }, config ))
147
+ }, now , config ))
149
148
assert .False (t , IsHighPriority (url.Values {
150
149
"query" : []string {"sum(up)" },
151
150
"start" : []string {strconv .FormatInt (now .Add (- 1 * time .Hour ).UnixMilli (), 10 )},
152
151
"end" : []string {strconv .FormatInt (now .UnixMilli (), 10 )},
153
- }, config ))
152
+ }, now , config ))
154
153
}
0 commit comments