nolint:paralleltest // t.Setenv
(t *testing.T)
| 81 | |
| 82 | //nolint:paralleltest // t.Setenv |
| 83 | func TestScheduleShow(t *testing.T) { |
| 84 | // Given |
| 85 | // Set timezone to Asia/Kolkata to surface any timezone-related bugs. |
| 86 | t.Setenv("TZ", "Asia/Kolkata") |
| 87 | loc, err := tz.TimezoneIANA() |
| 88 | require.NoError(t, err) |
| 89 | require.Equal(t, "Asia/Kolkata", loc.String()) |
| 90 | sched, err := cron.Weekly("CRON_TZ=Europe/Dublin 30 7 * * Mon-Fri") |
| 91 | require.NoError(t, err, "invalid schedule") |
| 92 | ownerClient, memberClient, _, ws := setupTestSchedule(t, sched) |
| 93 | now := time.Now() |
| 94 | |
| 95 | t.Run("OwnerNoArgs", func(t *testing.T) { |
| 96 | // When: owner specifies no args |
| 97 | inv, root := clitest.New(t, "schedule", "show") |
| 98 | //nolint:gocritic // Testing that owner user sees all |
| 99 | clitest.SetupConfig(t, ownerClient, root) |
| 100 | pty := ptytest.New(t).Attach(inv) |
| 101 | require.NoError(t, inv.Run()) |
| 102 | |
| 103 | // Then: they should see their own workspaces. |
| 104 | // 1st workspace: a-owner-ws1 has both autostart and autostop enabled. |
| 105 | pty.ExpectMatch(ws[0].OwnerName + "/" + ws[0].Name) |
| 106 | pty.ExpectMatch(sched.Humanize()) |
| 107 | pty.ExpectMatch(sched.Next(now).In(loc).Format(time.RFC3339)) |
| 108 | pty.ExpectMatch("8h") |
| 109 | pty.ExpectMatch(ws[0].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) |
| 110 | // 2nd workspace: b-owner-ws2 has only autostart enabled. |
| 111 | pty.ExpectMatch(ws[1].OwnerName + "/" + ws[1].Name) |
| 112 | pty.ExpectMatch(sched.Humanize()) |
| 113 | pty.ExpectMatch(sched.Next(now).In(loc).Format(time.RFC3339)) |
| 114 | }) |
| 115 | |
| 116 | t.Run("OwnerAll", func(t *testing.T) { |
| 117 | // When: owner lists all workspaces |
| 118 | inv, root := clitest.New(t, "schedule", "show", "--all") |
| 119 | //nolint:gocritic // Testing that owner user sees all |
| 120 | clitest.SetupConfig(t, ownerClient, root) |
| 121 | pty := ptytest.New(t).Attach(inv) |
| 122 | require.NoError(t, inv.Run()) |
| 123 | |
| 124 | // Then: they should see all workspaces |
| 125 | // 1st workspace: a-owner-ws1 has both autostart and autostop enabled. |
| 126 | pty.ExpectMatch(ws[0].OwnerName + "/" + ws[0].Name) |
| 127 | pty.ExpectMatch(sched.Humanize()) |
| 128 | pty.ExpectMatch(sched.Next(now).In(loc).Format(time.RFC3339)) |
| 129 | pty.ExpectMatch("8h") |
| 130 | pty.ExpectMatch(ws[0].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) |
| 131 | // 2nd workspace: b-owner-ws2 has only autostart enabled. |
| 132 | pty.ExpectMatch(ws[1].OwnerName + "/" + ws[1].Name) |
| 133 | pty.ExpectMatch(sched.Humanize()) |
| 134 | pty.ExpectMatch(sched.Next(now).In(loc).Format(time.RFC3339)) |
| 135 | // 3rd workspace: c-member-ws3 has only autostop enabled. |
| 136 | pty.ExpectMatch(ws[2].OwnerName + "/" + ws[2].Name) |
| 137 | pty.ExpectMatch("8h") |
| 138 | pty.ExpectMatch(ws[2].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) |
| 139 | // 4th workspace: d-member-ws4 has neither autostart nor autostop enabled. |
| 140 | pty.ExpectMatch(ws[3].OwnerName + "/" + ws[3].Name) |
nothing calls this directly
no test coverage detected