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

Function TestScheduleModify

cli/schedule_test.go:260–331  ·  view source on GitHub ↗

nolint:paralleltest // t.Setenv

(t *testing.T)

Source from the content-addressed store, hash-verified

258
259//nolint:paralleltest // t.Setenv
260func TestScheduleModify(t *testing.T) {
261 // Given
262 // Set timezone to Asia/Kolkata to surface any timezone-related bugs.
263 t.Setenv("TZ", "Asia/Kolkata")
264 loc, err := tz.TimezoneIANA()
265 require.NoError(t, err)
266 require.Equal(t, "Asia/Kolkata", loc.String())
267 sched, err := cron.Weekly("CRON_TZ=Europe/Dublin 30 7 * * Mon-Fri")
268 require.NoError(t, err, "invalid schedule")
269 ownerClient, _, _, ws := setupTestSchedule(t, sched)
270 now := time.Now()
271
272 t.Run("SetStart", func(t *testing.T) {
273 // When: we set the start schedule
274 inv, root := clitest.New(t,
275 "schedule", "start", ws[3].OwnerName+"/"+ws[3].Name, "7:30AM", "Mon-Fri", "Europe/Dublin",
276 )
277 //nolint:gocritic // this workspace is not owned by the same user
278 clitest.SetupConfig(t, ownerClient, root)
279 pty := ptytest.New(t).Attach(inv)
280 require.NoError(t, inv.Run())
281
282 // Then: the updated schedule should be shown
283 pty.ExpectMatch(ws[3].OwnerName + "/" + ws[3].Name)
284 pty.ExpectMatch(sched.Humanize())
285 pty.ExpectMatch(sched.Next(now).In(loc).Format(time.RFC3339))
286 })
287
288 t.Run("SetStop", func(t *testing.T) {
289 // When: we set the stop schedule
290 inv, root := clitest.New(t,
291 "schedule", "stop", ws[2].OwnerName+"/"+ws[2].Name, "8h30m",
292 )
293 //nolint:gocritic // this workspace is not owned by the same user
294 clitest.SetupConfig(t, ownerClient, root)
295 pty := ptytest.New(t).Attach(inv)
296 require.NoError(t, inv.Run())
297
298 // Then: the updated schedule should be shown
299 pty.ExpectMatch(ws[2].OwnerName + "/" + ws[2].Name)
300 pty.ExpectMatch("8h30m")
301 pty.ExpectMatch(ws[2].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339))
302 })
303
304 t.Run("UnsetStart", func(t *testing.T) {
305 // When: we unset the start schedule
306 inv, root := clitest.New(t,
307 "schedule", "start", ws[1].OwnerName+"/"+ws[1].Name, "manual",
308 )
309 //nolint:gocritic // this workspace is owned by owner
310 clitest.SetupConfig(t, ownerClient, root)
311 pty := ptytest.New(t).Attach(inv)
312 require.NoError(t, inv.Run())
313
314 // Then: the updated schedule should be shown
315 pty.ExpectMatch(ws[1].OwnerName + "/" + ws[1].Name)
316 })
317

Callers

nothing calls this directly

Calls 15

TimezoneIANAFunction · 0.92
WeeklyFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
setupTestScheduleFunction · 0.85
SetenvMethod · 0.80
RunMethod · 0.65
AttachMethod · 0.65
FormatMethod · 0.65
NextMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected