(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func 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) { |
nothing calls this directly
no test coverage detected