Use http constants instead of string
Signed-off-by: Fish-pro <zechun.chen@daocloud.io>
This commit is contained in:
parent
8a694133c4
commit
05c759a19a
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue