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

Skip to content

Commit 2413106

Browse files
fix: improve shell compatibility of netstat check in test (#16141)
When I wrote the original just the other day, I used `$?`, which is fine on CI and in most cases, but not when the person running the test has their system shell set to fish (Fish uses $status) instead. In the interest of letting this test pass locally, I'll instead just grab the line count of the grep output. However, `wc` is padded on macos with spaces, so we need to get rid of those too.
1 parent 5380690 commit 2413106

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cli/ssh_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,8 +1219,10 @@ func TestSSH(t *testing.T) {
12191219
// started and accepting input on stdin.
12201220
_ = pty.Peek(ctx, 1)
12211221

1222-
pty.WriteLine(fmt.Sprintf("netstat -an | grep -q %s; echo \"returned $?\"", remoteSock))
1223-
pty.ExpectMatchContext(ctx, "returned 0")
1222+
// This needs to support most shells on Linux or macOS
1223+
// We can't include exactly what's expected in the input, as that will always be matched
1224+
pty.WriteLine(fmt.Sprintf(`echo "results: $(netstat -an | grep %s | wc -l | tr -d ' ')"`, remoteSock))
1225+
pty.ExpectMatchContext(ctx, "results: 1")
12241226

12251227
// And we're done.
12261228
pty.WriteLine("exit")

0 commit comments

Comments
 (0)