Run runs the entire workspace app test suite against deployments minted by the provided factory. appHostIsPrimary is true if the app host is also the primary coder API server. This disables any tests that test API passthrough or rely on the app server not being the API server. nolint:revive
(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory)
| 43 | // app server not being the API server. |
| 44 | // nolint:revive |
| 45 | func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { |
| 46 | setupProxyTest := func(t *testing.T, opts *DeploymentOptions) *Details { |
| 47 | return setupProxyTestWithFactory(t, factory, opts) |
| 48 | } |
| 49 | |
| 50 | t.Run("ReconnectingPTY", func(t *testing.T) { |
| 51 | t.Parallel() |
| 52 | if runtime.GOOS == "windows" { |
| 53 | // This might be our implementation, or ConPTY itself. It's |
| 54 | // difficult to find extensive tests for it, so it seems like it |
| 55 | // could be either. |
| 56 | t.Skip("ConPTY appears to be inconsistent on Windows.") |
| 57 | } |
| 58 | |
| 59 | t.Run("OK", func(t *testing.T) { |
| 60 | t.Parallel() |
| 61 | appDetails := setupProxyTest(t, nil) |
| 62 | |
| 63 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 64 | defer cancel() |
| 65 | |
| 66 | // Run the test against the path app hostname since that's where the |
| 67 | // reconnecting-pty proxy server we want to test is mounted. |
| 68 | client := appDetails.AppClient(t) |
| 69 | testReconnectingPTY(ctx, t, client, appDetails.Agent.ID, "") |
| 70 | assertWorkspaceLastUsedAtUpdated(t, appDetails, testutil.WaitLong) |
| 71 | }) |
| 72 | |
| 73 | t.Run("SignedTokenQueryParameter", func(t *testing.T) { |
| 74 | t.Parallel() |
| 75 | |
| 76 | if appHostIsPrimary { |
| 77 | t.Skip("Tickets are not used for terminal requests on the primary.") |
| 78 | } |
| 79 | |
| 80 | appDetails := setupProxyTest(t, nil) |
| 81 | |
| 82 | u := *appDetails.PathAppBaseURL |
| 83 | if u.Scheme == "http" { |
| 84 | u.Scheme = "ws" |
| 85 | } else { |
| 86 | u.Scheme = "wss" |
| 87 | } |
| 88 | u.Path = fmt.Sprintf("/api/v2/workspaceagents/%s/pty", appDetails.Agent.ID.String()) |
| 89 | |
| 90 | ctx := testutil.Context(t, testutil.WaitLong) |
| 91 | issueRes, err := appDetails.SDKClient.IssueReconnectingPTYSignedToken(ctx, codersdk.IssueReconnectingPTYSignedTokenRequest{ |
| 92 | URL: u.String(), |
| 93 | AgentID: appDetails.Agent.ID, |
| 94 | }) |
| 95 | require.NoError(t, err) |
| 96 | |
| 97 | // Make an unauthenticated client. |
| 98 | unauthedAppClient := codersdk.New(appDetails.AppClient(t).URL) |
| 99 | testReconnectingPTY(ctx, t, unauthedAppClient, appDetails.Agent.ID, issueRes.SignedToken) |
| 100 | assertWorkspaceLastUsedAtUpdated(t, appDetails, testutil.WaitLong) |
| 101 | }) |
| 102 | }) |