mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-22 05:10:32 +00:00
Modify the status code number to HTTP status semantics
Signed-off-by: clarklee92 <clarklee1992@hotmail.com> Kubernetes-commit: f86f5ee14ef3c8adf9855ce16dcc57beca949719
This commit is contained in:
parent
d7ea50d263
commit
d3a5e5f798
@ -476,25 +476,25 @@ func Test_cmdTokenSource_roundTrip(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
"Unauthorized",
|
||||
http.Response{StatusCode: 401},
|
||||
http.Response{StatusCode: http.StatusUnauthorized},
|
||||
make(map[string]string),
|
||||
make(map[string]string),
|
||||
},
|
||||
{
|
||||
"Unauthorized, nonempty defaultCache",
|
||||
http.Response{StatusCode: 401},
|
||||
http.Response{StatusCode: http.StatusUnauthorized},
|
||||
cmdCache,
|
||||
cmdCache,
|
||||
},
|
||||
{
|
||||
"Authorized",
|
||||
http.Response{StatusCode: 200},
|
||||
http.Response{StatusCode: http.StatusOK},
|
||||
make(map[string]string),
|
||||
simpleCacheUpdated,
|
||||
},
|
||||
{
|
||||
"Authorized, nonempty defaultCache",
|
||||
http.Response{StatusCode: 200},
|
||||
http.Response{StatusCode: http.StatusOK},
|
||||
cmdCache,
|
||||
cmdCacheUpdated,
|
||||
},
|
||||
|
@ -515,17 +515,17 @@ func TestTransformResponse(t *testing.T) {
|
||||
Error bool
|
||||
ErrFn func(err error) bool
|
||||
}{
|
||||
{Response: &http.Response{StatusCode: 200}, Data: []byte{}},
|
||||
{Response: &http.Response{StatusCode: 201}, Data: []byte{}, Created: true},
|
||||
{Response: &http.Response{StatusCode: http.StatusOK}, Data: []byte{}},
|
||||
{Response: &http.Response{StatusCode: http.StatusCreated}, Data: []byte{}, Created: true},
|
||||
{Response: &http.Response{StatusCode: 199}, Error: true},
|
||||
{Response: &http.Response{StatusCode: 500}, Error: true},
|
||||
{Response: &http.Response{StatusCode: 422}, Error: true},
|
||||
{Response: &http.Response{StatusCode: 409}, Error: true},
|
||||
{Response: &http.Response{StatusCode: 404}, Error: true},
|
||||
{Response: &http.Response{StatusCode: 401}, Error: true},
|
||||
{Response: &http.Response{StatusCode: http.StatusInternalServerError}, Error: true},
|
||||
{Response: &http.Response{StatusCode: http.StatusUnprocessableEntity}, Error: true},
|
||||
{Response: &http.Response{StatusCode: http.StatusConflict}, Error: true},
|
||||
{Response: &http.Response{StatusCode: http.StatusNotFound}, Error: true},
|
||||
{Response: &http.Response{StatusCode: http.StatusUnauthorized}, Error: true},
|
||||
{
|
||||
Response: &http.Response{
|
||||
StatusCode: 401,
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Header: http.Header{"Content-Type": []string{"application/json"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
@ -536,7 +536,7 @@ func TestTransformResponse(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Response: &http.Response{
|
||||
StatusCode: 401,
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Header: http.Header{"Content-Type": []string{"text/any"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
@ -545,9 +545,9 @@ func TestTransformResponse(t *testing.T) {
|
||||
return strings.Contains(err.Error(), "server has asked for the client to provide") && apierrors.IsUnauthorized(err)
|
||||
},
|
||||
},
|
||||
{Response: &http.Response{StatusCode: 403}, Error: true},
|
||||
{Response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
|
||||
{Response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
|
||||
{Response: &http.Response{StatusCode: http.StatusForbidden}, Error: true},
|
||||
{Response: &http.Response{StatusCode: http.StatusOK, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
|
||||
{Response: &http.Response{StatusCode: http.StatusOK, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
|
||||
}
|
||||
for i, test := range testCases {
|
||||
r := NewRequest(nil, "", uri, "", defaultContentConfig(), defaultSerializers(t), nil, nil, 0)
|
||||
@ -615,7 +615,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
{
|
||||
ContentType: "application/json",
|
||||
Response: &http.Response{
|
||||
StatusCode: 401,
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Header: http.Header{"Content-Type": []string{"application/json"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
@ -627,7 +627,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
{
|
||||
ContentType: "application/json",
|
||||
Response: &http.Response{
|
||||
StatusCode: 401,
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Header: http.Header{"Content-Type": []string{"application/protobuf"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
@ -644,7 +644,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
{
|
||||
ContentType: "application/json",
|
||||
Response: &http.Response{
|
||||
StatusCode: 500,
|
||||
StatusCode: http.StatusInternalServerError,
|
||||
Header: http.Header{"Content-Type": []string{"application/,others"}},
|
||||
},
|
||||
Decoder: scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
@ -657,7 +657,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
{
|
||||
// no negotiation when no content type specified
|
||||
Response: &http.Response{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Header: http.Header{"Content-Type": []string{"text/any"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
@ -667,7 +667,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
// no negotiation when no response content type specified
|
||||
ContentType: "text/any",
|
||||
Response: &http.Response{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
Decoder: scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
@ -676,7 +676,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
// unrecognized content type is not handled
|
||||
ContentType: "application/json",
|
||||
Response: &http.Response{
|
||||
StatusCode: 404,
|
||||
StatusCode: http.StatusNotFound,
|
||||
Header: http.Header{"Content-Type": []string{"application/unrecognized"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
@ -1178,7 +1178,7 @@ func (f *fakeUpgradeRoundTripper) RoundTrip(req *http.Request) (*http.Response,
|
||||
b := []byte{}
|
||||
body := ioutil.NopCloser(bytes.NewReader(b))
|
||||
resp := &http.Response{
|
||||
StatusCode: 101,
|
||||
StatusCode: http.StatusSwitchingProtocols,
|
||||
Body: body,
|
||||
}
|
||||
return resp, nil
|
||||
@ -1367,7 +1367,7 @@ func TestConnectionResetByPeerIsRetried(t *testing.T) {
|
||||
count++
|
||||
if count >= 3 {
|
||||
return &http.Response{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
||||
}, nil
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ func fakeScaleClient(t *testing.T) (ScalesGetter, []schema.GroupResource) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &http.Response{StatusCode: 200, Header: defaultHeaders(), Body: bytesBody(res)}, nil
|
||||
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeaders(), Body: bytesBody(res)}, nil
|
||||
case "PUT":
|
||||
decoder := codecs.UniversalDeserializer()
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
@ -198,7 +198,7 @@ func fakeScaleClient(t *testing.T) (ScalesGetter, []schema.GroupResource) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &http.Response{StatusCode: 200, Header: defaultHeaders(), Body: bytesBody(res)}, nil
|
||||
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeaders(), Body: bytesBody(res)}, nil
|
||||
case "PATCH":
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
@ -229,7 +229,7 @@ func fakeScaleClient(t *testing.T) (ScalesGetter, []schema.GroupResource) {
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid patch type")
|
||||
}
|
||||
return &http.Response{StatusCode: 200, Header: defaultHeaders(), Body: bytesBody(res)}, nil
|
||||
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeaders(), Body: bytesBody(res)}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected request for URL %q with method %q", req.URL.String(), req.Method)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user