Skip to content

Commit

Permalink
DEVPROD-7549: error if creating sleep schedule that is always off (#7921
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Kimchelly committed May 28, 2024
1 parent 1b1bd01 commit 38f9667
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions model/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ func (i *SleepScheduleInfo) Validate() error {

catcher := grip.NewBasicCatcher()

catcher.NewWhen(len(i.WholeWeekdaysOff) == 7, "cannot create a sleep schedule where the host is off 24/7 since the host could never turn on")
catcher.NewWhen(len(i.WholeWeekdaysOff) == 0 && i.DailyStartTime == "" && i.DailyStopTime == "", "cannot specify an empty sleep schedule that's missing both daily stop/start time and whole days off")
catcher.NewWhen(i.TimeZone == "", "sleep schedule time zone must be set")
catcher.ErrorfWhen(i.DailyStopTime != "" && i.DailyStartTime == "", "cannot specify a daily stop time without a daily start time")
Expand Down
6 changes: 6 additions & 0 deletions model/host/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6272,6 +6272,12 @@ func TestSleepScheduleInfoValidate(t *testing.T) {
TimeZone: "America/New_York",
}).Validate())
})
t.Run("FailsWithAllWeekdaysOff", func(t *testing.T) {
assert.Error(t, (&SleepScheduleInfo{
WholeWeekdaysOff: []time.Weekday{time.Sunday, time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday, time.Saturday},
TimeZone: "America/New_York",
}).Validate())
})
}

func TestUpdateSleepSchedule(t *testing.T) {
Expand Down

0 comments on commit 38f9667

Please sign in to comment.