Skip to content

Commit c90e471

Browse files
committed
rename flag, extra test
1 parent dc1475d commit c90e471

File tree

4 files changed

+65
-35
lines changed

4 files changed

+65
-35
lines changed

cli/ssh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,8 @@ func (r *RootCmd) ssh() *serpent.Command {
665665
Hidden: true, // Hidden until this features is at least in beta.
666666
},
667667
{
668-
Flag: "force-tunnel",
669-
Description: "Force the use of a new tunnel to the workspace, even if the Coder Connect tunnel is available.",
668+
Flag: "force-new-tunnel",
669+
Description: "Force the creation of a new tunnel to the workspace, even if the Coder Connect tunnel is available.",
670670
Value: serpent.BoolOf(&forceTunnel),
671671
},
672672
sshDisableAutostartOption(serpent.BoolOf(&disableAutostart)),

cli/ssh_test.go

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,41 +2114,71 @@ func TestSSH_Container(t *testing.T) {
21142114
func TestSSH_CoderConnect(t *testing.T) {
21152115
t.Parallel()
21162116

2117-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
2118-
defer cancel()
2117+
t.Run("Enabled", func(t *testing.T) {
2118+
t.Parallel()
2119+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
2120+
defer cancel()
21192121

2120-
fs := afero.NewMemMapFs()
2121-
//nolint:revive,staticcheck
2122-
ctx = context.WithValue(ctx, "fs", fs)
2122+
fs := afero.NewMemMapFs()
2123+
//nolint:revive,staticcheck
2124+
ctx = context.WithValue(ctx, "fs", fs)
21232125

2124-
client, workspace, agentToken := setupWorkspaceForAgent(t)
2125-
inv, root := clitest.New(t, "ssh", workspace.Name, "--network-info-dir", "/net", "--stdio")
2126-
clitest.SetupConfig(t, client, root)
2127-
_ = ptytest.New(t).Attach(inv)
2126+
client, workspace, agentToken := setupWorkspaceForAgent(t)
2127+
inv, root := clitest.New(t, "ssh", workspace.Name, "--network-info-dir", "/net", "--stdio")
2128+
clitest.SetupConfig(t, client, root)
2129+
_ = ptytest.New(t).Attach(inv)
21282130

2129-
errCh := make(chan error, 1)
2130-
tGo(t, func() {
2131-
err := inv.WithContext(withCoderConnectRunning(ctx)).Run()
2132-
errCh <- err
2131+
errCh := make(chan error, 1)
2132+
tGo(t, func() {
2133+
err := inv.WithContext(withCoderConnectRunning(ctx)).Run()
2134+
errCh <- err
2135+
})
2136+
2137+
_ = agenttest.New(t, client.URL, agentToken)
2138+
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
2139+
2140+
err := testutil.TryReceive(ctx, t, errCh)
2141+
// Making an SSH server available here is difficult, so we'll just check
2142+
// the command attempts to dial it.
2143+
require.ErrorContains(t, err, "dial coder connect host")
2144+
require.ErrorContains(t, err, "dev.myworkspace.myuser.coder")
2145+
2146+
// The network info file should be created since we passed `--stdio`
2147+
assert.Eventually(t, func() bool {
2148+
entries, err := afero.ReadDir(fs, "/net")
2149+
if err != nil {
2150+
return false
2151+
}
2152+
return len(entries) > 0
2153+
}, testutil.WaitLong, testutil.IntervalFast)
21332154
})
21342155

2135-
_ = agenttest.New(t, client.URL, agentToken)
2136-
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
2156+
t.Run("Disabled", func(t *testing.T) {
2157+
t.Parallel()
21372158

2138-
err := testutil.TryReceive(ctx, t, errCh)
2139-
// Making an SSH server available here is difficult, so we'll just check
2140-
// the command attempts to dial it.
2141-
require.ErrorContains(t, err, "dial coder connect host")
2142-
require.ErrorContains(t, err, "dev.myworkspace.myuser.coder")
2143-
2144-
// The network info file should be created since we passed `--stdio`
2145-
assert.Eventually(t, func() bool {
2146-
entries, err := afero.ReadDir(fs, "/net")
2147-
if err != nil {
2148-
return false
2149-
}
2150-
return len(entries) > 0
2151-
}, testutil.WaitLong, testutil.IntervalFast)
2159+
client, workspace, agentToken := setupWorkspaceForAgent(t)
2160+
inv, root := clitest.New(t, "ssh", workspace.Name, "--force-new-tunnel")
2161+
clitest.SetupConfig(t, client, root)
2162+
pty := ptytest.New(t).Attach(inv)
2163+
2164+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
2165+
defer cancel()
2166+
2167+
cmdDone := tGo(t, func() {
2168+
err := inv.WithContext(withCoderConnectRunning(ctx)).Run()
2169+
assert.NoError(t, err)
2170+
})
2171+
// Shouldn't fail to dial the coder connect host `--force-new-tunnel`
2172+
// is passed.
2173+
pty.ExpectMatch("Waiting")
2174+
2175+
_ = agenttest.New(t, client.URL, agentToken)
2176+
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
2177+
2178+
// Shells on Mac, Windows, and Linux all exit shells with the "exit" command.
2179+
pty.WriteLine("exit")
2180+
<-cmdDone
2181+
})
21522182
}
21532183

21542184
// tGoContext runs fn in a goroutine passing a context that will be

cli/testdata/coder_ssh_--help.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ OPTIONS:
1212
-e, --env string-array, $CODER_SSH_ENV
1313
Set environment variable(s) for session (key1=value1,key2=value2,...).
1414

15-
--force-tunnel bool
16-
Force the use of a new tunnel to the workspace, even if the Coder
15+
--force-new-tunnel bool
16+
Force the creation of a new tunnel to the workspace, even if the Coder
1717
Connect tunnel is available.
1818

1919
-A, --forward-agent bool, $CODER_SSH_FORWARD_AGENT

docs/reference/cli/ssh.md

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy