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

Function TestSSH_OneShotCommandMode

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

Source from the content-addressed store, hash-verified

2369}
2370
2371func TestSSH_OneShotCommandMode(t *testing.T) {
2372 t.Parallel()
2373 if runtime.GOOS == "windows" {
2374 t.Skip("'test' shell command and wc are not available on Windows")
2375 }
2376
2377 client, workspace, agentToken := setupWorkspaceForAgent(t)
2378 _ = agenttest.New(t, client.URL, agentToken)
2379 coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
2380
2381 t.Run("DoesNotRequestPTY", func(t *testing.T) {
2382 t.Parallel()
2383
2384 output := new(bytes.Buffer)
2385 inv, root := clitest.New(t, "ssh", workspace.Name, "test -t 0 && echo tty || echo not-tty")
2386 clitest.SetupConfig(t, client, root)
2387 inv.Stdout = output
2388 inv.Stderr = io.Discard
2389
2390 ctx := testutil.Context(t, testutil.WaitShort)
2391 err := inv.WithContext(ctx).Run()
2392 require.NoError(t, err)
2393 require.Equal(t, "not-tty", strings.TrimSpace(output.String()))
2394 })
2395
2396 t.Run("RequestsPTYWithFlag", func(t *testing.T) {
2397 t.Parallel()
2398
2399 output := new(bytes.Buffer)
2400 inv, root := clitest.New(t, "ssh", "--tty", workspace.Name, "test -t 0 && echo tty || echo not-tty")
2401 clitest.SetupConfig(t, client, root)
2402 inv.Stdout = output
2403 inv.Stderr = io.Discard
2404
2405 ctx := testutil.Context(t, testutil.WaitShort)
2406 err := inv.WithContext(ctx).Run()
2407 require.NoError(t, err)
2408 require.Equal(t, "tty", strings.TrimSpace(output.String()))
2409 })
2410
2411 t.Run("ClosesStdinOnEOF", func(t *testing.T) {
2412 t.Parallel()
2413
2414 output := new(bytes.Buffer)
2415 inv, root := clitest.New(t, "ssh", workspace.Name, "wc -l")
2416 clitest.SetupConfig(t, client, root)
2417 inv.Stdin = strings.NewReader("a\nb\nc\n")
2418 inv.Stdout = output
2419 inv.Stderr = io.Discard
2420
2421 ctx := testutil.Context(t, testutil.WaitShort)
2422 err := inv.WithContext(ctx).Run()
2423 require.NoError(t, err)
2424 require.Equal(t, "3", strings.TrimSpace(output.String()))
2425 })
2426
2427 t.Run("PropagatesExitCode", func(t *testing.T) {
2428 t.Parallel()

Callers

nothing calls this directly

Calls 13

NewFunction · 0.92
AwaitWorkspaceAgentsFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
ContextFunction · 0.92
SkipMethod · 0.80
WithContextMethod · 0.80
ExitCodeMethod · 0.80
setupWorkspaceForAgentFunction · 0.70
RunMethod · 0.65
EqualMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected