diff --git a/pkg/karmadactl/cmdinit/utils/util.go b/pkg/karmadactl/cmdinit/utils/util.go index 78002c228..a1cd4dc5d 100644 --- a/pkg/karmadactl/cmdinit/utils/util.go +++ b/pkg/karmadactl/cmdinit/utils/util.go @@ -46,7 +46,7 @@ func DownloadFile(url, filePath string) error { } defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return fmt.Errorf("failed download file. url: %s code: %v", url, resp.StatusCode) } diff --git a/pkg/registry/cluster/storage/proxy_test.go b/pkg/registry/cluster/storage/proxy_test.go index 6cc72b299..f35eccd76 100644 --- a/pkg/registry/cluster/storage/proxy_test.go +++ b/pkg/registry/cluster/storage/proxy_test.go @@ -114,7 +114,7 @@ func TestProxyREST_Connect(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - req, err := http.NewRequestWithContext(request.WithUser(request.NewContext(), &user.DefaultInfo{}), "GET", "http://127.0.0.1/xxx", nil) + req, err := http.NewRequestWithContext(request.WithUser(request.NewContext(), &user.DefaultInfo{}), http.MethodGet, "http://127.0.0.1/xxx", nil) if err != nil { t.Fatal(err) } diff --git a/pkg/search/proxy/controller_test.go b/pkg/search/proxy/controller_test.go index c80441473..325ec0e6d 100644 --- a/pkg/search/proxy/controller_test.go +++ b/pkg/search/proxy/controller_test.go @@ -410,7 +410,7 @@ func TestController_Connect(t *testing.T) { t.Fatal(err) } - req, err := http.NewRequest("GET", "/prefix/api/v1/pods", nil) + req, err := http.NewRequest(http.MethodGet, "/prefix/api/v1/pods", nil) if err != nil { t.Fatal(err) } @@ -476,7 +476,7 @@ func TestController_Connect_Error(t *testing.T) { } response := httptest.NewRecorder() - req, err := http.NewRequest("GET", "/api", nil) + req, err := http.NewRequest(http.MethodGet, "/api", nil) if err != nil { t.Error(err) return diff --git a/pkg/search/proxy/framework/plugins/cache/cache_test.go b/pkg/search/proxy/framework/plugins/cache/cache_test.go index a54e104d3..3d1ac3081 100644 --- a/pkg/search/proxy/framework/plugins/cache/cache_test.go +++ b/pkg/search/proxy/framework/plugins/cache/cache_test.go @@ -200,7 +200,7 @@ func TestCacheProxy_connect(t *testing.T) { // reset before each test actual = want{} - req, err := http.NewRequest("GET", tt.args.url, nil) + req, err := http.NewRequest(http.MethodGet, tt.args.url, nil) if err != nil { t.Error(err) return diff --git a/pkg/search/proxy/framework/plugins/cluster/cluster_test.go b/pkg/search/proxy/framework/plugins/cluster/cluster_test.go index bbd3df4cd..9ac0986c6 100644 --- a/pkg/search/proxy/framework/plugins/cluster/cluster_test.go +++ b/pkg/search/proxy/framework/plugins/cluster/cluster_test.go @@ -127,7 +127,7 @@ func TestModifyRequest(t *testing.T) { } body = buf } - req, _ := http.NewRequest("PUT", "/api/v1/namespaces/default/pods/foo", body) + req, _ := http.NewRequest(http.MethodPut, "/api/v1/namespaces/default/pods/foo", body) err := modifyRequest(req, tt.args.cluster) if err != nil { t.Error(err) @@ -365,7 +365,7 @@ func Test_clusterProxy_connect(t *testing.T) { args: args{ requestInfo: &request.RequestInfo{Verb: "update"}, request: (&http.Request{ - Method: "PUT", + Method: http.MethodPut, URL: &url.URL{Scheme: "https", Host: "localhost", Path: "/test"}, Body: io.NopCloser(&alwaysErrorReader{}), ContentLength: 10, diff --git a/pkg/search/proxy/framework/plugins/karmada/karmada_test.go b/pkg/search/proxy/framework/plugins/karmada/karmada_test.go index d5f72bc23..b8cacb5cd 100644 --- a/pkg/search/proxy/framework/plugins/karmada/karmada_test.go +++ b/pkg/search/proxy/framework/plugins/karmada/karmada_test.go @@ -83,7 +83,7 @@ func Test_karmadaProxy(t *testing.T) { return } - request, err := http.NewRequest("GET", "http://localhost", nil) + request, err := http.NewRequest(http.MethodGet, "http://localhost", nil) if err != nil { t.Error(err) return diff --git a/pkg/util/proxy/proxy_test.go b/pkg/util/proxy/proxy_test.go index 8e514a322..94f929fbd 100644 --- a/pkg/util/proxy/proxy_test.go +++ b/pkg/util/proxy/proxy_test.go @@ -188,7 +188,7 @@ func TestConnectCluster(t *testing.T) { if ctx == nil { ctx = context.TODO() } - req, err := http.NewRequestWithContext(ctx, "GET", "http://127.0.0.1/xxx", nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://127.0.0.1/xxx", nil) if err != nil { t.Fatal(err) } diff --git a/test/helper/request.go b/test/helper/request.go index 58ce27e0f..2bd0008e9 100644 --- a/test/helper/request.go +++ b/test/helper/request.go @@ -58,7 +58,7 @@ func DoRequest(urlPath string, token string) (int, error) { } bearToken := fmt.Sprintf("Bearer %s", string(decodeToken)) - res, err := http.NewRequest("GET", urlPath, nil) + res, err := http.NewRequest(http.MethodGet, urlPath, nil) if err != nil { return 0, err }