Skip to content

Commit e8d34d0

Browse files
authored
ci(lint): enable usestdlibvars linter (#4091)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
1 parent 02c1144 commit e8d34d0

16 files changed

+317
-314
lines changed

.golangci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ linters:
1919
- perfsprint
2020
- revive
2121
- testifylint
22+
- usestdlibvars
2223
- wastedassign
2324

2425
linters-settings:

auth_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestBasicAuthSucceed(t *testing.T) {
9090
})
9191

9292
w := httptest.NewRecorder()
93-
req, _ := http.NewRequest("GET", "/login", nil)
93+
req, _ := http.NewRequest(http.MethodGet, "/login", nil)
9494
req.Header.Set("Authorization", authorizationHeader("admin", "password"))
9595
router.ServeHTTP(w, req)
9696

@@ -109,7 +109,7 @@ func TestBasicAuth401(t *testing.T) {
109109
})
110110

111111
w := httptest.NewRecorder()
112-
req, _ := http.NewRequest("GET", "/login", nil)
112+
req, _ := http.NewRequest(http.MethodGet, "/login", nil)
113113
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:password")))
114114
router.ServeHTTP(w, req)
115115

@@ -129,7 +129,7 @@ func TestBasicAuth401WithCustomRealm(t *testing.T) {
129129
})
130130

131131
w := httptest.NewRecorder()
132-
req, _ := http.NewRequest("GET", "/login", nil)
132+
req, _ := http.NewRequest(http.MethodGet, "/login", nil)
133133
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:password")))
134134
router.ServeHTTP(w, req)
135135

@@ -147,7 +147,7 @@ func TestBasicAuthForProxySucceed(t *testing.T) {
147147
})
148148

149149
w := httptest.NewRecorder()
150-
req, _ := http.NewRequest("GET", "/test", nil)
150+
req, _ := http.NewRequest(http.MethodGet, "/test", nil)
151151
req.Header.Set("Proxy-Authorization", authorizationHeader("admin", "password"))
152152
router.ServeHTTP(w, req)
153153

@@ -166,7 +166,7 @@ func TestBasicAuthForProxy407(t *testing.T) {
166166
})
167167

168168
w := httptest.NewRecorder()
169-
req, _ := http.NewRequest("GET", "/test", nil)
169+
req, _ := http.NewRequest(http.MethodGet, "/test", nil)
170170
req.Header.Set("Proxy-Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:password")))
171171
router.ServeHTTP(w, req)
172172

