From a731dbd4de2067ffbcf72604b7681ba12ad18618 Mon Sep 17 00:00:00 2001
From: "gaurav.marwal" <gauravmarwal@gmail.com>
Date: Tue, 23 Apr 2024 17:38:46 +0530
Subject: [PATCH] Fix lint issues in workhorse authorization, cable and channel
 tests

---
 .../cmd/gitlab-workhorse/authorization_test.go    |  3 +--
 workhorse/cmd/gitlab-workhorse/cable_test.go      |  8 +++++---
 workhorse/cmd/gitlab-workhorse/channel_test.go    | 15 ++++++++++-----
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/workhorse/cmd/gitlab-workhorse/authorization_test.go b/workhorse/cmd/gitlab-workhorse/authorization_test.go
index d5a075ab8297..14f7f66dd121 100644
--- a/workhorse/cmd/gitlab-workhorse/authorization_test.go
+++ b/workhorse/cmd/gitlab-workhorse/authorization_test.go
@@ -25,7 +25,7 @@ func okHandler(w http.ResponseWriter, _ *http.Request, _ *api.Response) {
 	fmt.Fprint(w, "{\"status\":\"ok\"}")
 }
 
-func runPreAuthorizeHandler(t *testing.T, ts *httptest.Server, suffix string, url *regexp.Regexp, apiResponse interface{}, returnCode, expectedCode int) *httptest.ResponseRecorder {
+func runPreAuthorizeHandler(t *testing.T, ts *httptest.Server, suffix string, url *regexp.Regexp, apiResponse interface{}, returnCode, expectedCode int) {
 	if ts == nil {
 		ts = testAuthServer(t, url, nil, returnCode, apiResponse)
 	}
@@ -41,7 +41,6 @@ func runPreAuthorizeHandler(t *testing.T, ts *httptest.Server, suffix string, ur
 	response := httptest.NewRecorder()
 	a.PreAuthorizeHandler(okHandler, suffix).ServeHTTP(response, httpRequest)
 	require.Equal(t, expectedCode, response.Code)
-	return response
 }
 
 func TestPreAuthorizeHappyPath(t *testing.T) {
diff --git a/workhorse/cmd/gitlab-workhorse/cable_test.go b/workhorse/cmd/gitlab-workhorse/cable_test.go
index 36fa954d7bfe..a4a2bd3dddb2 100644
--- a/workhorse/cmd/gitlab-workhorse/cable_test.go
+++ b/workhorse/cmd/gitlab-workhorse/cable_test.go
@@ -26,7 +26,8 @@ func TestSingleBackend(t *testing.T) {
 
 	cableURL := websocketURL(workhorse.URL, cablePath)
 
-	client, _, err := dialWebsocket(cableURL, nil)
+	client, http, err := dialWebsocket(cableURL, nil)
+	defer http.Body.Close()
 	require.NoError(t, err)
 	defer client.Close()
 
@@ -41,7 +42,7 @@ func TestSingleBackend(t *testing.T) {
 }
 
 func TestSeparateCableBackend(t *testing.T) {
-	authBackendServer := testhelper.TestServerWithHandler(regexp.MustCompile(`.`), http.HandlerFunc(http.NotFound))
+	authBackendServer := testhelper.TestServerWithHandler(regexp.MustCompile(`.`), http.HandlerFunc(http.NotFoundHandler().ServeHTTP))
 	defer authBackendServer.Close()
 
 	cableServerConns, cableBackendServer := startCableServer()
@@ -52,7 +53,8 @@ func TestSeparateCableBackend(t *testing.T) {
 
 	cableURL := websocketURL(workhorse.URL, cablePath)
 
-	client, _, err := dialWebsocket(cableURL, nil)
+	client, http, err := dialWebsocket(cableURL, nil)
+	defer http.Body.Close()
 	require.NoError(t, err)
 	defer client.Close()
 
diff --git a/workhorse/cmd/gitlab-workhorse/channel_test.go b/workhorse/cmd/gitlab-workhorse/channel_test.go
index fab21bc7ef0a..11b414cc526c 100644
--- a/workhorse/cmd/gitlab-workhorse/channel_test.go
+++ b/workhorse/cmd/gitlab-workhorse/channel_test.go
@@ -44,7 +44,8 @@ func TestChannelHappyPath(t *testing.T) {
 		t.Run(test.name, func(t *testing.T) {
 			serverConns, clientURL := wireupChannel(t, test.channelPath, nil, "channel.k8s.io")
 
-			client, _, err := dialWebsocket(clientURL, nil, "terminal.gitlab.com")
+			client, http, err := dialWebsocket(clientURL, nil, "terminal.gitlab.com")
+			defer http.Body.Close()
 			require.NoError(t, err)
 
 			server := (<-serverConns).conn
@@ -71,14 +72,16 @@ func TestChannelHappyPath(t *testing.T) {
 func TestChannelBadTLS(t *testing.T) {
 	_, clientURL := wireupChannel(t, envTerminalPath, badCA, "channel.k8s.io")
 
-	_, _, err := dialWebsocket(clientURL, nil, "terminal.gitlab.com")
+	_, http, err := dialWebsocket(clientURL, nil, "terminal.gitlab.com")
+	defer http.Body.Close()
 	require.Equal(t, websocket.ErrBadHandshake, err, "unexpected error %v", err)
 }
 
 func TestChannelSessionTimeout(t *testing.T) {
 	serverConns, clientURL := wireupChannel(t, envTerminalPath, timeout, "channel.k8s.io")
 
-	client, _, err := dialWebsocket(clientURL, nil, "terminal.gitlab.com")
+	client, http, err := dialWebsocket(clientURL, nil, "terminal.gitlab.com")
+	defer http.Body.Close()
 	require.NoError(t, err)
 
 	sc := <-serverConns
@@ -95,7 +98,8 @@ func TestChannelProxyForwardsHeadersFromUpstream(t *testing.T) {
 	hdr.Set("Random-Header", "Value")
 	serverConns, clientURL := wireupChannel(t, envTerminalPath, setHeader(hdr), "channel.k8s.io")
 
-	client, _, err := dialWebsocket(clientURL, nil, "terminal.gitlab.com")
+	client, http, err := dialWebsocket(clientURL, nil, "terminal.gitlab.com")
+	defer http.Body.Close()
 	require.NoError(t, err)
 	defer client.Close()
 
@@ -109,7 +113,8 @@ func TestChannelProxyForwardsXForwardedForFromClient(t *testing.T) {
 
 	hdr := make(http.Header)
 	hdr.Set("X-Forwarded-For", "127.0.0.2")
-	client, _, err := dialWebsocket(clientURL, hdr, "terminal.gitlab.com")
+	client, http, err := dialWebsocket(clientURL, hdr, "terminal.gitlab.com")
+	defer http.Body.Close()
 	require.NoError(t, err)
 	defer client.Close()
 
-- 
GitLab