Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d0e63b

Browse files
committed
Fix config ssh tests
1 parent 3e31c06 commit 5d0e63b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

cli/configssh_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net"
77
"os"
88
"os/exec"
9-
"path/filepath"
109
"strings"
1110
"testing"
1211

@@ -27,6 +26,11 @@ import (
2726

2827
func TestConfigSSH(t *testing.T) {
2928
t.Parallel()
29+
_, err := exec.LookPath("socat")
30+
if err != nil {
31+
t.Skip("You must have socat installed to run this test!")
32+
}
33+
3034
client := coderdtest.New(t, nil)
3135
user := coderdtest.CreateFirstUser(t, client)
3236
coderdtest.NewProvisionerDaemon(t, client)
@@ -85,13 +89,15 @@ func TestConfigSSH(t *testing.T) {
8589
require.NoError(t, err)
8690
defer agentConn.Close()
8791

88-
// Using socat we can force SSH to use a UNIX socket
92+
// Using socat we can force SSH to use a TCP port
8993
// created in this test. That way we still validate
9094
// our configuration, but use the native SSH command
9195
// line to interface.
92-
socket := filepath.Join(t.TempDir(), "ssh")
93-
listener, err := net.Listen("unix", socket)
96+
listener, err := net.Listen("tcp", "127.0.0.1:0")
9497
require.NoError(t, err)
98+
t.Cleanup(func() {
99+
_ = listener.Close()
100+
})
95101
go func() {
96102
for {
97103
conn, err := listener.Accept()
@@ -108,7 +114,7 @@ func TestConfigSSH(t *testing.T) {
108114
_ = listener.Close()
109115
})
110116

111-
cmd, root := clitest.New(t, "config-ssh", "--ssh-option", "ProxyCommand socat - UNIX-CLIENT:"+socket, "--ssh-config-file", tempFile.Name())
117+
cmd, root := clitest.New(t, "config-ssh", "--ssh-option", "ProxyCommand socat - TCP4:"+listener.Addr().String(), "--ssh-config-file", tempFile.Name())
112118
clitest.SetupConfig(t, client, root)
113119
doneChan := make(chan struct{})
114120
pty := ptytest.New(t)

0 commit comments

Comments
 (0)