setupProxyTestWithFactory does the following: 1. Create a deployment with the factory. 2. Start a test app server. 3. Create a template version, template and workspace with many apps. 4. Start a workspace agent. 5. Returns details about the deployment and its apps.
(t *testing.T, factory DeploymentFactory, opts *DeploymentOptions)
| 186 | // 4. Start a workspace agent. |
| 187 | // 5. Returns details about the deployment and its apps. |
| 188 | func setupProxyTestWithFactory(t *testing.T, factory DeploymentFactory, opts *DeploymentOptions) *Details { |
| 189 | if opts == nil { |
| 190 | opts = &DeploymentOptions{} |
| 191 | } |
| 192 | if opts.AppHost == "" { |
| 193 | opts.AppHost = proxyTestSubdomainRaw |
| 194 | } |
| 195 | if opts.DisableSubdomainApps { |
| 196 | opts.AppHost = "" |
| 197 | } |
| 198 | if opts.StatsCollectorOptions.ReportInterval == 0 { |
| 199 | // Set to a really high value to avoid triggering flush without manually |
| 200 | // calling the function in test. This can easily happen because the |
| 201 | // default value is 30s and we run tests in parallel. The assertion |
| 202 | // typically happens such that: |
| 203 | // |
| 204 | // [use workspace] -> [fetch previous last used] -> [flush] -> [fetch new last used] |
| 205 | // |
| 206 | // When this edge case is triggered: |
| 207 | // |
| 208 | // [use workspace] -> [report interval flush] -> [fetch previous last used] -> [flush] -> [fetch new last used] |
| 209 | // |
| 210 | // In this case, both the previous and new last used will be the same, |
| 211 | // breaking the test assertion. |
| 212 | opts.StatsCollectorOptions.ReportInterval = 9001 * time.Hour |
| 213 | } |
| 214 | |
| 215 | deployment := factory(t, opts) |
| 216 | |
| 217 | // Configure the HTTP client to not follow redirects and to route all |
| 218 | // requests regardless of hostname to the coderd test server. |
| 219 | deployment.SDKClient.HTTPClient.CheckRedirect = func(_ *http.Request, _ []*http.Request) error { |
| 220 | return http.ErrUseLastResponse |
| 221 | } |
| 222 | forceURLTransport(t, deployment.SDKClient) |
| 223 | |
| 224 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium) |
| 225 | defer cancel() |
| 226 | |
| 227 | me, err := deployment.SDKClient.User(ctx, codersdk.Me) |
| 228 | require.NoError(t, err) |
| 229 | |
| 230 | if opts.noWorkspace { |
| 231 | return &Details{ |
| 232 | Deployment: deployment, |
| 233 | Me: me, |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | if opts.port == 0 { |
| 238 | opts.port = appServer(t, opts.headers, opts.ServeHTTPS, opts.handler) |
| 239 | } |
| 240 | workspace, agnt := createWorkspaceWithApps(t, deployment.SDKClient, deployment.FirstUser.OrganizationID, me, opts.port, opts.ServeHTTPS) |
| 241 | |
| 242 | details := &Details{ |
| 243 | Deployment: deployment, |
| 244 | Me: me, |
| 245 | Workspace: &workspace, |
no test coverage detected