nolint:paralleltest // t.Setenv
(t *testing.T)
| 332 | |
| 333 | //nolint:paralleltest // t.Setenv |
| 334 | func TestScheduleOverride(t *testing.T) { |
| 335 | tests := []struct { |
| 336 | command string |
| 337 | }{ |
| 338 | {command: "extend"}, |
| 339 | // test for backwards compatibility |
| 340 | {command: "override-stop"}, |
| 341 | } |
| 342 | |
| 343 | for _, tt := range tests { |
| 344 | t.Run(tt.command, func(t *testing.T) { |
| 345 | // Given |
| 346 | // Set timezone to Asia/Kolkata to surface any timezone-related bugs. |
| 347 | t.Setenv("TZ", "Asia/Kolkata") |
| 348 | loc, err := tz.TimezoneIANA() |
| 349 | require.NoError(t, err) |
| 350 | require.Equal(t, "Asia/Kolkata", loc.String()) |
| 351 | sched, err := cron.Weekly("CRON_TZ=Europe/Dublin 30 7 * * Mon-Fri") |
| 352 | require.NoError(t, err, "invalid schedule") |
| 353 | ownerClient, _, _, ws := setupTestSchedule(t, sched) |
| 354 | now := time.Now() |
| 355 | |
| 356 | // When: we override the stop schedule |
| 357 | inv, root := clitest.New(t, |
| 358 | "schedule", tt.command, ws[0].OwnerName+"/"+ws[0].Name, "10h", |
| 359 | ) |
| 360 | |
| 361 | clitest.SetupConfig(t, ownerClient, root) |
| 362 | pty := ptytest.New(t).Attach(inv) |
| 363 | require.NoError(t, inv.Run()) |
| 364 | |
| 365 | // Fetch the workspace to get the actual deadline set by the |
| 366 | // server. Computing our own expected deadline from a separately |
| 367 | // captured time.Now() is racy: the CLI command calls time.Now() |
| 368 | // internally, and with the Asia/Kolkata +05:30 offset the hour |
| 369 | // boundary falls at :30 UTC minutes. A small delay between our |
| 370 | // time.Now() and the command's is enough to land in different |
| 371 | // hours. |
| 372 | updated, err := ownerClient.Workspace(context.Background(), ws[0].ID) |
| 373 | require.NoError(t, err) |
| 374 | require.False(t, updated.LatestBuild.Deadline.IsZero(), "deadline should be set after extend") |
| 375 | require.WithinDuration(t, now.Add(10*time.Hour), updated.LatestBuild.Deadline.Time, 5*time.Minute) |
| 376 | expectedDeadline := updated.LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339) |
| 377 | |
| 378 | // Then: the updated schedule should be shown |
| 379 | pty.ExpectMatch(ws[0].OwnerName + "/" + ws[0].Name) |
| 380 | pty.ExpectMatch(sched.Humanize()) |
| 381 | pty.ExpectMatch(sched.Next(now).In(loc).Format(time.RFC3339)) |
| 382 | pty.ExpectMatch("8h") |
| 383 | pty.ExpectMatch(expectedDeadline) |
| 384 | }) |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | //nolint:paralleltest // t.Setenv |
| 389 | func TestScheduleStart_TemplateAutostartRequirement(t *testing.T) { |
nothing calls this directly
no test coverage detected