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

Function TestSSH_CoderConnect

cli/ssh_test.go:2151–2369  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2149}
2150
2151func TestSSH_CoderConnect(t *testing.T) {
2152 t.Parallel()
2153
2154 t.Run("Enabled", func(t *testing.T) {
2155 t.Parallel()
2156 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
2157 defer cancel()
2158
2159 fs := afero.NewMemMapFs()
2160 //nolint:revive,staticcheck
2161 ctx = context.WithValue(ctx, "fs", fs)
2162
2163 client, workspace, agentToken := setupWorkspaceForAgent(t)
2164 inv, root := clitest.New(t, "ssh", workspace.Name, "--network-info-dir", "/net", "--stdio")
2165 clitest.SetupConfig(t, client, root)
2166 _ = ptytest.New(t).Attach(inv)
2167
2168 ctx = cli.WithTestOnlyCoderConnectDialer(ctx, &fakeCoderConnectDialer{})
2169 ctx = withCoderConnectRunning(ctx)
2170
2171 errCh := make(chan error, 1)
2172 tGo(t, func() {
2173 err := inv.WithContext(ctx).Run()
2174 errCh <- err
2175 })
2176
2177 _ = agenttest.New(t, client.URL, agentToken)
2178 coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
2179
2180 err := testutil.TryReceive(ctx, t, errCh)
2181 // Our mock dialer will always fail with this error, if it was called
2182 require.ErrorContains(t, err, "dial coder connect host \"dev.myworkspace.myuser.coder:22\" over tcp")
2183
2184 // The network info file should be created since we passed `--stdio`
2185 entries, err := afero.ReadDir(fs, "/net")
2186 require.NoError(t, err)
2187 require.True(t, len(entries) > 0)
2188 })
2189
2190 t.Run("Disabled", func(t *testing.T) {
2191 t.Parallel()
2192 client, workspace, agentToken := setupWorkspaceForAgent(t)
2193
2194 _ = agenttest.New(t, client.URL, agentToken)
2195 coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
2196
2197 clientOutput, clientInput := io.Pipe()
2198 serverOutput, serverInput := io.Pipe()
2199 defer func() {
2200 for _, c := range []io.Closer{clientOutput, clientInput, serverOutput, serverInput} {
2201 _ = c.Close()
2202 }
2203 }()
2204
2205 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
2206 defer cancel()
2207
2208 inv, root := clitest.New(t, "ssh", "--force-new-tunnel", "--stdio", workspace.Name)

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
AwaitWorkspaceAgentsFunction · 0.92
TryReceiveFunction · 0.92
withCoderConnectRunningFunction · 0.85
tGoFunction · 0.85
tGoContextFunction · 0.85
WithContextMethod · 0.80

Tested by

no test coverage detected