diff --git a/.golangci.yml b/.golangci.yml index f22a4bcdf..17b00452a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,7 +21,7 @@ linters: - testifylint #- unconvert - unused - #- usestdlibvars + - usestdlibvars - whitespace exclusions: generated: lax diff --git a/config/http_config_test.go b/config/http_config_test.go index 58d13b0dc..1547a5d01 100644 --- a/config/http_config_test.go +++ b/config/http_config_test.go @@ -705,7 +705,7 @@ func TestBearerAuthRoundTripper(t *testing.T) { // Normal flow. bearerAuthRoundTripper := NewAuthorizationCredentialsRoundTripper("Bearer", NewInlineSecret(BearerToken), fakeRoundTripper) - request, _ := http.NewRequest("GET", "/hitchhiker", nil) + request, _ := http.NewRequest(http.MethodGet, "/hitchhiker", nil) request.Header.Set("User-Agent", "Douglas Adams mind") _, err := bearerAuthRoundTripper.RoundTrip(request) if err != nil { @@ -714,7 +714,7 @@ func TestBearerAuthRoundTripper(t *testing.T) { // Should honor already Authorization header set. bearerAuthRoundTripperShouldNotModifyExistingAuthorization := NewAuthorizationCredentialsRoundTripper("Bearer", NewInlineSecret(newBearerToken), fakeRoundTripper) - request, _ = http.NewRequest("GET", "/hitchhiker", nil) + request, _ = http.NewRequest(http.MethodGet, "/hitchhiker", nil) request.Header.Set("Authorization", ExpectedBearer) _, err = bearerAuthRoundTripperShouldNotModifyExistingAuthorization.RoundTrip(request) if err != nil { @@ -733,7 +733,7 @@ func TestBearerAuthFileRoundTripper(t *testing.T) { // Normal flow. bearerAuthRoundTripper := NewAuthorizationCredentialsRoundTripper("Bearer", &FileSecret{file: BearerTokenFile}, fakeRoundTripper) - request, _ := http.NewRequest("GET", "/hitchhiker", nil) + request, _ := http.NewRequest(http.MethodGet, "/hitchhiker", nil) request.Header.Set("User-Agent", "Douglas Adams mind") _, err := bearerAuthRoundTripper.RoundTrip(request) if err != nil { @@ -742,7 +742,7 @@ func TestBearerAuthFileRoundTripper(t *testing.T) { // Should honor already Authorization header set. bearerAuthRoundTripperShouldNotModifyExistingAuthorization := NewAuthorizationCredentialsRoundTripper("Bearer", &FileSecret{file: MissingBearerTokenFile}, fakeRoundTripper) - request, _ = http.NewRequest("GET", "/hitchhiker", nil) + request, _ = http.NewRequest(http.MethodGet, "/hitchhiker", nil) request.Header.Set("Authorization", ExpectedBearer) _, err = bearerAuthRoundTripperShouldNotModifyExistingAuthorization.RoundTrip(request) if err != nil { @@ -2104,7 +2104,7 @@ no_proxy: promcon.io,cncf.io`, proxyServer.URL), os.Setenv("NO_PROXY", tc.noProxyEnv) } - req := httptest.NewRequest("GET", tc.targetURL, nil) + req := httptest.NewRequest(http.MethodGet, tc.targetURL, nil) proxyFunc := proxyConfig.Proxy() resultURL, err := proxyFunc(req) diff --git a/route/route_test.go b/route/route_test.go index 87c32efd1..dd3303074 100644 --- a/route/route_test.go +++ b/route/route_test.go @@ -24,7 +24,7 @@ import ( func TestRedirect(t *testing.T) { router := New().WithPrefix("/test/prefix") w := httptest.NewRecorder() - r, err := http.NewRequest("GET", "http://localhost:9090/foo", nil) + r, err := http.NewRequest(http.MethodGet, "http://localhost:9090/foo", nil) require.NoErrorf(t, err, "Error building test request: %s", err) router.Redirect(w, r, "/some/endpoint", http.StatusFound) @@ -43,7 +43,7 @@ func TestContext(t *testing.T) { require.Equalf(t, want, got, "Unexpected context value: want %q, got %q", want, got) }) - r, err := http.NewRequest("GET", "http://localhost:9090/test/bar/", nil) + r, err := http.NewRequest(http.MethodGet, "http://localhost:9090/test/bar/", nil) require.NoErrorf(t, err, "Error building test request: %s", err) router.ServeHTTP(nil, r) } @@ -62,7 +62,7 @@ func TestContextWithValue(t *testing.T) { require.Equalf(t, want, got, "Unexpected context value: want %q, got %q", want, got) }) - r, err := http.NewRequest("GET", "http://localhost:9090/test/bar/", nil) + r, err := http.NewRequest(http.MethodGet, "http://localhost:9090/test/bar/", nil) require.NoErrorf(t, err, "Error building test request: %s", err) params := map[string]string{ "lorem": "ipsum", @@ -85,7 +85,7 @@ func TestContextWithoutValue(t *testing.T) { require.Equalf(t, want, got, "Unexpected context value: want %q, got %q", want, got) }) - r, err := http.NewRequest("GET", "http://localhost:9090/test", nil) + r, err := http.NewRequest(http.MethodGet, "http://localhost:9090/test", nil) require.NoErrorf(t, err, "Error building test request: %s", err) router.ServeHTTP(nil, r) } @@ -111,7 +111,7 @@ func TestInstrumentation(t *testing.T) { for _, c := range cases { c.router.Get("/foo", func(w http.ResponseWriter, r *http.Request) {}) - r, err := http.NewRequest("GET", "http://localhost:9090/foo", nil) + r, err := http.NewRequest(http.MethodGet, "http://localhost:9090/foo", nil) require.NoErrorf(t, err, "Error building test request: %s", err) c.router.ServeHTTP(nil, r) require.Equalf(t, c.want, got, "Unexpected value: want %q, got %q", c.want, got) @@ -151,7 +151,7 @@ func TestInstrumentations(t *testing.T) { for _, c := range cases { c.router.Get("/foo", func(w http.ResponseWriter, r *http.Request) {}) - r, err := http.NewRequest("GET", "http://localhost:9090/foo", nil) + r, err := http.NewRequest(http.MethodGet, "http://localhost:9090/foo", nil) require.NoErrorf(t, err, "Error building test request: %s", err) c.router.ServeHTTP(nil, r) require.Lenf(t, got, len(c.want), "Unexpected value: want %q, got %q", c.want, got) diff --git a/server/static_file_server_test.go b/server/static_file_server_test.go index 9aa8d76fb..254ca1c59 100644 --- a/server/static_file_server_test.go +++ b/server/static_file_server_test.go @@ -68,7 +68,7 @@ func TestServeHttp(t *testing.T) { for _, c := range cases { t.Run(c.name, func(t *testing.T) { rr := httptest.NewRecorder() - req, err := http.NewRequest("GET", "http://localhost/"+c.path, nil) + req, err := http.NewRequest(http.MethodGet, "http://localhost/"+c.path, nil) require.NoError(t, err) s := StaticFileServer(dummyFileSystem{})