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

Function createWorkspaceWithApps

coderd/workspaceapps/apptest/setup.go:366–556  ·  view source on GitHub ↗

nolint:revive

(t *testing.T, client *codersdk.Client, orgID uuid.UUID, me codersdk.User, port uint16, serveHTTPS bool, workspaceMutators ...func(*codersdk.CreateWorkspaceRequest))

Source from the content-addressed store, hash-verified

364
365//nolint:revive
366func createWorkspaceWithApps(t *testing.T, client *codersdk.Client, orgID uuid.UUID, me codersdk.User, port uint16, serveHTTPS bool, workspaceMutators ...func(*codersdk.CreateWorkspaceRequest)) (codersdk.Workspace, codersdk.WorkspaceAgent) {
367 authToken := uuid.NewString()
368
369 scheme := "http"
370 if serveHTTPS {
371 scheme = "https"
372 }
373
374 // Workspace name needs to be short to avoid hitting 62 char hostname
375 // segment limit.
376 workspaceName, err := cryptorand.String(6)
377 require.NoError(t, err)
378 workspaceName = "ws-" + workspaceName
379 workspaceMutators = append([]func(*codersdk.CreateWorkspaceRequest){
380 func(req *codersdk.CreateWorkspaceRequest) {
381 req.Name = workspaceName
382 },
383 }, workspaceMutators...)
384
385 // Intentionally going to choose a port that will never be chosen.
386 // Ports <1k will never be selected. 396 is for some old OS over IP.
387 // It will never likely be provisioned. Using quick timeout since
388 // it's all localhost
389 fakeAppURL := "http://127.1.0.1:396"
390 conn, err := net.DialTimeout("tcp", fakeAppURL, time.Millisecond*100)
391 if err == nil {
392 // In the absolute rare case someone hits this. Writing code to find a free port
393 // seems like a waste of time to program and run.
394 _ = conn.Close()
395 t.Errorf("an unused port is required for the fake app. "+
396 "The url %q happens to be an active port. If you hit this, then this test"+
397 "will need to be modified to run on your system. Or you can stop serving an"+
398 "app on that port.", fakeAppURL)
399 t.FailNow()
400 }
401
402 appURL := fmt.Sprintf("%s://127.0.0.1:%d?%s", scheme, port, proxyTestAppQuery)
403 protoApps := []*proto.App{
404 {
405 Slug: proxyTestAppNameFake,
406 DisplayName: proxyTestAppNameFake,
407 SharingLevel: proto.AppSharingLevel_OWNER,
408 Url: fakeAppURL,
409 Subdomain: true,
410 },
411 {
412 Slug: proxyTestAppNameOwner,
413 DisplayName: proxyTestAppNameOwner,
414 SharingLevel: proto.AppSharingLevel_OWNER,
415 Url: appURL,
416 Subdomain: true,
417 },
418 {
419 Slug: proxyTestAppNameAuthenticated,
420 DisplayName: proxyTestAppNameAuthenticated,
421 SharingLevel: proto.AppSharingLevel_AUTHENTICATED,
422 Url: appURL,
423 Subdomain: true,

Callers 2

RunFunction · 0.85

Calls 15

StringMethod · 0.95
GetManifestMethod · 0.95
StringFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
CreateWorkspaceFunction · 0.92
NewFunction · 0.92
WithFixedTokenFunction · 0.92
ContextFunction · 0.92
NewFunction · 0.92

Tested by

no test coverage detected