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

Function TestPrebuildUpdateLifecycleParams

enterprise/coderd/workspaces_test.go:2733–2908  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2731}
2732
2733func TestPrebuildUpdateLifecycleParams(t *testing.T) {
2734 t.Parallel()
2735
2736 // Autostart schedule configuration set to weekly at 9:30 AM UTC
2737 autostartSchedule, err := cron.Weekly("CRON_TZ=UTC 30 9 * * 1-5")
2738 require.NoError(t, err)
2739
2740 // TTL configuration set to 8 hours
2741 ttlMillis := ptr.Ref((8 * time.Hour).Milliseconds())
2742
2743 // Deadline configuration set to January 1st, 2024 at 10:00 AM UTC
2744 deadline := time.Date(2024, 1, 1, 10, 0, 0, 0, time.UTC)
2745
2746 cases := []struct {
2747 name string
2748 endpoint func(*testing.T, context.Context, *codersdk.Client, uuid.UUID) error
2749 apiErrorMsg string
2750 assertUpdate func(*testing.T, *quartz.Mock, *codersdk.Client, uuid.UUID)
2751 }{
2752 {
2753 name: "AutostartUpdatePrebuildAfterClaim",
2754 endpoint: func(t *testing.T, ctx context.Context, client *codersdk.Client, workspaceID uuid.UUID) error {
2755 err = client.UpdateWorkspaceAutostart(ctx, workspaceID, codersdk.UpdateWorkspaceAutostartRequest{
2756 Schedule: ptr.Ref(autostartSchedule.String()),
2757 })
2758 return err
2759 },
2760 apiErrorMsg: "Autostart is not supported for prebuilt workspaces",
2761 assertUpdate: func(t *testing.T, clock *quartz.Mock, client *codersdk.Client, workspaceID uuid.UUID) {
2762 // The workspace's autostart schedule should be updated to the given schedule,
2763 // and its next start time should be set to 2024-01-01 09:30 AM UTC
2764 updatedWorkspace := coderdtest.MustWorkspace(t, client, workspaceID)
2765 require.Equal(t, autostartSchedule.String(), *updatedWorkspace.AutostartSchedule)
2766 require.Equal(t, autostartSchedule.Next(clock.Now()), updatedWorkspace.NextStartAt.UTC())
2767 expectedNext := time.Date(2024, 1, 1, 9, 30, 0, 0, time.UTC)
2768 require.Equal(t, expectedNext, updatedWorkspace.NextStartAt.UTC())
2769 },
2770 },
2771 {
2772 name: "TTLUpdatePrebuildAfterClaim",
2773 endpoint: func(t *testing.T, ctx context.Context, client *codersdk.Client, workspaceID uuid.UUID) error {
2774 err := client.UpdateWorkspaceTTL(ctx, workspaceID, codersdk.UpdateWorkspaceTTLRequest{
2775 TTLMillis: ttlMillis,
2776 })
2777 return err
2778 },
2779 apiErrorMsg: "TTL updates are not supported for prebuilt workspaces",
2780 assertUpdate: func(t *testing.T, clock *quartz.Mock, client *codersdk.Client, workspaceID uuid.UUID) {
2781 // The workspace's TTL should be updated accordingly
2782 updatedWorkspace := coderdtest.MustWorkspace(t, client, workspaceID)
2783 require.Equal(t, ttlMillis, updatedWorkspace.TTLMillis)
2784 },
2785 },
2786 {
2787 name: "DormantUpdatePrebuildAfterClaim",
2788 endpoint: func(t *testing.T, ctx context.Context, client *codersdk.Client, workspaceID uuid.UUID) error {
2789 err := client.UpdateWorkspaceDormancy(ctx, workspaceID, codersdk.UpdateWorkspaceDormancy{
2790 Dormant: true,

Callers

nothing calls this directly

Calls 15

StatusCodeMethod · 0.95
WeeklyFunction · 0.92
RefFunction · 0.92
MustWorkspaceFunction · 0.92
NewWithDatabaseFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
PresetFunction · 0.92
WorkspaceBuildFunction · 0.92
AsSystemRestrictedFunction · 0.92
ContextFunction · 0.92

Tested by

no test coverage detected