mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 13:45:06 +00:00
Naming of Reason constants is inconsistent
Changed ReasonType to StatusReason (to match the field) and changed CauseReason to CauseType and renamed StatusCause.Reason to Type.
This commit is contained in:
@@ -626,7 +626,7 @@ func TestAsyncDelayReturnsError(t *testing.T) {
|
||||
server := httptest.NewServer(handler)
|
||||
|
||||
status := expectApiStatus(t, "DELETE", fmt.Sprintf("%s/prefix/version/foo/bar", server.URL), nil, http.StatusConflict)
|
||||
if status.Status != api.StatusFailure || status.Message == "" || status.Details == nil || status.Reason != api.ReasonTypeAlreadyExists {
|
||||
if status.Status != api.StatusFailure || status.Message == "" || status.Details == nil || status.Reason != api.StatusReasonAlreadyExists {
|
||||
t.Errorf("Unexpected status %#v", status)
|
||||
}
|
||||
}
|
||||
@@ -687,7 +687,7 @@ func TestWriteJSONDecodeError(t *testing.T) {
|
||||
writeJSON(http.StatusOK, api.Codec, &T{"Undecodable"}, w)
|
||||
}))
|
||||
status := expectApiStatus(t, "GET", server.URL, nil, http.StatusInternalServerError)
|
||||
if status.Reason != api.ReasonTypeUnknown {
|
||||
if status.Reason != api.StatusReasonUnknown {
|
||||
t.Errorf("unexpected reason %#v", status)
|
||||
}
|
||||
if !strings.Contains(status.Message, "type apiserver.T is not registered") {
|
||||
|
@@ -40,7 +40,7 @@ func NewNotFoundErr(kind, name string) error {
|
||||
return &apiServerError{api.Status{
|
||||
Status: api.StatusFailure,
|
||||
Code: http.StatusNotFound,
|
||||
Reason: api.ReasonTypeNotFound,
|
||||
Reason: api.StatusReasonNotFound,
|
||||
Details: &api.StatusDetails{
|
||||
Kind: kind,
|
||||
ID: name,
|
||||
@@ -54,7 +54,7 @@ func NewAlreadyExistsErr(kind, name string) error {
|
||||
return &apiServerError{api.Status{
|
||||
Status: api.StatusFailure,
|
||||
Code: http.StatusConflict,
|
||||
Reason: api.ReasonTypeAlreadyExists,
|
||||
Reason: api.StatusReasonAlreadyExists,
|
||||
Details: &api.StatusDetails{
|
||||
Kind: kind,
|
||||
ID: name,
|
||||
@@ -68,7 +68,7 @@ func NewConflictErr(kind, name string, err error) error {
|
||||
return &apiServerError{api.Status{
|
||||
Status: api.StatusFailure,
|
||||
Code: http.StatusConflict,
|
||||
Reason: api.ReasonTypeConflict,
|
||||
Reason: api.StatusReasonConflict,
|
||||
Details: &api.StatusDetails{
|
||||
Kind: kind,
|
||||
ID: name,
|
||||
@@ -83,7 +83,7 @@ func NewInvalidErr(kind, name string, errs errors.ErrorList) error {
|
||||
for i := range errs {
|
||||
if err, ok := errs[i].(errors.ValidationError); ok {
|
||||
causes = append(causes, api.StatusCause{
|
||||
Reason: api.CauseReasonType(err.Type),
|
||||
Type: api.CauseType(err.Type),
|
||||
Message: err.Error(),
|
||||
Field: err.Field,
|
||||
})
|
||||
@@ -92,7 +92,7 @@ func NewInvalidErr(kind, name string, errs errors.ErrorList) error {
|
||||
return &apiServerError{api.Status{
|
||||
Status: api.StatusFailure,
|
||||
Code: 422, // RFC 4918
|
||||
Reason: api.ReasonTypeInvalid,
|
||||
Reason: api.StatusReasonInvalid,
|
||||
Details: &api.StatusDetails{
|
||||
Kind: kind,
|
||||
ID: name,
|
||||
@@ -104,30 +104,30 @@ func NewInvalidErr(kind, name string, errs errors.ErrorList) error {
|
||||
|
||||
// IsNotFound returns true if the specified error was created by NewNotFoundErr
|
||||
func IsNotFound(err error) bool {
|
||||
return reasonForError(err) == api.ReasonTypeNotFound
|
||||
return reasonForError(err) == api.StatusReasonNotFound
|
||||
}
|
||||
|
||||
// IsAlreadyExists determines if the err is an error which indicates that a specified resource already exists.
|
||||
func IsAlreadyExists(err error) bool {
|
||||
return reasonForError(err) == api.ReasonTypeAlreadyExists
|
||||
return reasonForError(err) == api.StatusReasonAlreadyExists
|
||||
}
|
||||
|
||||
// IsConflict determines if the err is an error which indicates the provided update conflicts
|
||||
func IsConflict(err error) bool {
|
||||
return reasonForError(err) == api.ReasonTypeConflict
|
||||
return reasonForError(err) == api.StatusReasonConflict
|
||||
}
|
||||
|
||||
// IsInvalid determines if the err is an error which indicates the provided resource is not valid
|
||||
func IsInvalid(err error) bool {
|
||||
return reasonForError(err) == api.ReasonTypeInvalid
|
||||
return reasonForError(err) == api.StatusReasonInvalid
|
||||
}
|
||||
|
||||
func reasonForError(err error) api.ReasonType {
|
||||
func reasonForError(err error) api.StatusReason {
|
||||
switch t := err.(type) {
|
||||
case *apiServerError:
|
||||
return t.Status.Reason
|
||||
}
|
||||
return api.ReasonTypeUnknown
|
||||
return api.StatusReasonUnknown
|
||||
}
|
||||
|
||||
// errToAPIStatus converts an error to an api.Status object.
|
||||
@@ -148,7 +148,7 @@ func errToAPIStatus(err error) *api.Status {
|
||||
return &api.Status{
|
||||
Status: api.StatusFailure,
|
||||
Code: status,
|
||||
Reason: api.ReasonTypeUnknown,
|
||||
Reason: api.StatusReasonUnknown,
|
||||
Message: err.Error(),
|
||||
}
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ func TestErrorNew(t *testing.T) {
|
||||
t.Errorf("expected to not be confict")
|
||||
}
|
||||
if IsNotFound(err) {
|
||||
t.Errorf(fmt.Sprintf("expected to not be %s", api.ReasonTypeNotFound))
|
||||
t.Errorf(fmt.Sprintf("expected to not be %s", api.StatusReasonNotFound))
|
||||
}
|
||||
if IsInvalid(err) {
|
||||
t.Errorf("expected to not be invalid")
|
||||
@@ -63,8 +63,8 @@ func TestNewInvalidErr(t *testing.T) {
|
||||
Kind: "kind",
|
||||
ID: "name",
|
||||
Causes: []api.StatusCause{{
|
||||
Reason: api.CauseReasonTypeFieldValueDuplicate,
|
||||
Field: "field[0].name",
|
||||
Type: api.CauseTypeFieldValueDuplicate,
|
||||
Field: "field[0].name",
|
||||
}},
|
||||
},
|
||||
},
|
||||
@@ -74,8 +74,8 @@ func TestNewInvalidErr(t *testing.T) {
|
||||
Kind: "kind",
|
||||
ID: "name",
|
||||
Causes: []api.StatusCause{{
|
||||
Reason: api.CauseReasonTypeFieldValueInvalid,
|
||||
Field: "field[0].name",
|
||||
Type: api.CauseTypeFieldValueInvalid,
|
||||
Field: "field[0].name",
|
||||
}},
|
||||
},
|
||||
},
|
||||
@@ -85,8 +85,8 @@ func TestNewInvalidErr(t *testing.T) {
|
||||
Kind: "kind",
|
||||
ID: "name",
|
||||
Causes: []api.StatusCause{{
|
||||
Reason: api.CauseReasonTypeFieldValueNotFound,
|
||||
Field: "field[0].name",
|
||||
Type: api.CauseTypeFieldValueNotFound,
|
||||
Field: "field[0].name",
|
||||
}},
|
||||
},
|
||||
},
|
||||
@@ -96,8 +96,8 @@ func TestNewInvalidErr(t *testing.T) {
|
||||
Kind: "kind",
|
||||
ID: "name",
|
||||
Causes: []api.StatusCause{{
|
||||
Reason: api.CauseReasonTypeFieldValueNotSupported,
|
||||
Field: "field[0].name",
|
||||
Type: api.CauseTypeFieldValueNotSupported,
|
||||
Field: "field[0].name",
|
||||
}},
|
||||
},
|
||||
},
|
||||
@@ -107,8 +107,8 @@ func TestNewInvalidErr(t *testing.T) {
|
||||
Kind: "kind",
|
||||
ID: "name",
|
||||
Causes: []api.StatusCause{{
|
||||
Reason: api.CauseReasonTypeFieldValueRequired,
|
||||
Field: "field[0].name",
|
||||
Type: api.CauseTypeFieldValueRequired,
|
||||
Field: "field[0].name",
|
||||
}},
|
||||
},
|
||||
},
|
||||
@@ -118,7 +118,7 @@ func TestNewInvalidErr(t *testing.T) {
|
||||
expected.Causes[0].Message = vErr.Error()
|
||||
err := NewInvalidErr("kind", "name", apierrors.ErrorList{vErr})
|
||||
status := errToAPIStatus(err)
|
||||
if status.Code != 422 || status.Reason != api.ReasonTypeInvalid {
|
||||
if status.Code != 422 || status.Reason != api.StatusReasonInvalid {
|
||||
t.Errorf("unexpected status: %#v", status)
|
||||
}
|
||||
if !reflect.DeepEqual(expected, status.Details) {
|
||||
@@ -130,13 +130,13 @@ func TestNewInvalidErr(t *testing.T) {
|
||||
func Test_errToAPIStatus(t *testing.T) {
|
||||
err := &apiServerError{}
|
||||
status := errToAPIStatus(err)
|
||||
if status.Reason != api.ReasonTypeUnknown || status.Status != api.StatusFailure {
|
||||
if status.Reason != api.StatusReasonUnknown || status.Status != api.StatusFailure {
|
||||
t.Errorf("unexpected status object: %#v", status)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_reasonForError(t *testing.T) {
|
||||
if e, a := api.ReasonTypeUnknown, reasonForError(nil); e != a {
|
||||
if e, a := api.StatusReasonUnknown, reasonForError(nil); e != a {
|
||||
t.Errorf("unexpected reason type: %#v", a)
|
||||
}
|
||||
}
|
||||
|
@@ -192,7 +192,7 @@ func (op *Operation) StatusOrResult() (description interface{}, finished bool) {
|
||||
if op.finished == nil {
|
||||
return &api.Status{
|
||||
Status: api.StatusWorking,
|
||||
Reason: api.ReasonTypeWorking,
|
||||
Reason: api.StatusReasonWorking,
|
||||
Details: &api.StatusDetails{ID: op.ID, Kind: "operation"},
|
||||
}, false
|
||||
}
|
||||
|
Reference in New Issue
Block a user