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

Function TestConfigSSH

cli/configssh_test.go:60–170  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

58}
59
60func TestConfigSSH(t *testing.T) {
61 t.Parallel()
62
63 if runtime.GOOS == "windows" {
64 t.Skip("See coder/internal#117")
65 }
66
67 const hostname = "test-coder."
68 const expectedKey = "ConnectionAttempts"
69 const removeKey = "ConnectTimeout"
70 client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{
71 ConfigSSH: codersdk.SSHConfigResponse{
72 HostnamePrefix: hostname,
73 SSHConfigOptions: map[string]string{
74 // Something we can test for
75 expectedKey: "3",
76 removeKey: "",
77 },
78 },
79 })
80 owner := coderdtest.CreateFirstUser(t, client)
81 member, memberUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
82 r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
83 OrganizationID: owner.OrganizationID,
84 OwnerID: memberUser.ID,
85 }).WithAgent().Do()
86 _ = agenttest.New(t, client.URL, r.AgentToken)
87 resources := coderdtest.AwaitWorkspaceAgents(t, client, r.Workspace.ID)
88 agentConn, err := workspacesdk.New(client).
89 DialAgent(context.Background(), resources[0].Agents[0].ID, nil)
90 require.NoError(t, err)
91 defer agentConn.Close()
92
93 listener, err := net.Listen("tcp", "127.0.0.1:0")
94 require.NoError(t, err)
95 defer func() {
96 _ = listener.Close()
97 }()
98 copyDone := make(chan struct{})
99 go func() {
100 defer close(copyDone)
101 var wg sync.WaitGroup
102 for {
103 conn, err := listener.Accept()
104 if err != nil {
105 break
106 }
107 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
108 ssh, err := agentConn.SSH(ctx)
109 cancel()
110 assert.NoError(t, err)
111 wg.Add(2)
112 go func() {
113 defer wg.Done()
114 _, _ = io.Copy(conn, ssh)
115 }()
116 go func() {
117 defer wg.Done()

Callers

nothing calls this directly

Calls 15

NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
WorkspaceBuildFunction · 0.92
NewFunction · 0.92
AwaitWorkspaceAgentsFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
StartWithWaiterFunction · 0.92
sshConfigFileNameFunction · 0.85

Tested by

no test coverage detected