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

Function TestSupportBundle

cli/support_test.go:43–251  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

41)
42
43func TestSupportBundle(t *testing.T) {
44 t.Parallel()
45 if runtime.GOOS == "windows" {
46 t.Skip("for some reason, windows fails to remove tempdirs sometimes")
47 }
48
49 // Support bundle tests can share a single coderdtest instance.
50 var dc codersdk.DeploymentConfig
51 dc.Values = coderdtest.DeploymentValues(t)
52 dc.Values.Prometheus.Enable = true
53 secretValue := uuid.NewString()
54 seedSecretDeploymentOptions(t, &dc, secretValue)
55 // Use a mock healthcheck function to avoid flaky DERP health
56 // checks in CI. The DERP checker performs real network operations
57 // (portmapper gateway probing, STUN) that can hang for 60s+ on
58 // macOS CI runners. Since this test validates support bundle
59 // generation, not healthcheck correctness, a canned report is
60 // sufficient.
61 client, closer, api := coderdtest.NewWithAPI(t, &coderdtest.Options{
62 DeploymentValues: dc.Values,
63 HealthcheckFunc: func(_ context.Context, _ string, _ *healthcheck.Progress) *healthsdk.HealthcheckReport {
64 return &healthsdk.HealthcheckReport{
65 Time: time.Now(),
66 Healthy: true,
67 Severity: health.SeverityOK,
68 }
69 },
70 })
71
72 t.Cleanup(func() { closer.Close() })
73 owner := coderdtest.CreateFirstUser(t, client)
74 memberClient, member := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
75
76 // Set up test fixtures
77 setupCtx := testutil.Context(t, testutil.WaitLong)
78 workspaceWithAgent := setupSupportBundleTestFixture(setupCtx, t, api.Database, owner.OrganizationID, owner.UserID, func(agents []*proto.Agent) []*proto.Agent {
79 // This should not show up in the bundle output
80 agents[0].Env["SECRET_VALUE"] = secretValue
81 return agents
82 })
83 workspaceWithoutAgent := setupSupportBundleTestFixture(setupCtx, t, api.Database, owner.OrganizationID, owner.UserID, nil)
84 memberWorkspace := setupSupportBundleTestFixture(setupCtx, t, api.Database, owner.OrganizationID, member.ID, nil)
85
86 t.Run("WorkspaceWithAgent", func(t *testing.T) {
87 t.Parallel()
88
89 tempDir := t.TempDir()
90 logPath := filepath.Join(tempDir, "coder-agent.log")
91 require.NoError(t, os.WriteFile(logPath, []byte("hello from the agent"), 0o600))
92 agt := agenttest.New(t, client.URL, workspaceWithAgent.AgentToken, func(o *agent.Options) {
93 o.LogDir = tempDir
94 })
95 defer agt.Close()
96 coderdtest.NewWorkspaceAgentWaiter(t, client, workspaceWithAgent.Workspace.ID).Wait()
97
98 d := t.TempDir()
99 path := filepath.Join(d, "bundle.zip")
100 inv, root := clitest.New(t, "support", "bundle", workspaceWithAgent.Workspace.Name, "--output-file", path, "--yes")

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
DeploymentValuesFunction · 0.92
NewWithAPIFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
ContextFunction · 0.92
NewFunction · 0.92
NewWorkspaceAgentWaiterFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92

Tested by

no test coverage detected