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

Function TestVSCodeSSH

cli/vscodessh_test.go:26–93  ·  view source on GitHub ↗

TestVSCodeSSH ensures the agent connects properly with SSH and that network information is properly written to the FS.

(t *testing.T)

Source from the content-addressed store, hash-verified

24// TestVSCodeSSH ensures the agent connects properly with SSH
25// and that network information is properly written to the FS.
26func TestVSCodeSSH(t *testing.T) {
27 t.Parallel()
28 ctx := testutil.Context(t, testutil.WaitLong)
29 dv := coderdtest.DeploymentValues(t)
30 dv.Experiments = []string{string(codersdk.ExperimentWorkspaceUsage)}
31 batcher := &workspacestatstest.StatsBatcher{
32 LastStats: &agentproto.Stats{},
33 }
34 admin, store := coderdtest.NewWithDatabase(t, &coderdtest.Options{
35 DeploymentValues: dv,
36 StatsBatcher: batcher,
37 })
38 admin.SetLogger(testutil.Logger(t).Named("client"))
39 first := coderdtest.CreateFirstUser(t, admin)
40 client, user := coderdtest.CreateAnotherUser(t, admin, first.OrganizationID)
41 r := dbfake.WorkspaceBuild(t, store, database.WorkspaceTable{
42 OrganizationID: first.OrganizationID,
43 OwnerID: user.ID,
44 }).WithAgent().Do()
45 workspace := r.Workspace
46 agentToken := r.AgentToken
47
48 user, err := client.User(ctx, codersdk.Me)
49 require.NoError(t, err)
50
51 _ = agenttest.New(t, client.URL, agentToken)
52 _ = coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
53
54 fs := afero.NewMemMapFs()
55 err = afero.WriteFile(fs, "/url", []byte(client.URL.String()), 0o600)
56 require.NoError(t, err)
57 err = afero.WriteFile(fs, "/token", []byte(client.SessionToken()), 0o600)
58 require.NoError(t, err)
59
60 //nolint:revive,staticcheck
61 ctx = context.WithValue(ctx, "fs", fs)
62
63 inv, _ := clitest.New(t,
64 "vscodessh",
65 "--url-file", "/url",
66 "--session-token-file", "/token",
67 "--network-info-dir", "/net",
68 "--log-dir", "/log",
69 "--network-info-interval", "25ms",
70 fmt.Sprintf("coder-vscode--%s--%s", user.Username, workspace.Name),
71 )
72 ptytest.New(t).Attach(inv)
73
74 waiter := clitest.StartWithWaiter(t, inv.WithContext(ctx))
75
76 for _, dir := range []string{"/net", "/log"} {
77 assert.Eventually(t, func() bool {
78 entries, err := afero.ReadDir(fs, dir)
79 if err != nil {
80 return false
81 }
82 return len(entries) > 0
83 }, testutil.WaitLong, testutil.IntervalFast)

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
DeploymentValuesFunction · 0.92
NewWithDatabaseFunction · 0.92
LoggerFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
WorkspaceBuildFunction · 0.92
NewFunction · 0.92
AwaitWorkspaceAgentsFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
StartWithWaiterFunction · 0.92

Tested by

no test coverage detected