benchmarks_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ import (
1414
func BenchmarkOneRoute(B *testing.B) {
1515
router := New()
1616
router.GET("/ping", func(c *Context) {})
17-
runRequest(B, router, "GET", "/ping")
17+
runRequest(B, router, http.MethodGet, "/ping")
1818
}
1919

2020
func BenchmarkRecoveryMiddleware(B *testing.B) {
2121
router := New()
2222
router.Use(Recovery())
2323
router.GET("/", func(c *Context) {})
24-
runRequest(B, router, "GET", "/")
24+
runRequest(B, router, http.MethodGet, "/")
2525
}
2626

2727
func BenchmarkLoggerMiddleware(B *testing.B) {
2828
router := New()
2929
router.Use(LoggerWithWriter(newMockWriter()))
3030
router.GET("/", func(c *Context) {})
31-
runRequest(B, router, "GET", "/")
31+
runRequest(B, router, http.MethodGet, "/")
3232
}
3333

3434
func BenchmarkManyHandlers(B *testing.B) {
@@ -37,15 +37,15 @@ func BenchmarkManyHandlers(B *testing.B) {
3737
router.Use(func(c *Context) {})
3838
router.Use(func(c *Context) {})
3939
router.GET("/ping", func(c *Context) {})
40-
runRequest(B, router, "GET", "/ping")
40+
runRequest(B, router, http.MethodGet, "/ping")
4141
}
4242

4343
func Benchmark5Params(B *testing.B) {
4444
DefaultWriter = os.Stdout
4545
router := New()
4646
router.Use(func(c *Context) {})
4747
router.GET("/param/:param1/:params2/:param3/:param4/:param5", func(c *Context) {})
48-
runRequest(B, router, "GET", "/param/path/to/parameter/john/12345")
48+
runRequest(B, router, http.MethodGet, "/param/path/to/parameter/john/12345")
4949
}
5050

5151
func BenchmarkOneRouteJSON(B *testing.B) {
@@ -56,7 +56,7 @@ func BenchmarkOneRouteJSON(B *testing.B) {
5656
router.GET("/json", func(c *Context) {
5757
c.JSON(http.StatusOK, data)
5858
})
59-
runRequest(B, router, "GET", "/json")
59+
runRequest(B, router, http.MethodGet, "/json")
6060
}
6161

6262
func BenchmarkOneRouteHTML(B *testing.B) {
@@ -68,29 +68,29 @@ func BenchmarkOneRouteHTML(B *testing.B) {
6868
router.GET("/html", func(c *Context) {
6969
c.HTML(http.StatusOK, "index", "hola")
7070
})
71-
runRequest(B, router, "GET", "/html")
71+
runRequest(B, router, http.MethodGet, "/html")
7272
}
7373

7474
func BenchmarkOneRouteSet(B *testing.B) {
7575
router := New()
7676
router.GET("/ping", func(c *Context) {
7777
c.Set("key", "value")
7878
})
79-
runRequest(B, router, "GET", "/ping")
79+
runRequest(B, router, http.MethodGet, "/ping")
8080
}
8181

8282
func BenchmarkOneRouteString(B *testing.B) {
8383
router := New()
8484
router.GET("/text", func(c *Context) {
8585
c.String(http.StatusOK, "this is a plain text")
8686
})
87-
runRequest(B, router, "GET", "/text")
87+
runRequest(B, router, http.MethodGet, "/text")
8888
}
8989

9090
func BenchmarkManyRoutesFist(B *testing.B) {
9191
router := New()
9292
router.Any("/ping", func(c *Context) {})
93-
runRequest(B, router, "GET", "/ping")
93+
runRequest(B, router, http.MethodGet, "/ping")
9494
}
9595

9696
func BenchmarkManyRoutesLast(B *testing.B) {
@@ -103,7 +103,7 @@ func Benchmark404(B *testing.B) {
103103
router := New()
104104
router.Any("/something", func(c *Context) {})
105105
router.NoRoute(func(c *Context) {})
106-
runRequest(B, router, "GET", "/ping")
106+
runRequest(B, router, http.MethodGet, "/ping")
107107
}
108108

109109
func Benchmark404Many(B *testing.B) {
@@ -118,7 +118,7 @@ func Benchmark404Many(B *testing.B) {
118118
router.GET("/user/:id/:mode", func(c *Context) {})
119119

120120
router.NoRoute(func(c *Context) {})
121-
runRequest(B, router, "GET", "/viewfake")
121+
runRequest(B, router, http.MethodGet, "/viewfake")
122122
}
123123

124124
type mockWriter struct {

binding/binding_msgpack_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package binding
88

99
import (
1010
"bytes"
11+
"net/http"
1112
"testing"
1213

1314
"github.com/stretchr/testify/assert"
@@ -39,20 +40,20 @@ func testMsgPackBodyBinding(t *testing.T, b Binding, name, path, badPath, body,
3940
assert.Equal(t, name, b.Name())
4041

4142
obj := FooStruct{}
42-
req := requestWithBody("POST", path, body)
43+
req := requestWithBody(http.MethodPost, path, body)
4344
req.Header.Add("Content-Type", MIMEMSGPACK)
4445
err := b.Bind(req, &obj)
4546
require.NoError(t, err)
4647
assert.Equal(t, "bar", obj.Foo)
4748

4849
obj = FooStruct{}
49-
req = requestWithBody("POST", badPath, badBody)
50+
req = requestWithBody(http.MethodPost, badPath, badBody)
5051
req.Header.Add("Content-Type", MIMEMSGPACK)
5152
err = MsgPack.Bind(req, &obj)
5253
require.Error(t, err)
5354
}
5455

5556
func TestBindingDefaultMsgPack(t *testing.T) {
56-
assert.Equal(t, MsgPack, Default("POST", MIMEMSGPACK))
57-
assert.Equal(t, MsgPack, Default("PUT", MIMEMSGPACK2))
57+
assert.Equal(t, MsgPack, Default(http.MethodPost, MIMEMSGPACK))
58+
assert.Equal(t, MsgPack, Default(http.MethodPut, MIMEMSGPACK2))
5859
}

0 commit comments

Comments
 (0)