Skip to content

Commit

Permalink
chore: enable usestdlibvars linter (prometheus#1680)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 authored and shivanthzen committed Nov 13, 2024
1 parent b915862 commit 954a5c0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ linters:
- staticcheck
- unconvert
- unused
- usestdlibvars
- wastedassign

issues:
Expand Down
14 changes: 7 additions & 7 deletions prometheus/promhttp/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestHandlerErrorHandling(t *testing.T) {
logger := log.New(logBuf, "", 0)

writer := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/", nil)
request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add("Accept", "test/plain")

mReg := &mockTransactionGatherer{g: reg}
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestInstrumentMetricHandler(t *testing.T) {
// Do it again to test idempotency.
InstrumentMetricHandler(reg, HandlerForTransactional(mReg, HandlerOpts{}))
writer := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/", nil)
request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add(acceptHeader, acceptTextPlain)

handler.ServeHTTP(writer, request)
Expand Down Expand Up @@ -311,7 +311,7 @@ func TestHandlerMaxRequestsInFlight(t *testing.T) {
w1 := httptest.NewRecorder()
w2 := httptest.NewRecorder()
w3 := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/", nil)
request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add(acceptHeader, acceptTextPlain)

c := blockingCollector{Block: make(chan struct{}), CollectStarted: make(chan struct{}, 1)}
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestHandlerTimeout(t *testing.T) {
handler := HandlerFor(reg, HandlerOpts{Timeout: time.Millisecond})
w := httptest.NewRecorder()

request, _ := http.NewRequest("GET", "/", nil)
request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add("Accept", "test/plain")

c := blockingCollector{Block: make(chan struct{}), CollectStarted: make(chan struct{}, 1)}
Expand All @@ -372,7 +372,7 @@ func TestInstrumentMetricHandlerWithCompression(t *testing.T) {
handler := InstrumentMetricHandler(reg, HandlerForTransactional(mReg, HandlerOpts{DisableCompression: false}))
compression := Zstd
writer := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/", nil)
request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add(acceptHeader, acceptTextPlain)
request.Header.Add(acceptEncodingHeader, string(compression))

Expand Down Expand Up @@ -533,7 +533,7 @@ func TestNegotiateEncodingWriter(t *testing.T) {
}

for _, test := range testCases {
request, _ := http.NewRequest("GET", "/", nil)
request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add(acceptEncodingHeader, test.acceptEncoding)
rr := httptest.NewRecorder()
_, encodingHeader, _, err := negotiateEncodingWriter(request, rr, test.offeredCompressions)
Expand Down Expand Up @@ -631,7 +631,7 @@ func BenchmarkCompression(b *testing.B) {
b.Run(benchmark.name+"_"+size.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
writer := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/", nil)
request, _ := http.NewRequest(http.MethodGet, "/", nil)
request.Header.Add(acceptEncodingHeader, benchmark.compressionType)
handler.ServeHTTP(writer, request)
}
Expand Down
4 changes: 2 additions & 2 deletions prometheus/promhttp/instrument_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestClientMiddlewareAPI_WithRequestContext(t *testing.T) {
}))
defer backend.Close()

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

req, err := http.NewRequest("GET", backend.URL, nil)
req, err := http.NewRequest(http.MethodGet, backend.URL, nil)
if err != nil {
t.Fatalf("%v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions prometheus/promhttp/instrument_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func TestMiddlewareAPI(t *testing.T) {
_, _ = w.Write([]byte("OK"))
})

r, _ := http.NewRequest("GET", "www.example.com", nil)
r, _ := http.NewRequest(http.MethodGet, "www.example.com", nil)
w := httptest.NewRecorder()
chain.ServeHTTP(w, r)

Expand All @@ -432,7 +432,7 @@ func TestMiddlewareAPI_WithExemplars(t *testing.T) {
_, _ = w.Write([]byte("OK"))
}, 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()
chain.ServeHTTP(w, r)

Expand Down
2 changes: 1 addition & 1 deletion prometheus/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}
writer := httptest.NewRecorder()
handler := promhttp.HandlerFor(gatherer, promhttp.HandlerOpts{})
request, _ := http.NewRequest("GET", "/", nil)
request, _ := http.NewRequest(http.MethodGet, "/", nil)
for key, value := range scenario.headers {
request.Header.Add(key, value)
}
Expand Down

0 comments on commit 954a5c0

Please sign in to comment.