@@ -12,11 +12,14 @@ import (
1212"github.com/coder/coder/v2/coderd/rbac"
1313"github.com/coder/coder/v2/coderd/schedule/cron"
1414"github.com/coder/coder/v2/codersdk"
15+ "github.com/coder/coder/v2/enterprise/coderd"
1516"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
1617"github.com/coder/coder/v2/enterprise/coderd/license"
1718"github.com/coder/coder/v2/testutil"
1819)
1920
21+ const TimeFormatHHMM = coderd .TimeFormatHHMM
22+
2023func TestUserQuietHours (t * testing.T ) {
2124t .Parallel ()
2225
@@ -42,15 +45,17 @@ func TestUserQuietHours(t *testing.T) {
4245
4346t .Run ("OK" ,func (t * testing.T ) {
4447t .Parallel ()
45-
46- defaultQuietHoursSchedule := "CRON_TZ=America/Chicago 0 1 * * *"
48+ // Using 10 for minutes lets us test a format bug in which values greater
49+ // than 5 were causing the API to explode because the time was returned
50+ // incorrectly
51+ defaultQuietHoursSchedule := "CRON_TZ=America/Chicago 10 1 * * *"
4752defaultScheduleParsed ,err := cron .Daily (defaultQuietHoursSchedule )
4853require .NoError (t ,err )
4954nextTime := defaultScheduleParsed .Next (time .Now ().In (defaultScheduleParsed .Location ()))
5055if time .Until (nextTime )< time .Hour {
5156// Use a different default schedule instead, because we want to avoid
5257// the schedule "ticking over" during this test run.
53- defaultQuietHoursSchedule = "CRON_TZ=America/Chicago0 13 * * *"
58+ defaultQuietHoursSchedule = "CRON_TZ=America/Chicago10 13 * * *"
5459defaultScheduleParsed ,err = cron .Daily (defaultQuietHoursSchedule )
5560require .NoError (t ,err )
5661}
@@ -79,7 +84,7 @@ func TestUserQuietHours(t *testing.T) {
7984require .NoError (t ,err )
8085require .Equal (t ,defaultScheduleParsed .String (),sched1 .RawSchedule )
8186require .False (t ,sched1 .UserSet )
82- require .Equal (t ,defaultScheduleParsed .TimeParsed ().Format ("15:40" ),sched1 .Time )
87+ require .Equal (t ,defaultScheduleParsed .TimeParsed ().Format (TimeFormatHHMM ),sched1 .Time )
8388require .Equal (t ,defaultScheduleParsed .Location ().String (),sched1 .Timezone )
8489require .WithinDuration (t ,defaultScheduleParsed .Next (time .Now ()),sched1 .Next ,15 * time .Second )
8590
@@ -102,7 +107,7 @@ func TestUserQuietHours(t *testing.T) {
102107require .NoError (t ,err )
103108require .Equal (t ,customScheduleParsed .String (),sched2 .RawSchedule )
104109require .True (t ,sched2 .UserSet )
105- require .Equal (t ,customScheduleParsed .TimeParsed ().Format ("15:40" ),sched2 .Time )
110+ require .Equal (t ,customScheduleParsed .TimeParsed ().Format (TimeFormatHHMM ),sched2 .Time )
106111require .Equal (t ,customScheduleParsed .Location ().String (),sched2 .Timezone )
107112require .WithinDuration (t ,customScheduleParsed .Next (time .Now ()),sched2 .Next ,15 * time .Second )
108113
@@ -111,7 +116,7 @@ func TestUserQuietHours(t *testing.T) {
111116require .NoError (t ,err )
112117require .Equal (t ,customScheduleParsed .String (),sched3 .RawSchedule )
113118require .True (t ,sched3 .UserSet )
114- require .Equal (t ,customScheduleParsed .TimeParsed ().Format ("15:40" ),sched3 .Time )
119+ require .Equal (t ,customScheduleParsed .TimeParsed ().Format (TimeFormatHHMM ),sched3 .Time )
115120require .Equal (t ,customScheduleParsed .Location ().String (),sched3 .Timezone )
116121require .WithinDuration (t ,customScheduleParsed .Next (time .Now ()),sched3 .Next ,15 * time .Second )
117122