From d42d57006607b72402d319a97f7ae3af06024d0f Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Wed, 5 Apr 2023 08:35:02 -0700 Subject: [PATCH] ssh/tailssh: handle output matching better in tests (#7799) --- ssh/tailssh/tailssh_test.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ssh/tailssh/tailssh_test.go b/ssh/tailssh/tailssh_test.go index 443e0b3cb..d262093ec 100644 --- a/ssh/tailssh/tailssh_test.go +++ b/ssh/tailssh/tailssh_test.go @@ -365,6 +365,8 @@ func TestSSHRecordingCancelsSessionsOnUploadFailure(t *testing.T) { handler func(w http.ResponseWriter, r *http.Request) sshCommand string wantClientOutput string + + clientOutputMustNotContain []string }{ { name: "upload-denied", @@ -373,6 +375,8 @@ func TestSSHRecordingCancelsSessionsOnUploadFailure(t *testing.T) { }, sshCommand: "echo hello", wantClientOutput: "recording: server responded with 403 Forbidden\r\n", + + clientOutputMustNotContain: []string{"hello"}, }, { name: "upload-fails-after-starting", @@ -382,7 +386,9 @@ func TestSSHRecordingCancelsSessionsOnUploadFailure(t *testing.T) { w.WriteHeader(http.StatusInternalServerError) }, sshCommand: "echo hello && sleep 1 && echo world", - wantClientOutput: "hello\n\r\n\r\nrecording server responded with: 500 Internal Server Error\r\n\r\n", + wantClientOutput: "\r\n\r\nrecording server responded with: 500 Internal Server Error\r\n\r\n", + + clientOutputMustNotContain: []string{"world"}, }, } @@ -416,9 +422,15 @@ func TestSSHRecordingCancelsSessionsOnUploadFailure(t *testing.T) { } else { t.Errorf("client did not get kicked out: %q", got) } - if string(got) != tt.wantClientOutput { + gotStr := string(got) + if !strings.HasSuffix(gotStr, tt.wantClientOutput) { t.Errorf("client got %q, want %q", got, tt.wantClientOutput) } + for _, x := range tt.clientOutputMustNotContain { + if strings.Contains(gotStr, x) { + t.Errorf("client output must not contain %q", x) + } + } }() if err := s.HandleSSHConn(dc); err != nil { t.Errorf("unexpected error: %v", err)