MCPcopy Index your code
hub / github.com/coder/coder / TestNextAllowedAutostart

Function TestNextAllowedAutostart

coderd/schedule/autostart_test.go:12–41  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestNextAllowedAutostart(t *testing.T) {
13 t.Parallel()
14
15 t.Run("WhenScheduleOutOfSync", func(t *testing.T) {
16 t.Parallel()
17
18 // 1st January 2024 is a Monday
19 at := time.Date(2024, time.January, 1, 10, 0, 0, 0, time.UTC)
20 // Monday-Friday 9:00AM UTC
21 sched := "CRON_TZ=UTC 00 09 * * 1-5"
22 // Only allow an autostart on mondays
23 opts := schedule.TemplateScheduleOptions{
24 AutostartRequirement: schedule.TemplateAutostartRequirement{
25 DaysOfWeek: 0b00000001,
26 },
27 }
28
29 // NextAutostart will return a non-allowed autostart time as
30 // our AutostartRequirement only allows Mondays but we expect
31 // this to return a Tuesday.
32 next, allowed := schedule.NextAutostart(at, sched, opts)
33 require.False(t, allowed)
34 require.Equal(t, time.Date(2024, time.January, 2, 9, 0, 0, 0, time.UTC), next)
35
36 // NextAllowedAutostart should return the next allowed autostart time.
37 next, err := schedule.NextAllowedAutostart(at, sched, opts)
38 require.NoError(t, err)
39 require.Equal(t, time.Date(2024, time.January, 8, 9, 0, 0, 0, time.UTC), next)
40 })
41}

Callers

nothing calls this directly

Calls 4

NextAutostartFunction · 0.92
NextAllowedAutostartFunction · 0.92
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected