@@ -177,16 +177,16 @@ func TestConfig_IsUnderMaintenance(t *testing.T) {
177
177
yes , no := true , false
178
178
now := time .Now ().UTC ()
179
179
scenarios := []struct {
180
- name string
181
- cfg * Config
182
- expected bool
180
+ name string
181
+ cfg * Config
182
+ expectedUnderMaintenance bool
183
183
}{
184
184
{
185
185
name : "disabled" ,
186
186
cfg : & Config {
187
187
Enabled : & no ,
188
188
},
189
- expected : false ,
189
+ expectedUnderMaintenance : false ,
190
190
},
191
191
{
192
192
name : "under-maintenance-explicitly-enabled" ,
@@ -195,23 +195,23 @@ func TestConfig_IsUnderMaintenance(t *testing.T) {
195
195
Start : fmt .Sprintf ("%02d:00" , now .Hour ()),
196
196
Duration : 2 * time .Hour ,
197
197
},
198
- expected : true ,
198
+ expectedUnderMaintenance : true ,
199
199
},
200
200
{
201
201
name : "under-maintenance-starting-now-for-2h" ,
202
202
cfg : & Config {
203
203
Start : fmt .Sprintf ("%02d:00" , now .Hour ()),
204
204
Duration : 2 * time .Hour ,
205
205
},
206
- expected : true ,
206
+ expectedUnderMaintenance : true ,
207
207
},
208
208
{
209
209
name : "under-maintenance-starting-now-for-8h" ,
210
210
cfg : & Config {
211
211
Start : fmt .Sprintf ("%02d:00" , now .Hour ()),
212
212
Duration : 8 * time .Hour ,
213
213
},
214
- expected : true ,
214
+ expectedUnderMaintenance : true ,
215
215
},
216
216
{
217
217
name : "under-maintenance-starting-now-for-8h-explicit-days" ,
@@ -220,7 +220,7 @@ func TestConfig_IsUnderMaintenance(t *testing.T) {
220
220
Duration : 8 * time .Hour ,
221
221
Every : []string {"Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday" },
222
222
},
223
- expected : true ,
223
+ expectedUnderMaintenance : true ,
224
224
},
225
225
{
226
226
name : "under-maintenance-starting-now-for-23h-explicit-days" ,
@@ -229,40 +229,40 @@ func TestConfig_IsUnderMaintenance(t *testing.T) {
229
229
Duration : 23 * time .Hour ,
230
230
Every : []string {"Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday" },
231
231
},
232
- expected : true ,
232
+ expectedUnderMaintenance : true ,
233
233
},
234
234
{
235
235
name : "under-maintenance-starting-4h-ago-for-8h" ,
236
236
cfg : & Config {
237
237
Start : fmt .Sprintf ("%02d:00" , normalizeHour (now .Hour ()- 4 )),
238
238
Duration : 8 * time .Hour ,
239
239
},
240
- expected : true ,
240
+ expectedUnderMaintenance : true ,
241
241
},
242
242
{
243
243
name : "under-maintenance-starting-22h-ago-for-23h" ,
244
244
cfg : & Config {
245
245
Start : fmt .Sprintf ("%02d:00" , normalizeHour (now .Hour ()- 22 )),
246
246
Duration : 23 * time .Hour ,
247
247
},
248
- expected : true ,
248
+ expectedUnderMaintenance : true ,
249
249
},
250
250
{
251
251
name : "under-maintenance-starting-22h-ago-for-24h" ,
252
252
cfg : & Config {
253
253
Start : fmt .Sprintf ("%02d:00" , normalizeHour (now .Hour ()- 22 )),
254
254
Duration : 24 * time .Hour ,
255
255
},
256
- expected : true ,
256
+ expectedUnderMaintenance : true ,
257
257
},
258
258
{
259
259
name : "under-maintenance-amsterdam-timezone-starting-now-for-2h" ,
260
260
cfg : & Config {
261
- Start : fmt .Sprintf ("%02d:00" , now .Hour ()),
261
+ Start : fmt .Sprintf ("%02d:00" , inTimezone ( now , "Europe/Amsterdam" , t ) .Hour ()),
262
262
Duration : 2 * time .Hour ,
263
263
Timezone : "Europe/Amsterdam" ,
264
264
},
265
- expected : true ,
265
+ expectedUnderMaintenance : true ,
266
266
},
267
267
{
268
268
name : "under-maintenance-perth-timezone-starting-now-for-2h" ,
@@ -271,7 +271,17 @@ func TestConfig_IsUnderMaintenance(t *testing.T) {
271
271
Duration : 2 * time .Hour ,
272
272
Timezone : "Australia/Perth" ,
273
273
},
274
- expected : true ,
274
+ expectedUnderMaintenance : true ,
275
+ },
276
+ {
277
+ name : "not-under-maintenance-los-angeles-timezone-starting-now-for-2h-today" ,
278
+ cfg : & Config {
279
+ Start : fmt .Sprintf ("%02d:00" , now .Hour ()),
280
+ Duration : 2 * time .Hour ,
281
+ Timezone : "America/Los_Angeles" ,
282
+ Every : []string {now .Weekday ().String ()},
283
+ },
284
+ expectedUnderMaintenance : false ,
275
285
},
276
286
{
277
287
name : "under-maintenance-utc-timezone-starting-now-for-2h" ,
@@ -280,23 +290,23 @@ func TestConfig_IsUnderMaintenance(t *testing.T) {
280
290
Duration : 2 * time .Hour ,
281
291
Timezone : "UTC" ,
282
292
},
283
- expected : true ,
293
+ expectedUnderMaintenance : true ,
284
294
},
285
295
{
286
296
name : "not-under-maintenance-starting-4h-ago-for-3h" ,
287
297
cfg : & Config {
288
298
Start : fmt .Sprintf ("%02d:00" , normalizeHour (now .Hour ()- 4 )),
289
299
Duration : 3 * time .Hour ,
290
300
},
291
- expected : false ,
301
+ expectedUnderMaintenance : false ,
292
302
},
293
303
{
294
304
name : "not-under-maintenance-starting-5h-ago-for-1h" ,
295
305
cfg : & Config {
296
306
Start : fmt .Sprintf ("%02d:00" , normalizeHour (now .Hour ()- 5 )),
297
307
Duration : time .Hour ,
298
308
},
299
- expected : false ,
309
+ expectedUnderMaintenance : false ,
300
310
},
301
311
{
302
312
name : "not-under-maintenance-today" ,
@@ -305,7 +315,7 @@ func TestConfig_IsUnderMaintenance(t *testing.T) {
305
315
Duration : time .Hour ,
306
316
Every : []string {now .Add (48 * time .Hour ).Weekday ().String ()},
307
317
},
308
- expected : false ,
318
+ expectedUnderMaintenance : false ,
309
319
},
310
320
{
311
321
name : "not-under-maintenance-today-with-24h-duration" ,
@@ -314,17 +324,7 @@ func TestConfig_IsUnderMaintenance(t *testing.T) {
314
324
Duration : 24 * time .Hour ,
315
325
Every : []string {now .Add (48 * time .Hour ).Weekday ().String ()},
316
326
},
317
- expected : false ,
318
- },
319
- {
320
- name : "not-under-maintenance-los-angeles-timezone-starting-now-for-2h-today" ,
321
- cfg : & Config {
322
- Start : fmt .Sprintf ("%02d:00" , now .Hour ()),
323
- Duration : 2 * time .Hour ,
324
- Timezone : "America/Los_Angeles" ,
325
- Every : []string {now .Weekday ().String ()},
326
- },
327
- expected : false ,
327
+ expectedUnderMaintenance : false ,
328
328
},
329
329
}
330
330
for _ , scenario := range scenarios {
@@ -335,8 +335,8 @@ func TestConfig_IsUnderMaintenance(t *testing.T) {
335
335
t .Fatal ("validation shouldn't have returned an error, got" , err )
336
336
}
337
337
isUnderMaintenance := scenario .cfg .IsUnderMaintenance ()
338
- if isUnderMaintenance != scenario .expected {
339
- t .Errorf ("expected %v, got %v" , scenario .expected , isUnderMaintenance )
338
+ if isUnderMaintenance != scenario .expectedUnderMaintenance {
339
+ t .Errorf ("expectedUnderMaintenance %v, got %v" , scenario .expectedUnderMaintenance , isUnderMaintenance )
340
340
t .Logf ("start=%v; duration=%v; now=%v" , scenario .cfg .Start , scenario .cfg .Duration , time .Now ().UTC ())
341
341
}
342
342
})
@@ -352,7 +352,6 @@ func normalizeHour(hour int) int {
352
352
353
353
func inTimezone (passedTime time.Time , timezone string , t * testing.T ) time.Time {
354
354
timezoneLocation , err := time .LoadLocation (timezone )
355
-
356
355
if err != nil {
357
356
t .Fatalf ("timezone %s did not load" , timezone )
358
357
}
0 commit comments