From 43d77f7c419e2161fcfef1373bc9efe9d3647e81 Mon Sep 17 00:00:00 2001 From: Fish-pro Date: Fri, 10 Feb 2023 10:21:05 +0800 Subject: [PATCH] Use http constants instead of string Signed-off-by: Fish-pro --- discovery/consul/consul_test.go | 2 +- discovery/xds/xds_test.go | 6 +++--- storage/remote/client_test.go | 2 +- web/api/v1/api_test.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/discovery/consul/consul_test.go b/discovery/consul/consul_test.go index 9dc2d660b..c92960163 100644 --- a/discovery/consul/consul_test.go +++ b/discovery/consul/consul_test.go @@ -365,7 +365,7 @@ func TestGetDatacenterShouldReturnError(t *testing.T) { { // Define a handler that will return status 500. handler: func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) }, errMessage: "Unexpected response code: 500 ()", }, diff --git a/discovery/xds/xds_test.go b/discovery/xds/xds_test.go index b6c141e28..974a47342 100644 --- a/discovery/xds/xds_test.go +++ b/discovery/xds/xds_test.go @@ -74,16 +74,16 @@ func createTestHTTPServer(t *testing.T, responder discoveryResponder) *httptest. discoveryRes, err := responder(discoveryReq) if err != nil { - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) return } if discoveryRes == nil { - w.WriteHeader(304) + w.WriteHeader(http.StatusNotModified) return } - w.WriteHeader(200) + w.WriteHeader(http.StatusOK) data, err := protoJSONMarshalOptions.Marshal(discoveryRes) require.NoError(t, err) diff --git a/storage/remote/client_test.go b/storage/remote/client_test.go index c040667a5..9c99b292e 100644 --- a/storage/remote/client_test.go +++ b/storage/remote/client_test.go @@ -87,7 +87,7 @@ func TestStoreHTTPErrorHandling(t *testing.T) { func TestClientRetryAfter(t *testing.T) { server := httptest.NewServer( http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - http.Error(w, longErrMessage, 429) + http.Error(w, longErrMessage, http.StatusTooManyRequests) }), ) defer server.Close() diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index 919fad34b..80bc11087 100644 --- a/web/api/v1/api_test.go +++ b/web/api/v1/api_test.go @@ -2783,7 +2783,7 @@ func TestRespondSuccess(t *testing.T) { t.Fatalf("Error reading response body: %s", err) } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { t.Fatalf("Return code %d expected in success response but got %d", 200, resp.StatusCode) } if h := resp.Header.Get("Content-Type"); h != "application/json" {