Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVPROD-7549: error if creating sleep schedule that is always off #7921

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading