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

Function TestWorkspaceUpdateAutostart

coderd/workspaces_test.go:3183–3379  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3181}
3182
3183func TestWorkspaceUpdateAutostart(t *testing.T) {
3184 t.Parallel()
3185 dublinLoc := mustLocation(t, "Europe/Dublin")
3186
3187 testCases := []struct {
3188 name string
3189 schedule *string
3190 expectedError string
3191 at time.Time
3192 expectedNext time.Time
3193 expectedInterval time.Duration
3194 }{
3195 {
3196 name: "disable autostart",
3197 schedule: ptr.Ref(""),
3198 expectedError: "",
3199 },
3200 {
3201 name: "friday to monday",
3202 schedule: ptr.Ref("CRON_TZ=Europe/Dublin 30 9 * * 1-5"),
3203 expectedError: "",
3204 at: time.Date(2022, 5, 6, 9, 31, 0, 0, dublinLoc),
3205 expectedNext: time.Date(2022, 5, 9, 9, 30, 0, 0, dublinLoc),
3206 expectedInterval: 71*time.Hour + 59*time.Minute,
3207 },
3208 {
3209 name: "monday to tuesday",
3210 schedule: ptr.Ref("CRON_TZ=Europe/Dublin 30 9 * * 1-5"),
3211 expectedError: "",
3212 at: time.Date(2022, 5, 9, 9, 31, 0, 0, dublinLoc),
3213 expectedNext: time.Date(2022, 5, 10, 9, 30, 0, 0, dublinLoc),
3214 expectedInterval: 23*time.Hour + 59*time.Minute,
3215 },
3216 {
3217 // DST in Ireland began on Mar 27 in 2022 at 0100. Forward 1 hour.
3218 name: "DST start",
3219 schedule: ptr.Ref("CRON_TZ=Europe/Dublin 30 9 * * *"),
3220 expectedError: "",
3221 at: time.Date(2022, 3, 26, 9, 31, 0, 0, dublinLoc),
3222 expectedNext: time.Date(2022, 3, 27, 9, 30, 0, 0, dublinLoc),
3223 expectedInterval: 22*time.Hour + 59*time.Minute,
3224 },
3225 {
3226 // DST in Ireland ends on Oct 30 in 2022 at 0200. Back 1 hour.
3227 name: "DST end",
3228 schedule: ptr.Ref("CRON_TZ=Europe/Dublin 30 9 * * *"),
3229 expectedError: "",
3230 at: time.Date(2022, 10, 29, 9, 31, 0, 0, dublinLoc),
3231 expectedNext: time.Date(2022, 10, 30, 9, 30, 0, 0, dublinLoc),
3232 expectedInterval: 24*time.Hour + 59*time.Minute,
3233 },
3234 {
3235 name: "invalid location",
3236 schedule: ptr.Ref("CRON_TZ=Imaginary/Place 30 9 * * 1-5"),
3237 expectedError: "parse schedule: provided bad location Imaginary/Place: unknown time zone Imaginary/Place",
3238 },
3239 {
3240 name: "invalid schedule",

Callers

nothing calls this directly

Calls 15

RefFunction · 0.92
NewMockFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
CreateWorkspaceFunction · 0.92
WeeklyFunction · 0.92
ContextFunction · 0.92
WorkspaceMethod · 0.80

Tested by

no test coverage detected