Merge pull request #84807 from clarklee92/ModifyTheStatusCode

Modify the status code number to HTTP status semantics

Kubernetes-commit: 43b102a83cc1d2b97a6a59f1c14967a840df2c35
This commit is contained in:
Kubernetes Publisher 2019-11-06 12:20:46 -08:00
commit a57d0056db
6 changed files with 31 additions and 31 deletions

2
Godeps/Godeps.json generated
View File

@ -344,7 +344,7 @@
},
{
"ImportPath": "k8s.io/api",
"Rev": "b704a2adc893"
"Rev": "f0152ed5fdbc"
},
{
"ImportPath": "k8s.io/apimachinery",

4
go.mod
View File

@ -28,7 +28,7 @@ require (
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
google.golang.org/appengine v1.5.0 // indirect
k8s.io/api v0.0.0-20191106065814-b704a2adc893
k8s.io/api v0.0.0-20191106225817-f0152ed5fdbc
k8s.io/apimachinery v0.0.0-20191105185716-00d39968b57e
k8s.io/klog v1.0.0
k8s.io/utils v0.0.0-20191030222137-2b95a09bc58d
@ -44,6 +44,6 @@ replace (
golang.org/x/sys => golang.org/x/sys v0.0.0-20190209173611-3b5209105503
golang.org/x/text => golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db
golang.org/x/time => golang.org/x/time v0.0.0-20161028155119-f51c12702a4d
k8s.io/api => k8s.io/api v0.0.0-20191106065814-b704a2adc893
k8s.io/api => k8s.io/api v0.0.0-20191106225817-f0152ed5fdbc
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20191105185716-00d39968b57e
)

2
go.sum
View File

@ -174,7 +174,7 @@ gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.0.0-20191106065814-b704a2adc893/go.mod h1:P8GsfdPr4GFN3wwx7irwr6UNXEMI2CAh9x1dojhvY+g=
k8s.io/api v0.0.0-20191106225817-f0152ed5fdbc/go.mod h1:P8GsfdPr4GFN3wwx7irwr6UNXEMI2CAh9x1dojhvY+g=
k8s.io/apimachinery v0.0.0-20191105185716-00d39968b57e/go.mod h1:gA1T9z4LIup7PIegBwxkF2UYXUNVKhOAPvQWWnAc34k=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=

View File

@ -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,
},

View File

@ -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
}

View File

@ -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)
}