From 0fe29232ebfbd424ab9791d027f844ed4a20f336 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 5 Nov 2015 21:42:59 -0800 Subject: [PATCH] Remove obsolete ErrorList Prefix logic --- pkg/apis/extensions/validation/validation.go | 2 +- pkg/util/validation/errors.go | 22 ------- pkg/util/validation/errors_test.go | 60 -------------------- 3 files changed, 1 insertion(+), 83 deletions(-) diff --git a/pkg/apis/extensions/validation/validation.go b/pkg/apis/extensions/validation/validation.go index 33820863425..27352d6661a 100644 --- a/pkg/apis/extensions/validation/validation.go +++ b/pkg/apis/extensions/validation/validation.go @@ -53,7 +53,7 @@ func validateHorizontalPodAutoscalerSpec(autoscaler extensions.HorizontalPodAuto allErrs = append(allErrs, validation.NewInvalidError(fldPath.Child("cpuUtilization", "targetPercentage"), autoscaler.CPUUtilization.TargetPercentage, `must be greater than or equal to 1`)) } if refErrs := ValidateSubresourceReference(autoscaler.ScaleRef, fldPath.Child("scaleRef")); len(refErrs) > 0 { - allErrs = append(allErrs, refErrs.Prefix("scaleRef")...) + allErrs = append(allErrs, refErrs...) } else if autoscaler.ScaleRef.Subresource != "scale" { allErrs = append(allErrs, validation.NewNotSupportedError(fldPath.Child("scaleRef", "subresource"), autoscaler.ScaleRef.Subresource, []string{"scale"})) } diff --git a/pkg/util/validation/errors.go b/pkg/util/validation/errors.go index 381b9659074..0efe4a9fa19 100644 --- a/pkg/util/validation/errors.go +++ b/pkg/util/validation/errors.go @@ -181,28 +181,6 @@ func NewInternalError(field *FieldPath, err error) *Error { // ErrorList holds a set of errors. type ErrorList []*Error -// Prefix adds a prefix to the Field of every Error in the list. -// Returns the list for convenience. -func (list ErrorList) Prefix(prefix string) ErrorList { - for i := range list { - err := list[i] - if strings.HasPrefix(err.Field, "[") { - err.Field = prefix + err.Field - } else if len(err.Field) != 0 { - err.Field = prefix + "." + err.Field - } else { - err.Field = prefix - } - } - return list -} - -// PrefixIndex adds an index to the Field of every Error in the list. -// Returns the list for convenience. -func (list ErrorList) PrefixIndex(index int) ErrorList { - return list.Prefix(fmt.Sprintf("[%d]", index)) -} - // NewErrorTypeMatcher returns an errors.Matcher that returns true // if the provided error is a Error and has the provided ErrorType. func NewErrorTypeMatcher(t ErrorType) utilerrors.Matcher { diff --git a/pkg/util/validation/errors_test.go b/pkg/util/validation/errors_test.go index ae115648b9f..504d0f1853c 100644 --- a/pkg/util/validation/errors_test.go +++ b/pkg/util/validation/errors_test.go @@ -132,63 +132,3 @@ func TestErrListFilter(t *testing.T) { t.Errorf("should filter") } } - -func TestErrListPrefix(t *testing.T) { - testCases := []struct { - Err *Error - Expected string - }{ - { - NewNotFoundError("[0].bar", "value"), - "foo[0].bar", - }, - { - NewInvalidError("field", "value", ""), - "foo.field", - }, - { - NewDuplicateError("", "value"), - "foo", - }, - } - for _, testCase := range testCases { - errList := ErrorList{testCase.Err} - prefix := errList.Prefix("foo") - if prefix == nil || len(prefix) != len(errList) { - t.Errorf("Prefix should return self") - } - if e, a := testCase.Expected, errList[0].Field; e != a { - t.Errorf("expected %s, got %s", e, a) - } - } -} - -func TestErrListPrefixIndex(t *testing.T) { - testCases := []struct { - Err *Error - Expected string - }{ - { - NewNotFoundError("[0].bar", "value"), - "[1][0].bar", - }, - { - NewInvalidError("field", "value", ""), - "[1].field", - }, - { - NewDuplicateError("", "value"), - "[1]", - }, - } - for _, testCase := range testCases { - errList := ErrorList{testCase.Err} - prefix := errList.PrefixIndex(1) - if prefix == nil || len(prefix) != len(errList) { - t.Errorf("PrefixIndex should return self") - } - if e, a := testCase.Expected, errList[0].Field; e != a { - t.Errorf("expected %s, got %s", e, a) - } - } -}