(t *testing.T)
| 2493 | } |
| 2494 | |
| 2495 | func TestSSH_Completion(t *testing.T) { |
| 2496 | t.Parallel() |
| 2497 | |
| 2498 | t.Run("SingleAgent", func(t *testing.T) { |
| 2499 | t.Parallel() |
| 2500 | |
| 2501 | client, workspace, agentToken := setupWorkspaceForAgent(t) |
| 2502 | _ = agenttest.New(t, client.URL, agentToken) |
| 2503 | coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID) |
| 2504 | |
| 2505 | var stdout bytes.Buffer |
| 2506 | inv, root := clitest.New(t, "ssh", "") |
| 2507 | inv.Stdout = &stdout |
| 2508 | inv.Environ.Set("COMPLETION_MODE", "1") |
| 2509 | clitest.SetupConfig(t, client, root) |
| 2510 | |
| 2511 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium) |
| 2512 | defer cancel() |
| 2513 | |
| 2514 | err := inv.WithContext(ctx).Run() |
| 2515 | require.NoError(t, err) |
| 2516 | |
| 2517 | // For single-agent workspaces, the only completion should be the |
| 2518 | // bare workspace name. |
| 2519 | output := stdout.String() |
| 2520 | t.Logf("Completion output: %q", output) |
| 2521 | require.Contains(t, output, workspace.Name) |
| 2522 | }) |
| 2523 | |
| 2524 | t.Run("MultiAgent", func(t *testing.T) { |
| 2525 | t.Parallel() |
| 2526 | |
| 2527 | client, store := coderdtest.NewWithDatabase(t, nil) |
| 2528 | first := coderdtest.CreateFirstUser(t, client) |
| 2529 | userClient, user := coderdtest.CreateAnotherUserMutators(t, client, first.OrganizationID, nil, func(r *codersdk.CreateUserRequestWithOrgs) { |
| 2530 | r.Username = "multiuser" |
| 2531 | }) |
| 2532 | |
| 2533 | r := dbfake.WorkspaceBuild(t, store, database.WorkspaceTable{ |
| 2534 | Name: "multiworkspace", |
| 2535 | OrganizationID: first.OrganizationID, |
| 2536 | OwnerID: user.ID, |
| 2537 | }).WithAgent(func(agents []*proto.Agent) []*proto.Agent { |
| 2538 | return []*proto.Agent{ |
| 2539 | { |
| 2540 | Name: "agent1", |
| 2541 | Auth: &proto.Agent_Token{}, |
| 2542 | }, |
| 2543 | { |
| 2544 | Name: "agent2", |
| 2545 | Auth: &proto.Agent_Token{}, |
| 2546 | }, |
| 2547 | } |
| 2548 | }).Do() |
| 2549 | |
| 2550 | var stdout bytes.Buffer |
| 2551 | inv, root := clitest.New(t, "ssh", "") |
| 2552 | inv.Stdout = &stdout |
nothing calls this directly
no test coverage detected