File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -478,3 +478,66 @@ func TestSchedulesOverlap(t *testing.T) {
478
478
})
479
479
}
480
480
}
481
+
482
+ func TestValidateSchedules (t * testing.T ) {
483
+ t .Parallel ()
484
+ testCases := []struct {
485
+ name string
486
+ schedules []string
487
+ expectErr bool
488
+ }{
489
+ // Basic validation
490
+ {
491
+ name : "Empty schedules" ,
492
+ schedules : []string {},
493
+ expectErr : false ,
494
+ },
495
+ {
496
+ name : "Single valid schedule" ,
497
+ schedules : []string {
498
+ "* 9-18 * * 1-5" ,
499
+ },
500
+ expectErr : false ,
501
+ },
502
+ {
503
+ name : "Multiple valid non-overlapping schedules" ,
504
+ schedules : []string {
505
+ "* 9-12 * * 1-5" ,
506
+ "* 13-18 * * 1-5" ,
507
+ },
508
+ expectErr : false ,
509
+ },
510
+
511
+ // Overlapping schedules
512
+ {
513
+ name : "Two overlapping schedules" ,
514
+ schedules : []string {
515
+ "* 9-14 * * 1-5" ,
516
+ "* 12-18 * * 1-5" ,
517
+ },
518
+ expectErr : true ,
519
+ },
520
+ {
521
+ name : "Three schedules with only second and third overlapping" ,
522
+ schedules : []string {
523
+ "* 9-11 * * 1-5" , // 9AM-11AM (no overlap)
524
+ "* 12-18 * * 1-5" , // 12PM-6PM
525
+ "* 15-20 * * 1-5" , // 3PM-8PM (overlaps with second)
526
+ },
527
+ expectErr : true ,
528
+ },
529
+ }
530
+
531
+ for _ , testCase := range testCases {
532
+ testCase := testCase
533
+ t .Run (testCase .name , func (t * testing.T ) {
534
+ t .Parallel ()
535
+ err := cron .ValidateSchedules (testCase .schedules )
536
+ if testCase .expectErr {
537
+ require .Error (t , err )
538
+ } else {
539
+ require .NoError (t , err )
540
+ }
541
+ })
542
+ }
543
+ }
You can’t perform that action at this time.
0 commit comments