MCPcopy Create free account
hub / github.com/coder/coder / TestPrebuildsPause

Function TestPrebuildsPause

enterprise/cli/prebuilds_test.go:31–137  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func TestPrebuildsPause(t *testing.T) {
32 t.Parallel()
33
34 t.Run("Success", func(t *testing.T) {
35 t.Parallel()
36
37 client, _ := coderdenttest.New(t, &coderdenttest.Options{
38 LicenseOptions: &coderdenttest.LicenseOptions{
39 Features: license.Features{
40 codersdk.FeatureWorkspacePrebuilds: 1,
41 },
42 },
43 })
44
45 inv, conf := newCLI(t, "prebuilds", "pause")
46 var buf bytes.Buffer
47 inv.Stderr = &buf
48 //nolint:gocritic // Only owners can change deployment settings
49 clitest.SetupConfig(t, client, conf)
50
51 err := inv.Run()
52 require.NoError(t, err)
53
54 // Verify the output message
55 assert.Contains(t, buf.String(), "Prebuilds are now paused.")
56
57 // Verify the settings were actually updated
58 //nolint:gocritic // Only owners can change deployment settings
59 settings, err := client.GetPrebuildsSettings(inv.Context())
60 require.NoError(t, err)
61 assert.True(t, settings.ReconciliationPaused)
62 })
63
64 t.Run("UnauthorizedUser", func(t *testing.T) {
65 t.Parallel()
66
67 adminClient, admin := coderdenttest.New(t, &coderdenttest.Options{
68 LicenseOptions: &coderdenttest.LicenseOptions{
69 Features: license.Features{
70 codersdk.FeatureWorkspacePrebuilds: 1,
71 },
72 },
73 })
74
75 // Create a regular user without admin privileges
76 client, _ := coderdtest.CreateAnotherUser(t, adminClient, admin.OrganizationID)
77
78 inv, conf := newCLI(t, "prebuilds", "pause")
79 clitest.SetupConfig(t, client, conf)
80
81 err := inv.Run()
82 require.Error(t, err)
83 var sdkError *codersdk.Error
84 require.ErrorAsf(t, err, &sdkError, "error should be of type *codersdk.Error")
85 assert.Equal(t, http.StatusForbidden, sdkError.StatusCode())
86 })
87
88 t.Run("NoLicense", func(t *testing.T) {

Callers

nothing calls this directly

Calls 12

StatusCodeMethod · 0.95
NewFunction · 0.92
SetupConfigFunction · 0.92
CreateAnotherUserFunction · 0.92
newCLIFunction · 0.85
RunMethod · 0.65
GetPrebuildsSettingsMethod · 0.65
ContextMethod · 0.65
ContainsMethod · 0.45
StringMethod · 0.45
ErrorMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected