(t *testing.T)
| 68 | ) |
| 69 | |
| 70 | func TestWorkspaceAgent(t *testing.T) { |
| 71 | t.Parallel() |
| 72 | t.Run("Connect", func(t *testing.T) { |
| 73 | t.Parallel() |
| 74 | client, db := coderdtest.NewWithDatabase(t, nil) |
| 75 | user := coderdtest.CreateFirstUser(t, client) |
| 76 | tmpDir := t.TempDir() |
| 77 | anotherClient, anotherUser := coderdtest.CreateAnotherUser(t, client, user.OrganizationID) |
| 78 | |
| 79 | r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 80 | OrganizationID: user.OrganizationID, |
| 81 | OwnerID: anotherUser.ID, |
| 82 | }).WithAgent(func(agents []*proto.Agent) []*proto.Agent { |
| 83 | agents[0].Directory = tmpDir |
| 84 | return agents |
| 85 | }).Do() |
| 86 | |
| 87 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 88 | defer cancel() |
| 89 | workspace, err := anotherClient.Workspace(ctx, r.Workspace.ID) |
| 90 | require.NoError(t, err) |
| 91 | require.Equal(t, tmpDir, workspace.LatestBuild.Resources[0].Agents[0].Directory) |
| 92 | _, err = anotherClient.WorkspaceAgent(ctx, workspace.LatestBuild.Resources[0].Agents[0].ID) |
| 93 | require.NoError(t, err) |
| 94 | require.False(t, workspace.LatestBuild.Resources[0].Agents[0].Health.Healthy) |
| 95 | }) |
| 96 | t.Run("HasFallbackTroubleshootingURL", func(t *testing.T) { |
| 97 | t.Parallel() |
| 98 | client, db := coderdtest.NewWithDatabase(t, nil) |
| 99 | user := coderdtest.CreateFirstUser(t, client) |
| 100 | tmpDir := t.TempDir() |
| 101 | r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 102 | OrganizationID: user.OrganizationID, |
| 103 | OwnerID: user.UserID, |
| 104 | }).WithAgent(func(agents []*proto.Agent) []*proto.Agent { |
| 105 | agents[0].Directory = tmpDir |
| 106 | return agents |
| 107 | }).Do() |
| 108 | |
| 109 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium) |
| 110 | defer cancel() |
| 111 | |
| 112 | workspace, err := client.Workspace(ctx, r.Workspace.ID) |
| 113 | require.NoError(t, err) |
| 114 | require.NotEmpty(t, workspace.LatestBuild.Resources[0].Agents[0].TroubleshootingURL) |
| 115 | t.Log(workspace.LatestBuild.Resources[0].Agents[0].TroubleshootingURL) |
| 116 | }) |
| 117 | t.Run("Timeout", func(t *testing.T) { |
| 118 | t.Parallel() |
| 119 | // timeouts can cause error logs to be dropped on shutdown |
| 120 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug) |
| 121 | client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{ |
| 122 | Logger: &logger, |
| 123 | }) |
| 124 | user := coderdtest.CreateFirstUser(t, client) |
| 125 | tmpDir := t.TempDir() |
| 126 | |
| 127 | wantTroubleshootingURL := "https://example.com/troubleshoot" |
nothing calls this directly
no test coverage detected