From 2413106f223ebbb3c736653b9064c422ffcb3e4e Mon Sep 17 00:00:00 2001 From: Ethan <39577870+ethanndickson@users.noreply.github.com> Date: Wed, 15 Jan 2025 14:23:53 +1100 Subject: [PATCH] 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. --- cli/ssh_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/ssh_test.go b/cli/ssh_test.go index 23c7a01898..76d76ac8ad 100644 --- a/cli/ssh_test.go +++ b/cli/ssh_test.go @@ -1219,8 +1219,10 @@ func TestSSH(t *testing.T) { // started and accepting input on stdin. _ = pty.Peek(ctx, 1) - pty.WriteLine(fmt.Sprintf("netstat -an | grep -q %s; echo \"returned $?\"", remoteSock)) - pty.ExpectMatchContext(ctx, "returned 0") + // This needs to support most shells on Linux or macOS + // We can't include exactly what's expected in the input, as that will always be matched + pty.WriteLine(fmt.Sprintf(`echo "results: $(netstat -an | grep %s | wc -l | tr -d ' ')"`, remoteSock)) + pty.ExpectMatchContext(ctx, "results: 1") // And we're done. pty.WriteLine("exit")