Commit ceee678b authored by Tim Hockin's avatar Tim Hockin

Rename validation 'New' funcs

parent 682f2a5a
......@@ -92,7 +92,7 @@ func TestNewInvalid(t *testing.T) {
Details *unversioned.StatusDetails
}{
{
validation.NewFieldDuplicate("field[0].name", "bar"),
validation.NewDuplicateError("field[0].name", "bar"),
&unversioned.StatusDetails{
Kind: "kind",
Name: "name",
......@@ -103,7 +103,7 @@ func TestNewInvalid(t *testing.T) {
},
},
{
validation.NewFieldInvalid("field[0].name", "bar", "detail"),
validation.NewInvalidError("field[0].name", "bar", "detail"),
&unversioned.StatusDetails{
Kind: "kind",
Name: "name",
......@@ -114,7 +114,7 @@ func TestNewInvalid(t *testing.T) {
},
},
{
validation.NewFieldNotFound("field[0].name", "bar"),
validation.NewNotFoundError("field[0].name", "bar"),
&unversioned.StatusDetails{
Kind: "kind",
Name: "name",
......@@ -125,7 +125,7 @@ func TestNewInvalid(t *testing.T) {
},
},
{
validation.NewFieldNotSupported("field[0].name", "bar", nil),
validation.NewNotSupportedError("field[0].name", "bar", nil),
&unversioned.StatusDetails{
Kind: "kind",
Name: "name",
......@@ -136,7 +136,7 @@ func TestNewInvalid(t *testing.T) {
},
},
{
validation.NewFieldRequired("field[0].name"),
validation.NewRequiredError("field[0].name"),
&unversioned.StatusDetails{
Kind: "kind",
Name: "name",
......
......@@ -27,10 +27,10 @@ func ValidateEvent(event *api.Event) validation.ErrorList {
// TODO: There is no namespace required for node.
if event.InvolvedObject.Kind != "Node" &&
event.Namespace != event.InvolvedObject.Namespace {
allErrs = append(allErrs, validation.NewFieldInvalid("involvedObject.namespace", event.InvolvedObject.Namespace, "namespace does not match involvedObject"))
allErrs = append(allErrs, validation.NewInvalidError("involvedObject.namespace", event.InvolvedObject.Namespace, "namespace does not match involvedObject"))
}
if !validation.IsDNS1123Subdomain(event.Namespace) {
allErrs = append(allErrs, validation.NewFieldInvalid("namespace", event.Namespace, ""))
allErrs = append(allErrs, validation.NewInvalidError("namespace", event.Namespace, ""))
}
return allErrs
}
......@@ -274,11 +274,11 @@ func TestCheckInvalidErr(t *testing.T) {
expected string
}{
{
errors.NewInvalid("Invalid1", "invalidation", validation.ErrorList{validation.NewFieldInvalid("Cause", "single", "details")}),
errors.NewInvalid("Invalid1", "invalidation", validation.ErrorList{validation.NewInvalidError("Cause", "single", "details")}),
`Error from server: Invalid1 "invalidation" is invalid: Cause: invalid value 'single', Details: details`,
},
{
errors.NewInvalid("Invalid2", "invalidation", validation.ErrorList{validation.NewFieldInvalid("Cause", "multi1", "details"), validation.NewFieldInvalid("Cause", "multi2", "details")}),
errors.NewInvalid("Invalid2", "invalidation", validation.ErrorList{validation.NewInvalidError("Cause", "multi1", "details"), validation.NewInvalidError("Cause", "multi2", "details")}),
`Error from server: Invalid2 "invalidation" is invalid: [Cause: invalid value 'multi1', Details: details, Cause: invalid value 'multi2', Details: details]`,
},
{
......
......@@ -317,7 +317,7 @@ func filterInvalidPods(pods []*api.Pod, source string, recorder record.EventReco
} else {
name := kubecontainer.GetPodFullName(pod)
if names.Has(name) {
errlist = append(errlist, utilvalidation.NewFieldDuplicate("name", pod.Name))
errlist = append(errlist, utilvalidation.NewDuplicateError("name", pod.Name))
} else {
names.Insert(name)
}
......
......@@ -701,14 +701,14 @@ const qualifiedNameErrorMsg string = "must match regex [" + validation.DNS1123Su
func validateLabelKey(k string) error {
if !validation.IsQualifiedName(k) {
return validation.NewFieldInvalid("label key", k, qualifiedNameErrorMsg)
return validation.NewInvalidError("label key", k, qualifiedNameErrorMsg)
}
return nil
}
func validateLabelValue(v string) error {
if !validation.IsValidLabelValue(v) {
return validation.NewFieldInvalid("label value", v, qualifiedNameErrorMsg)
return validation.NewInvalidError("label value", v, qualifiedNameErrorMsg)
}
return nil
}
......
......@@ -129,10 +129,10 @@ func (r *BindingREST) Create(ctx api.Context, obj runtime.Object) (out runtime.O
binding := obj.(*api.Binding)
// TODO: move me to a binding strategy
if len(binding.Target.Kind) != 0 && binding.Target.Kind != "Node" {
return nil, errors.NewInvalid("binding", binding.Name, validation.ErrorList{validation.NewFieldInvalid("to.kind", binding.Target.Kind, "must be empty or 'Node'")})
return nil, errors.NewInvalid("binding", binding.Name, validation.ErrorList{validation.NewInvalidError("to.kind", binding.Target.Kind, "must be empty or 'Node'")})
}
if len(binding.Target.Name) == 0 {
return nil, errors.NewInvalid("binding", binding.Name, validation.ErrorList{validation.NewFieldRequired("to.name")})
return nil, errors.NewInvalid("binding", binding.Name, validation.ErrorList{validation.NewRequiredError("to.name")})
}
err = r.assignPod(ctx, binding.Name, binding.Target.Name, binding.Annotations)
out = &unversioned.Status{Status: unversioned.StatusSuccess}
......
......@@ -84,7 +84,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
// Allocate next available.
ip, err := rs.serviceIPs.AllocateNext()
if err != nil {
el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("spec.clusterIP", service.Spec.ClusterIP, err.Error())}
el := utilvalidation.ErrorList{utilvalidation.NewInvalidError("spec.clusterIP", service.Spec.ClusterIP, err.Error())}
return nil, errors.NewInvalid("Service", service.Name, el)
}
service.Spec.ClusterIP = ip.String()
......@@ -92,7 +92,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
} else if api.IsServiceIPSet(service) {
// Try to respect the requested IP.
if err := rs.serviceIPs.Allocate(net.ParseIP(service.Spec.ClusterIP)); err != nil {
el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("spec.clusterIP", service.Spec.ClusterIP, err.Error())}
el := utilvalidation.ErrorList{utilvalidation.NewInvalidError("spec.clusterIP", service.Spec.ClusterIP, err.Error())}
return nil, errors.NewInvalid("Service", service.Name, el)
}
releaseServiceIP = true
......@@ -104,13 +104,13 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
if servicePort.NodePort != 0 {
err := nodePortOp.Allocate(servicePort.NodePort)
if err != nil {
el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("nodePort", servicePort.NodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
el := utilvalidation.ErrorList{utilvalidation.NewInvalidError("nodePort", servicePort.NodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
return nil, errors.NewInvalid("Service", service.Name, el)
}
} else if assignNodePorts {
nodePort, err := nodePortOp.AllocateNext()
if err != nil {
el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("nodePort", servicePort.NodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
el := utilvalidation.ErrorList{utilvalidation.NewInvalidError("nodePort", servicePort.NodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
return nil, errors.NewInvalid("Service", service.Name, el)
}
servicePort.NodePort = nodePort
......@@ -223,14 +223,14 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
if !contains(oldNodePorts, nodePort) {
err := nodePortOp.Allocate(nodePort)
if err != nil {
el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("nodePort", nodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
el := utilvalidation.ErrorList{utilvalidation.NewInvalidError("nodePort", nodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
return nil, false, errors.NewInvalid("Service", service.Name, el)
}
}
} else {
nodePort, err = nodePortOp.AllocateNext()
if err != nil {
el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("nodePort", nodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
el := utilvalidation.ErrorList{utilvalidation.NewInvalidError("nodePort", nodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
return nil, false, errors.NewInvalid("Service", service.Name, el)
}
servicePort.NodePort = nodePort
......
......@@ -48,7 +48,7 @@ func ParseWatchResourceVersion(resourceVersion, kind string) (uint64, error) {
version, err := strconv.ParseUint(resourceVersion, 10, 64)
if err != nil {
// TODO: Does this need to be a ErrorList? I can't convince myself it does.
return 0, errors.NewInvalid(kind, "", utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("resourceVersion", resourceVersion, err.Error())})
return 0, errors.NewInvalid(kind, "", utilvalidation.ErrorList{utilvalidation.NewInvalidError("resourceVersion", resourceVersion, err.Error())})
}
return version + 1, nil
}
......
......@@ -65,29 +65,29 @@ type ErrorType string
// TODO: These values are duplicated in api/types.go, but there's a circular dep. Fix it.
const (
// ErrorTypeNotFound is used to report failure to find a requested value
// (e.g. looking up an ID). See NewFieldNotFound.
// (e.g. looking up an ID). See NewNotFoundError.
ErrorTypeNotFound ErrorType = "FieldValueNotFound"
// ErrorTypeRequired is used to report required values that are not
// provided (e.g. empty strings, null values, or empty arrays). See
// NewFieldRequired.
// NewRequiredError.
ErrorTypeRequired ErrorType = "FieldValueRequired"
// ErrorTypeDuplicate is used to report collisions of values that must be
// unique (e.g. unique IDs). See NewFieldDuplicate.
// unique (e.g. unique IDs). See NewDuplicateError.
ErrorTypeDuplicate ErrorType = "FieldValueDuplicate"
// ErrorTypeInvalid is used to report malformed values (e.g. failed regex
// match, too long, out of bounds). See NewFieldInvalid.
// match, too long, out of bounds). See NewInvalidError.
ErrorTypeInvalid ErrorType = "FieldValueInvalid"
// ErrorTypeNotSupported is used to report unknown values for enumerated
// fields (e.g. a list of valid values). See NewFieldNotSupported.
// fields (e.g. a list of valid values). See NewNotSupportedError.
ErrorTypeNotSupported ErrorType = "FieldValueNotSupported"
// ErrorTypeForbidden is used to report valid (as per formatting rules)
// values which would be accepted under some conditions, but which are not
// permitted by the current conditions (such as security policy). See
// NewFieldForbidden.
// NewForbiddenError.
ErrorTypeForbidden ErrorType = "FieldValueForbidden"
// ErrorTypeTooLong is used to report that the given value is too long.
// This is similar to ErrorTypeInvalid, but the error will not include the
// too-long value. See NewFieldTooLong.
// too-long value. See NewTooLongError.
ErrorTypeTooLong ErrorType = "FieldValueTooLong"
// ErrorTypeInternal is used to report other errors that are not related
// to user input.
......@@ -119,35 +119,35 @@ func (t ErrorType) String() string {
}
}
// NewFieldNotFound returns a *Error indicating "value not found". This is
// NewNotFoundError returns a *Error indicating "value not found". This is
// used to report failure to find a requested value (e.g. looking up an ID).
func NewFieldNotFound(field string, value interface{}) *Error {
func NewNotFoundError(field string, value interface{}) *Error {
return &Error{ErrorTypeNotFound, field, value, ""}
}
// NewFieldRequired returns a *Error indicating "value required". This is used
// NewRequiredError returns a *Error indicating "value required". This is used
// to report required values that are not provided (e.g. empty strings, null
// values, or empty arrays).
func NewFieldRequired(field string) *Error {
func NewRequiredError(field string) *Error {
return &Error{ErrorTypeRequired, field, "", ""}
}
// NewFieldDuplicate returns a *Error indicating "duplicate value". This is
// NewDuplicateError returns a *Error indicating "duplicate value". This is
// used to report collisions of values that must be unique (e.g. names or IDs).
func NewFieldDuplicate(field string, value interface{}) *Error {
func NewDuplicateError(field string, value interface{}) *Error {
return &Error{ErrorTypeDuplicate, field, value, ""}
}
// NewFieldInvalid returns a *Error indicating "invalid value". This is used
// NewInvalidError returns a *Error indicating "invalid value". This is used
// to report malformed values (e.g. failed regex match, too long, out of bounds).
func NewFieldInvalid(field string, value interface{}, detail string) *Error {
func NewInvalidError(field string, value interface{}, detail string) *Error {
return &Error{ErrorTypeInvalid, field, value, detail}
}
// NewFieldNotSupported returns a *Error indicating "unsupported value".
// NewNotSupportedError returns a *Error indicating "unsupported value".
// This is used to report unknown values for enumerated fields (e.g. a list of
// valid values).
func NewFieldNotSupported(field string, value interface{}, validValues []string) *Error {
func NewNotSupportedError(field string, value interface{}, validValues []string) *Error {
detail := ""
if validValues != nil && len(validValues) > 0 {
detail = "supported values: " + strings.Join(validValues, ", ")
......@@ -155,19 +155,19 @@ func NewFieldNotSupported(field string, value interface{}, validValues []string)
return &Error{ErrorTypeNotSupported, field, value, detail}
}
// NewFieldForbidden returns a *Error indicating "forbidden". This is used to
// NewForbiddenError returns a *Error indicating "forbidden". This is used to
// report valid (as per formatting rules) values which would be accepted under
// some conditions, but which are not permitted by current conditions (e.g.
// security policy).
func NewFieldForbidden(field string, value interface{}) *Error {
func NewForbiddenError(field string, value interface{}) *Error {
return &Error{ErrorTypeForbidden, field, value, ""}
}
// NewFieldTooLong returns a *Error indicating "too long". This is used to
// NewTooLongError returns a *Error indicating "too long". This is used to
// report that the given value is too long. This is similar to
// NewFieldInvalid, but the returned error will not include the too-long
// NewInvalidError, but the returned error will not include the too-long
// value.
func NewFieldTooLong(field string, value interface{}, maxLength int) *Error {
func NewTooLongError(field string, value interface{}, maxLength int) *Error {
return &Error{ErrorTypeTooLong, field, value, fmt.Sprintf("must have at most %d characters", maxLength)}
}
......
......@@ -28,23 +28,23 @@ func TestMakeFuncs(t *testing.T) {
expected ErrorType
}{
{
func() *Error { return NewFieldInvalid("f", "v", "d") },
func() *Error { return NewInvalidError("f", "v", "d") },
ErrorTypeInvalid,
},
{
func() *Error { return NewFieldNotSupported("f", "v", nil) },
func() *Error { return NewNotSupportedError("f", "v", nil) },
ErrorTypeNotSupported,
},
{
func() *Error { return NewFieldDuplicate("f", "v") },
func() *Error { return NewDuplicateError("f", "v") },
ErrorTypeDuplicate,
},
{
func() *Error { return NewFieldNotFound("f", "v") },
func() *Error { return NewNotFoundError("f", "v") },
ErrorTypeNotFound,
},
{
func() *Error { return NewFieldRequired("f") },
func() *Error { return NewRequiredError("f") },
ErrorTypeRequired,
},
{
......@@ -62,7 +62,7 @@ func TestMakeFuncs(t *testing.T) {
}
func TestErrorUsefulMessage(t *testing.T) {
s := NewFieldInvalid("foo", "bar", "deet").Error()
s := NewInvalidError("foo", "bar", "deet").Error()
t.Logf("message: %v", s)
for _, part := range []string{"foo", "bar", "deet", ErrorTypeInvalid.String()} {
if !strings.Contains(s, part) {
......@@ -76,7 +76,7 @@ func TestErrorUsefulMessage(t *testing.T) {
Inner interface{}
KV map[string]int
}
s = NewFieldInvalid(
s = NewInvalidError(
"foo",
&complicated{
Baz: 1,
......@@ -102,8 +102,8 @@ func TestToAggregate(t *testing.T) {
testCases := []ErrorList{
nil,
{},
{NewFieldInvalid("f", "v", "d")},
{NewFieldInvalid("f", "v", "d"), NewInternalError("", fmt.Errorf("e"))},
{NewInvalidError("f", "v", "d")},
{NewInvalidError("f", "v", "d"), NewInternalError("", fmt.Errorf("e"))},
}
for i, tc := range testCases {
agg := tc.ToAggregate()
......@@ -121,9 +121,9 @@ func TestToAggregate(t *testing.T) {
func TestErrListFilter(t *testing.T) {
list := ErrorList{
NewFieldInvalid("test.field", "", ""),
NewFieldInvalid("field.test", "", ""),
NewFieldDuplicate("test", "value"),
NewInvalidError("test.field", "", ""),
NewInvalidError("field.test", "", ""),
NewDuplicateError("test", "value"),
}
if len(list.Filter(NewErrorTypeMatcher(ErrorTypeDuplicate))) != 2 {
t.Errorf("should not filter")
......@@ -139,15 +139,15 @@ func TestErrListPrefix(t *testing.T) {
Expected string
}{
{
NewFieldNotFound("[0].bar", "value"),
NewNotFoundError("[0].bar", "value"),
"foo[0].bar",
},
{
NewFieldInvalid("field", "value", ""),
NewInvalidError("field", "value", ""),
"foo.field",
},
{
NewFieldDuplicate("", "value"),
NewDuplicateError("", "value"),
"foo",
},
}
......@@ -169,15 +169,15 @@ func TestErrListPrefixIndex(t *testing.T) {
Expected string
}{
{
NewFieldNotFound("[0].bar", "value"),
NewNotFoundError("[0].bar", "value"),
"[1][0].bar",
},
{
NewFieldInvalid("field", "value", ""),
NewInvalidError("field", "value", ""),
"[1].field",
},
{
NewFieldDuplicate("", "value"),
NewDuplicateError("", "value"),
"[1]",
},
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment