@@ -11,6 +11,7 @@ import (
1111)
1212
1313func Test_check (t * testing.T ) {
14+ baseTime := time .Now ()
1415 type args struct {
1516 params * ConditionParams
1617 messages []* graph.MessageInfo
@@ -31,7 +32,7 @@ func Test_check(t *testing.T) {
3132 {ID : "A" }, {ID : "B" }, {ID : "C" },
3233 },
3334 lastReportMap : map [string ]interface {}{},
34- baseTime : time . Now () ,
35+ baseTime : baseTime ,
3536 },
3637 []string {"A" , "B" , "C" },
3738 false ,
@@ -48,7 +49,7 @@ func Test_check(t *testing.T) {
4849 {ID : "C" , Condition : `eq .Command "foobar"` },
4950 },
5051 lastReportMap : map [string ]interface {}{},
51- baseTime : time . Now () ,
52+ baseTime : baseTime ,
5253 },
5354 []string {"B" },
5455 false ,
@@ -64,7 +65,7 @@ func Test_check(t *testing.T) {
6465 {ID : "B" , Condition : `contains .UserEmail "fred"` },
6566 },
6667 lastReportMap : map [string ]interface {}{},
67- baseTime : time . Now () ,
68+ baseTime : baseTime ,
6869 },
6970 []string {"A" },
7071 false ,
@@ -80,7 +81,7 @@ func Test_check(t *testing.T) {
8081 {ID : "B" , Condition : `hasPrefix .UserEmail "org"` },
8182 },
8283 lastReportMap : map [string ]interface {}{},
83- baseTime : time . Now () ,
84+ baseTime : baseTime ,
8485 },
8586 []string {"A" },
8687 false ,
@@ -96,7 +97,7 @@ func Test_check(t *testing.T) {
9697 {ID : "B" , Condition : `hasSuffix .UserEmail "org"` },
9798 },
9899 lastReportMap : map [string ]interface {}{},
99- baseTime : time . Now () ,
100+ baseTime : baseTime ,
100101 },
101102 []string {"B" },
102103 false ,
@@ -112,7 +113,7 @@ func Test_check(t *testing.T) {
112113 {ID : "B" , Condition : `regexMatch .UserEmail "^doe.org$"` },
113114 },
114115 lastReportMap : map [string ]interface {}{},
115- baseTime : time . Now () ,
116+ baseTime : baseTime ,
116117 },
117118 []string {"A" },
118119 false ,
@@ -128,7 +129,7 @@ func Test_check(t *testing.T) {
128129 {ID : "B" , Condition : `regexMatch .UserEmail ".*("` },
129130 },
130131 lastReportMap : map [string ]interface {}{},
131- baseTime : time . Now () ,
132+ baseTime : baseTime ,
132133 },
133134 []string {"A" },
134135 false ,
@@ -150,7 +151,7 @@ func Test_check(t *testing.T) {
150151 {ID : "H" , Condition : `eq .StateVersion.Build "foo"` },
151152 },
152153 lastReportMap : map [string ]interface {}{},
153- baseTime : time . Now () ,
154+ baseTime : baseTime ,
154155 },
155156 []string {"A" , "B" , "C" , "D" },
156157 false ,
@@ -165,10 +166,10 @@ func Test_check(t *testing.T) {
165166 {ID : "C" , Repeat : graph .MessageRepeatTypeDisabled },
166167 },
167168 lastReportMap : map [string ]interface {}{
168- "A" : time . Now ( ),
169- "C" : time . Now ( ),
169+ "A" : baseTime . Format ( time . RFC3339 ),
170+ "C" : baseTime . Format ( time . RFC3339 ),
170171 },
171- baseTime : time . Now () ,
172+ baseTime : baseTime ,
172173 },
173174 []string {"B" },
174175 false ,
@@ -183,10 +184,10 @@ func Test_check(t *testing.T) {
183184 {ID : "C" , Repeat : graph .MessageRepeatTypeConstantly },
184185 },
185186 lastReportMap : map [string ]interface {}{
186- "A" : time . Now ( ),
187- "C" : time . Now (). Add (- time .Hour * 24 * 30 ),
187+ "A" : baseTime . Format ( time . RFC3339 ),
188+ "C" : baseTime . Add (- time .Hour * 24 * 30 ). Format ( time . RFC3339 ),
188189 },
189- baseTime : time . Now () ,
190+ baseTime : baseTime ,
190191 },
191192 []string {"A" , "B" , "C" },
192193 false ,
@@ -201,11 +202,11 @@ func Test_check(t *testing.T) {
201202 {ID : "C" , Repeat : graph .MessageRepeatTypeHourly },
202203 },
203204 lastReportMap : map [string ]interface {}{
204- "A" : time . Now ( ),
205- "B" : time . Now (). Add (- time .Hour ),
206- "C" : time . Now ( ),
205+ "A" : baseTime . Format ( time . RFC3339 ),
206+ "B" : baseTime . Add (- time .Hour ). Format ( time . RFC3339 ),
207+ "C" : baseTime . Format ( time . RFC3339 ),
207208 },
208- baseTime : time . Now () ,
209+ baseTime : baseTime ,
209210 },
210211 []string {"B" },
211212 false ,
@@ -220,11 +221,11 @@ func Test_check(t *testing.T) {
220221 {ID : "C" , Repeat : graph .MessageRepeatTypeHourly },
221222 },
222223 lastReportMap : map [string ]interface {}{
223- "A" : time . Now ( ),
224- "B" : time . Now (). Add (- time .Hour * 24 ),
225- "C" : time . Now ( ),
224+ "A" : baseTime . Format ( time . RFC3339 ),
225+ "B" : baseTime . Add (- time .Hour * 24 ). Format ( time . RFC3339 ),
226+ "C" : baseTime . Format ( time . RFC3339 ),
226227 },
227- baseTime : time . Now () ,
228+ baseTime : baseTime ,
228229 },
229230 []string {"B" },
230231 false ,
@@ -239,11 +240,11 @@ func Test_check(t *testing.T) {
239240 {ID : "C" , Repeat : graph .MessageRepeatTypeHourly },
240241 },
241242 lastReportMap : map [string ]interface {}{
242- "A" : time . Now ( ),
243- "B" : time . Now (). Add (- time .Hour * 24 * 7 ),
244- "C" : time . Now ( ),
243+ "A" : baseTime . Format ( time . RFC3339 ),
244+ "B" : baseTime . Add (- time .Hour * 24 * 7 ). Format ( time . RFC3339 ),
245+ "C" : baseTime . Format ( time . RFC3339 ),
245246 },
246- baseTime : time . Now () ,
247+ baseTime : baseTime ,
247248 },
248249 []string {"B" },
249250 false ,
@@ -258,15 +259,86 @@ func Test_check(t *testing.T) {
258259 {ID : "C" , Repeat : graph .MessageRepeatTypeHourly },
259260 },
260261 lastReportMap : map [string ]interface {}{
261- "A" : time . Now ( ),
262- "B" : time . Now (). Add (- time .Hour * 24 * 7 * 30 ),
263- "C" : time . Now ( ),
262+ "A" : baseTime . Format ( time . RFC3339 ),
263+ "B" : baseTime . Add (- time .Hour * 24 * 7 * 30 ). Format ( time . RFC3339 ),
264+ "C" : baseTime . Format ( time . RFC3339 ),
264265 },
265- baseTime : time . Now () ,
266+ baseTime : baseTime ,
266267 },
267268 []string {"B" },
268269 false ,
269270 },
271+ {
272+ "Date Range - Within Range" ,
273+ args {
274+ params : & ConditionParams {},
275+ messages : []* graph.MessageInfo {
276+ {ID : "A" , StartDate : baseTime .Add (- 24 * time .Hour ).Format (time .RFC3339 ), EndDate : baseTime .Add (24 * time .Hour ).Format (time .RFC3339 )},
277+ {ID : "B" , StartDate : baseTime .Add (- 1 * time .Hour ).Format (time .RFC3339 ), EndDate : baseTime .Add (1 * time .Hour ).Format (time .RFC3339 )},
278+ {ID : "C" , StartDate : baseTime .Add (1 * time .Hour ).Format (time .RFC3339 ), EndDate : baseTime .Add (24 * time .Hour ).Format (time .RFC3339 )},
279+ },
280+ lastReportMap : map [string ]interface {}{},
281+ baseTime : baseTime ,
282+ },
283+ []string {"A" , "B" },
284+ false ,
285+ },
286+ {
287+ "Date Range - No Dates Specified" ,
288+ args {
289+ params : & ConditionParams {},
290+ messages : []* graph.MessageInfo {
291+ {ID : "A" },
292+ {ID : "B" , StartDate : baseTime .Add (- 1 * time .Hour ).Format (time .RFC3339 )},
293+ {ID : "C" , EndDate : baseTime .Add (1 * time .Hour ).Format (time .RFC3339 )},
294+ },
295+ lastReportMap : map [string ]interface {}{},
296+ baseTime : baseTime ,
297+ },
298+ []string {"A" , "B" , "C" },
299+ false ,
300+ },
301+ {
302+ "Date Range - Invalid Date Format" ,
303+ args {
304+ params : & ConditionParams {},
305+ messages : []* graph.MessageInfo {
306+ {ID : "A" , StartDate : "invalid-date" },
307+ },
308+ lastReportMap : map [string ]interface {}{},
309+ baseTime : baseTime ,
310+ },
311+ []string {},
312+ true ,
313+ },
314+ {
315+ "Date Range - Only Start Date" ,
316+ args {
317+ params : & ConditionParams {},
318+ messages : []* graph.MessageInfo {
319+ {ID : "A" , StartDate : baseTime .Add (- 1 * time .Hour ).Format (time .RFC3339 )},
320+ {ID : "B" , StartDate : baseTime .Add (1 * time .Hour ).Format (time .RFC3339 )},
321+ },
322+ lastReportMap : map [string ]interface {}{},
323+ baseTime : baseTime ,
324+ },
325+ []string {"A" },
326+ false ,
327+ },
328+ {
329+ "Date Range - Only End Date" ,
330+ args {
331+ params : & ConditionParams {},
332+ messages : []* graph.MessageInfo {
333+ {ID : "A" , EndDate : baseTime .Add (1 * time .Hour ).Format (time .RFC3339 )},
334+ {ID : "B" , EndDate : baseTime .Add (- 1 * time .Hour ).Format (time .RFC3339 )},
335+ },
336+ lastReportMap : map [string ]interface {}{},
337+ baseTime : baseTime ,
338+ },
339+ []string {"A" },
340+ false ,
341+ },
270342 }
271343 for _ , tt := range tests {
272344 t .Run (tt .name , func (t * testing.T ) {
0 commit comments