Skip to content

Commit d040b81

Browse files
refactor: check for a specific error in tests
1 parent 59bc618 commit d040b81

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

provider/helpers/schedule_validation_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -516,22 +516,20 @@ func TestSchedulesOverlap(t *testing.T) {
516516
func TestValidateSchedules(t *testing.T) {
517517
t.Parallel()
518518
testCases := []struct {
519-
name string
520-
schedules []string
521-
expectErr bool
519+
name string
520+
schedules []string
521+
expectedErrMsg string
522522
}{
523523
// Basic validation
524524
{
525525
name: "Empty schedules",
526526
schedules: []string{},
527-
expectErr: false,
528527
},
529528
{
530529
name: "Single valid schedule",
531530
schedules: []string{
532531
"* 9-18 * * 1-5",
533532
},
534-
expectErr: false,
535533
},
536534

537535
// Non-overlapping schedules
@@ -541,15 +539,13 @@ func TestValidateSchedules(t *testing.T) {
541539
"* 9-12 * * 1-5",
542540
"* 13-18 * * 1-5",
543541
},
544-
expectErr: false,
545542
},
546543
{
547544
name: "Multiple valid non-overlapping schedules",
548545
schedules: []string{
549546
"* 9-18 * * 1-5",
550547
"* 9-13 * * 6,0",
551548
},
552-
expectErr: false,
553549
},
554550

555551
// Overlapping schedules
@@ -559,7 +555,7 @@ func TestValidateSchedules(t *testing.T) {
559555
"* 9-14 * * 1-5",
560556
"* 12-18 * * 1-5",
561557
},
562-
expectErr: true,
558+
expectedErrMsg: "schedules overlap: * 9-14 * * 1-5 and * 12-18 * * 1-5",
563559
},
564560
{
565561
name: "Three schedules with only second and third overlapping",
@@ -568,7 +564,7 @@ func TestValidateSchedules(t *testing.T) {
568564
"* 12-18 * * 1-5", // 12PM-6PM
569565
"* 15-20 * * 1-5", // 3PM-8PM (overlaps with second)
570566
},
571-
expectErr: true,
567+
expectedErrMsg: "schedules overlap: * 12-18 * * 1-5 and * 15-20 * * 1-5",
572568
},
573569
}
574570

@@ -577,8 +573,9 @@ func TestValidateSchedules(t *testing.T) {
577573
t.Run(testCase.name, func(t *testing.T) {
578574
t.Parallel()
579575
err := helpers.ValidateSchedules(testCase.schedules)
580-
if testCase.expectErr {
576+
if testCase.expectedErrMsg != "" {
581577
require.Error(t, err)
578+
require.Contains(t, err.Error(), testCase.expectedErrMsg)
582579
} else {
583580
require.NoError(t, err)
584581
}

0 commit comments

Comments
 (0)