Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit73e6a84

Browse files
committed
Attempt windows test compat
1 parentdb5438a commit73e6a84

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

‎cli/configssh_internal_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import (
44
"os"
55
"os/exec"
66
"path/filepath"
7+
"runtime"
78
"strings"
89
"testing"
910

1011
"github.com/stretchr/testify/require"
1112
)
1213

14+
// This test tries to mimic the behavior of OpenSSH
15+
// when executing e.g. a ProxyCommand.
1316
funcTest_sshConfigExecEscape(t*testing.T) {
1417
t.Parallel()
1518

@@ -34,7 +37,11 @@ func Test_sshConfigExecEscape(t *testing.T) {
3437
err:=os.MkdirAll(dir,0o755)
3538
require.NoError(t,err)
3639
bin:=filepath.Join(dir,"coder")
37-
err=os.WriteFile(bin, []byte("#!/bin/sh\necho yay\n"),0o755)//nolint:gosec
40+
contents:= []byte("#!/bin/sh\necho yay\n")
41+
ifruntime.GOOS=="windows" {
42+
contents= []byte("cls\r\n@echo off\r\necho\"yay\"\r\n")
43+
}
44+
err=os.WriteFile(bin,contents,0o755)//nolint:gosec
3845
require.NoError(t,err)
3946

4047
escaped,err:=sshConfigExecEscape(bin)
@@ -44,7 +51,11 @@ func Test_sshConfigExecEscape(t *testing.T) {
4451
}
4552
require.NoError(t,err)
4653

47-
b,err:=exec.Command("/bin/sh","-c",escaped).Output()
54+
args:= []string{"/bin/sh","-c",escaped}
55+
ifruntime.GOOS=="windows" {
56+
args= []string{"cmd.exe","/c",escaped}
57+
}
58+
b,err:=exec.Command(args[0],args[1:]...).Output()//nolint:gosec
4859
require.NoError(t,err)
4960
got:=strings.TrimSpace(string(b))
5061
require.Equal(t,"yay",got)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp