Use http constants instead of string

Signed-off-by: Fish-pro <zechun.chen@daocloud.io>
This commit is contained in:
Fish-pro 2023-02-10 10:21:05 +08:00
parent c70d85baed
commit 43d77f7c41
4 changed files with 6 additions and 6 deletions

View File

@ -365,7 +365,7 @@ func TestGetDatacenterShouldReturnError(t *testing.T) {
{ {
// Define a handler that will return status 500. // Define a handler that will return status 500.
handler: func(w http.ResponseWriter, r *http.Request) { handler: func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(500) w.WriteHeader(http.StatusInternalServerError)
}, },
errMessage: "Unexpected response code: 500 ()", errMessage: "Unexpected response code: 500 ()",
}, },

View File

@ -74,16 +74,16 @@ func createTestHTTPServer(t *testing.T, responder discoveryResponder) *httptest.
discoveryRes, err := responder(discoveryReq) discoveryRes, err := responder(discoveryReq)
if err != nil { if err != nil {
w.WriteHeader(500) w.WriteHeader(http.StatusInternalServerError)
return return
} }
if discoveryRes == nil { if discoveryRes == nil {
w.WriteHeader(304) w.WriteHeader(http.StatusNotModified)
return return
} }
w.WriteHeader(200) w.WriteHeader(http.StatusOK)
data, err := protoJSONMarshalOptions.Marshal(discoveryRes) data, err := protoJSONMarshalOptions.Marshal(discoveryRes)
require.NoError(t, err) require.NoError(t, err)

View File

@ -87,7 +87,7 @@ func TestStoreHTTPErrorHandling(t *testing.T) {
func TestClientRetryAfter(t *testing.T) { func TestClientRetryAfter(t *testing.T) {
server := httptest.NewServer( server := httptest.NewServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, longErrMessage, 429) http.Error(w, longErrMessage, http.StatusTooManyRequests)
}), }),
) )
defer server.Close() defer server.Close()

View File

@ -2783,7 +2783,7 @@ func TestRespondSuccess(t *testing.T) {
t.Fatalf("Error reading response body: %s", err) 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) 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" { if h := resp.Header.Get("Content-Type"); h != "application/json" {