@@ -2114,41 +2114,71 @@ func TestSSH_Container(t *testing.T) {
2114
2114
func TestSSH_CoderConnect (t * testing.T ) {
2115
2115
t .Parallel ()
2116
2116
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 ()
2119
2121
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 )
2123
2125
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 )
2128
2130
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 )
2133
2154
})
2134
2155
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 ( )
2137
2158
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
+ })
2152
2182
}
2153
2183
2154
2184
// tGoContext runs fn in a goroutine passing a context that will be
0 commit comments