chore: enable usestdlibvars linter (#1680)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL 2024-11-11 15:19:33 +01:00 committed by GitHub
parent 400ee29a10
commit bab92a7743
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 13 additions and 12 deletions

View File

@ -31,6 +31,7 @@ linters:
- staticcheck - staticcheck
- unconvert - unconvert
- unused - unused
- usestdlibvars
- wastedassign - wastedassign
issues: issues:

View File

@ -131,7 +131,7 @@ func TestHandlerErrorHandling(t *testing.T) {
logger := log.New(logBuf, "", 0) logger := log.New(logBuf, "", 0)
writer := httptest.NewRecorder() writer := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/", nil) request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add("Accept", "test/plain") request.Header.Add("Accept", "test/plain")
mReg := &mockTransactionGatherer{g: reg} mReg := &mockTransactionGatherer{g: reg}
@ -252,7 +252,7 @@ func TestInstrumentMetricHandler(t *testing.T) {
// Do it again to test idempotency. // Do it again to test idempotency.
InstrumentMetricHandler(reg, HandlerForTransactional(mReg, HandlerOpts{})) InstrumentMetricHandler(reg, HandlerForTransactional(mReg, HandlerOpts{}))
writer := httptest.NewRecorder() writer := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/", nil) request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add(acceptHeader, acceptTextPlain) request.Header.Add(acceptHeader, acceptTextPlain)
handler.ServeHTTP(writer, request) handler.ServeHTTP(writer, request)
@ -311,7 +311,7 @@ func TestHandlerMaxRequestsInFlight(t *testing.T) {
w1 := httptest.NewRecorder() w1 := httptest.NewRecorder()
w2 := httptest.NewRecorder() w2 := httptest.NewRecorder()
w3 := httptest.NewRecorder() w3 := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/", nil) request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add(acceptHeader, acceptTextPlain) request.Header.Add(acceptHeader, acceptTextPlain)
c := blockingCollector{Block: make(chan struct{}), CollectStarted: make(chan struct{}, 1)} c := blockingCollector{Block: make(chan struct{}), CollectStarted: make(chan struct{}, 1)}
@ -348,7 +348,7 @@ func TestHandlerTimeout(t *testing.T) {
handler := HandlerFor(reg, HandlerOpts{Timeout: time.Millisecond}) handler := HandlerFor(reg, HandlerOpts{Timeout: time.Millisecond})
w := httptest.NewRecorder() w := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/", nil) request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add("Accept", "test/plain") request.Header.Add("Accept", "test/plain")
c := blockingCollector{Block: make(chan struct{}), CollectStarted: make(chan struct{}, 1)} c := blockingCollector{Block: make(chan struct{}), CollectStarted: make(chan struct{}, 1)}
@ -372,7 +372,7 @@ func TestInstrumentMetricHandlerWithCompression(t *testing.T) {
handler := InstrumentMetricHandler(reg, HandlerForTransactional(mReg, HandlerOpts{DisableCompression: false})) handler := InstrumentMetricHandler(reg, HandlerForTransactional(mReg, HandlerOpts{DisableCompression: false}))
compression := Zstd compression := Zstd
writer := httptest.NewRecorder() writer := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/", nil) request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add(acceptHeader, acceptTextPlain) request.Header.Add(acceptHeader, acceptTextPlain)
request.Header.Add(acceptEncodingHeader, string(compression)) request.Header.Add(acceptEncodingHeader, string(compression))
@ -533,7 +533,7 @@ func TestNegotiateEncodingWriter(t *testing.T) {
} }
for _, test := range testCases { for _, test := range testCases {
request, _ := http.NewRequest("GET", "/", nil) request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add(acceptEncodingHeader, test.acceptEncoding) request.Header.Add(acceptEncodingHeader, test.acceptEncoding)
rr := httptest.NewRecorder() rr := httptest.NewRecorder()
_, encodingHeader, _, err := negotiateEncodingWriter(request, rr, test.offeredCompressions) _, encodingHeader, _, err := negotiateEncodingWriter(request, rr, test.offeredCompressions)
@ -631,7 +631,7 @@ func BenchmarkCompression(b *testing.B) {
b.Run(benchmark.name+"_"+size.name, func(b *testing.B) { b.Run(benchmark.name+"_"+size.name, func(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
writer := httptest.NewRecorder() writer := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/", nil) request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add(acceptEncodingHeader, benchmark.compressionType) request.Header.Add(acceptEncodingHeader, benchmark.compressionType)
handler.ServeHTTP(writer, request) handler.ServeHTTP(writer, request)
} }

View File

@ -223,7 +223,7 @@ func TestClientMiddlewareAPI_WithRequestContext(t *testing.T) {
})) }))
defer backend.Close() defer backend.Close()
req, err := http.NewRequest("GET", backend.URL, nil) req, err := http.NewRequest(http.MethodGet, backend.URL, nil)
if err != nil { if err != nil {
t.Fatalf("%v", err) t.Fatalf("%v", err)
} }
@ -276,7 +276,7 @@ func TestClientMiddlewareAPIWithRequestContextTimeout(t *testing.T) {
})) }))
defer backend.Close() defer backend.Close()
req, err := http.NewRequest("GET", backend.URL, nil) req, err := http.NewRequest(http.MethodGet, backend.URL, nil)
if err != nil { if err != nil {
t.Fatalf("%v", err) t.Fatalf("%v", err)
} }

View File

@ -418,7 +418,7 @@ func TestMiddlewareAPI(t *testing.T) {
_, _ = w.Write([]byte("OK")) _, _ = w.Write([]byte("OK"))
}) })
r, _ := http.NewRequest("GET", "www.example.com", nil) r, _ := http.NewRequest(http.MethodGet, "www.example.com", nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()
chain.ServeHTTP(w, r) chain.ServeHTTP(w, r)
@ -432,7 +432,7 @@ func TestMiddlewareAPI_WithExemplars(t *testing.T) {
_, _ = w.Write([]byte("OK")) _, _ = w.Write([]byte("OK"))
}, WithExemplarFromContext(func(_ context.Context) prometheus.Labels { return exemplar })) }, WithExemplarFromContext(func(_ context.Context) prometheus.Labels { return exemplar }))
r, _ := http.NewRequest("GET", "www.example.com", nil) r, _ := http.NewRequest(http.MethodGet, "www.example.com", nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()
chain.ServeHTTP(w, r) chain.ServeHTTP(w, r)

View File

@ -714,7 +714,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
} }
writer := httptest.NewRecorder() writer := httptest.NewRecorder()
handler := promhttp.HandlerFor(gatherer, promhttp.HandlerOpts{}) handler := promhttp.HandlerFor(gatherer, promhttp.HandlerOpts{})
request, _ := http.NewRequest("GET", "/", nil) request, _ := http.NewRequest(http.MethodGet, "/", nil)
for key, value := range scenario.headers { for key, value := range scenario.headers {
request.Header.Add(key, value) request.Header.Add(key, value)
} }