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

Function TestLogsCmd

cli/logs_test.go:19–115  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestLogsCmd(t *testing.T) {
20 t.Parallel()
21
22 client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{})
23 owner := coderdtest.CreateFirstUser(t, client)
24 memberClient, memberUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
25
26 testWorkspace := func(t testing.TB, db database.Store, ownerID, orgID uuid.UUID) dbfake.WorkspaceResponse {
27 wb := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
28 OwnerID: memberUser.ID,
29 OrganizationID: owner.OrganizationID,
30 }).WithAgent().Do()
31 _ = dbgen.ProvisionerJobLog(t, db, database.ProvisionerJobLog{
32 JobID: wb.Build.JobID,
33 Output: "test provisioner log for build " + wb.Build.ID.String(),
34 })
35 for _, agt := range wb.Agents {
36 _ = dbgen.WorkspaceAgentLog(t, db, database.WorkspaceAgentLog{
37 AgentID: agt.ID,
38 Output: "test agent log for agent " + agt.ID.String(),
39 })
40 }
41 return wb
42 }
43
44 assertLogOutput := func(t testing.TB, wb dbfake.WorkspaceResponse, output string) {
45 t.Helper()
46 require.Contains(t, output, "test provisioner log for build "+wb.Build.ID.String())
47 for _, agt := range wb.Agents {
48 require.Contains(t, output, "test agent log for agent "+agt.ID.String())
49 }
50 }
51
52 assertAntagonist := func(t testing.TB, wb dbfake.WorkspaceResponse, output string) {
53 t.Helper()
54 require.NotContains(t, output, "test provisioner log for build "+wb.Build.ID.String())
55 for _, agt := range wb.Agents {
56 require.NotContains(t, output, "test agent log for agent "+agt.ID.String())
57 }
58 }
59
60 wb1 := testWorkspace(t, db, memberUser.ID, owner.OrganizationID)
61 wb2 := testWorkspace(t, db, owner.UserID, owner.OrganizationID)
62
63 t.Run("workspace not found", func(t *testing.T) {
64 t.Parallel()
65
66 inv, root := clitest.New(t, "logs", "doesnotexist")
67 clitest.SetupConfig(t, memberClient, root)
68 ctx := testutil.Context(t, testutil.WaitShort)
69 var stdout strings.Builder
70 inv.Stdout = &stdout
71 err := inv.WithContext(ctx).Run()
72 require.ErrorContains(t, err, "Resource not found or you do not have access to this resource")
73 })
74
75 // Note: not testing with --follow as it is inherently racy.
76 t.Run("current build", func(t *testing.T) {

Callers

nothing calls this directly

Calls 15

NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
WorkspaceBuildFunction · 0.92
ProvisionerJobLogFunction · 0.92
WorkspaceAgentLogFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
ContextFunction · 0.92
testWorkspaceStruct · 0.85
WithAgentMethod · 0.80
WithContextMethod · 0.80

Tested by

no test coverage detected