Skip to content

Commit 55cd93f

Browse files
ashmckenzieGitLab
authored andcommitted
Merge branch 'ashmckenzie/fix-require-in-http-handlers' into 'main'
Fix 'go-require: do not use require in http handlers (testifylint)' linter errors See merge request https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/1168 Merged-by: Ash McKenzie <[email protected]> Approved-by: Javiera Tapia <[email protected]> Approved-by: Vasilii Iakliushin <[email protected]>
2 parents 6b65a4c + 5c2e881 commit 55cd93f

File tree

9 files changed

+93
-153
lines changed

9 files changed

+93
-153
lines changed

client/client_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/golang-jwt/jwt/v5"
16+
"github.com/stretchr/testify/assert"
1617
"github.com/stretchr/testify/require"
1718

1819
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
@@ -240,20 +241,20 @@ func buildRequests(t *testing.T, relativeURLRoot string) []testserver.TestReques
240241
{
241242
Path: "/api/v4/internal/hello",
242243
Handler: func(w http.ResponseWriter, r *http.Request) {
243-
require.Equal(t, http.MethodGet, r.Method)
244+
assert.Equal(t, http.MethodGet, r.Method)
244245

245246
fmt.Fprint(w, "Hello")
246247
},
247248
},
248249
{
249250
Path: "/api/v4/internal/post_endpoint",
250251
Handler: func(w http.ResponseWriter, r *http.Request) {
251-
require.Equal(t, http.MethodPost, r.Method)
252+
assert.Equal(t, http.MethodPost, r.Method)
252253

253254
b, err := io.ReadAll(r.Body)
254255
defer r.Body.Close()
255256

256-
require.NoError(t, err)
257+
assert.NoError(t, err)
257258

258259
fmt.Fprint(w, "Echo: "+string(b))
259260
},

client/httpclient_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111
"time"
1212

13+
"github.com/stretchr/testify/assert"
1314
"github.com/stretchr/testify/require"
1415
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
1516
)
@@ -34,15 +35,15 @@ func TestBasicAuthSettings(t *testing.T) {
3435
{
3536
Path: "/api/v4/internal/get_endpoint",
3637
Handler: func(w http.ResponseWriter, r *http.Request) {
37-
require.Equal(t, http.MethodGet, r.Method)
38+
assert.Equal(t, http.MethodGet, r.Method)
3839

3940
fmt.Fprint(w, r.Header.Get("Authorization"))
4041
},
4142
},
4243
{
4344
Path: "/api/v4/internal/post_endpoint",
4445
Handler: func(w http.ResponseWriter, r *http.Request) {
45-
require.Equal(t, http.MethodPost, r.Method)
46+
assert.Equal(t, http.MethodPost, r.Method)
4647

4748
fmt.Fprint(w, r.Header.Get("Authorization"))
4849
},
@@ -82,7 +83,7 @@ func TestEmptyBasicAuthSettings(t *testing.T) {
8283
{
8384
Path: "/api/v4/internal/empty_basic_auth",
8485
Handler: func(_ http.ResponseWriter, r *http.Request) {
85-
require.Equal(t, "", r.Header.Get("Authorization"))
86+
assert.Equal(t, "", r.Header.Get("Authorization"))
8687
},
8788
},
8889
}
@@ -100,13 +101,13 @@ func TestRequestWithUserAgent(t *testing.T) {
100101
{
101102
Path: "/api/v4/internal/default_user_agent",
102103
Handler: func(_ http.ResponseWriter, r *http.Request) {
103-
require.Equal(t, defaultUserAgent, r.UserAgent())
104+
assert.Equal(t, defaultUserAgent, r.UserAgent())
104105
},
105106
},
106107
{
107108
Path: "/api/v4/internal/override_user_agent",
108109
Handler: func(_ http.ResponseWriter, r *http.Request) {
109-
require.Equal(t, gitalyUserAgent, r.UserAgent())
110+
assert.Equal(t, gitalyUserAgent, r.UserAgent())
110111
},
111112
},
112113
}

client/httpsclient_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path"
99
"testing"
1010

11+
"github.com/stretchr/testify/assert"
1112
"github.com/stretchr/testify/require"
1213
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
1314
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/testhelper"
@@ -116,7 +117,7 @@ func setupWithRequests(t *testing.T, caFile, caPath, clientCAPath, clientCertPat
116117
{
117118
Path: "/api/v4/internal/hello",
118119
Handler: func(w http.ResponseWriter, r *http.Request) {
119-
require.Equal(t, http.MethodGet, r.Method)
120+
assert.Equal(t, http.MethodGet, r.Method)
120121

121122
fmt.Fprint(w, "Hello")
122123
},

cmd/gitlab-sshd/acceptance_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/mikesmitty/edkey"
2323
"github.com/pires/go-proxyproto"
24+
"github.com/stretchr/testify/assert"
2425
"github.com/stretchr/testify/require"
2526
gitalyClient "gitlab.com/gitlab-org/gitaly/v16/client"
2627
pb "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
@@ -112,7 +113,7 @@ func startGitOverHTTPServer(t *testing.T) string {
112113
switch r.URL.Query().Get("service") {
113114
case "git-receive-pack":
114115
stream, err := client.InfoRefsReceivePack(ctx, rpcRequest)
115-
require.NoError(t, err)
116+
assert.NoError(t, err)
116117
reader = streamio.NewReader(func() ([]byte, error) {
117118
resp, err := stream.Recv()
118119
return resp.GetData(), err
@@ -122,17 +123,17 @@ func startGitOverHTTPServer(t *testing.T) string {
122123
}
123124

124125
_, err := io.Copy(w, reader)
125-
require.NoError(t, err)
126+
assert.NoError(t, err)
126127
},
127128
},
128129
{
129130
Path: "/git-receive-pack",
130131
Handler: func(_ http.ResponseWriter, r *http.Request) {
131132
body, err := io.ReadAll(r.Body)
132-
require.NoError(t, err)
133+
assert.NoError(t, err)
133134
defer r.Body.Close()
134135

135-
require.Equal(t, "0000", string(body))
136+
assert.Equal(t, "0000", string(body))
136137
},
137138
},
138139
}
@@ -185,7 +186,7 @@ func successAPI(t *testing.T, handlers ...customHandler) http.Handler {
185186
response := buildAllowedResponse(t, "responses/allowed_without_console_messages.json")
186187

187188
_, err := fmt.Fprint(w, response)
188-
require.NoError(t, err)
189+
assert.NoError(t, err)
189190
case "/api/v4/internal/shellhorse/git_audit_event":
190191
w.WriteHeader(http.StatusOK)
191192
return
@@ -495,7 +496,7 @@ func TestGeoGitReceivePackSuccess(t *testing.T) {
495496

496497
w.WriteHeader(300)
497498
_, err := fmt.Fprint(w, response)
498-
require.NoError(t, err)
499+
assert.NoError(t, err)
499500
},
500501
}
501502
client := runSSHD(t, successAPI(t, handler))

internal/command/lfsauthenticate/lfsauthenticate_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"testing"
1010

11+
"github.com/stretchr/testify/assert"
1112
"github.com/stretchr/testify/require"
1213

1314
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
@@ -73,11 +74,11 @@ func TestLfsAuthenticateRequests(t *testing.T) {
7374
Handler: func(w http.ResponseWriter, r *http.Request) {
7475
b, err := io.ReadAll(r.Body)
7576
defer r.Body.Close()
76-
require.NoError(t, err)
77+
assert.NoError(t, err)
7778

7879
var request *lfsauthenticate.Request
79-
require.NoError(t, json.Unmarshal(b, &request))
80-
require.Equal(t, request.Operation, operation)
80+
assert.NoError(t, json.Unmarshal(b, &request))
81+
assert.Equal(t, request.Operation, operation)
8182

8283
if request.UserID == userID {
8384
body := map[string]interface{}{
@@ -86,7 +87,7 @@ func TestLfsAuthenticateRequests(t *testing.T) {
8687
"repository_http_path": "https://gitlab.com/repo/path",
8788
"expires_in": 1800,
8889
}
89-
require.NoError(t, json.NewEncoder(w).Encode(body))
90+
assert.NoError(t, json.NewEncoder(w).Encode(body))
9091
} else {
9192
w.WriteHeader(http.StatusForbidden)
9293
}
@@ -97,10 +98,10 @@ func TestLfsAuthenticateRequests(t *testing.T) {
9798
Handler: func(w http.ResponseWriter, r *http.Request) {
9899
b, err := io.ReadAll(r.Body)
99100
defer r.Body.Close()
100-
require.NoError(t, err)
101+
assert.NoError(t, err)
101102

102103
var request *accessverifier.Request
103-
require.NoError(t, json.Unmarshal(b, &request))
104+
assert.NoError(t, json.Unmarshal(b, &request))
104105

105106
var glID string
106107
if request.Username == "somename" {
@@ -119,7 +120,7 @@ func TestLfsAuthenticateRequests(t *testing.T) {
119120
},
120121
},
121122
}
122-
require.NoError(t, json.NewEncoder(w).Encode(body))
123+
assert.NoError(t, json.NewEncoder(w).Encode(body))
123124
},
124125
},
125126
}

0 commit comments

Comments
 (0)