Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit ceee678

Browse files
committed
Rename validation 'New' funcs
1 parent 682f2a5 commit ceee678

File tree

12 files changed

+297
-297
lines changed

12 files changed

+297
-297
lines changed

pkg/api/errors/errors_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestNewInvalid(t *testing.T) {
9292
Details *unversioned.StatusDetails
9393
}{
9494
{
95-
validation.NewFieldDuplicate("field[0].name", "bar"),
95+
validation.NewDuplicateError("field[0].name", "bar"),
9696
&unversioned.StatusDetails{
9797
Kind: "kind",
9898
Name: "name",
@@ -103,7 +103,7 @@ func TestNewInvalid(t *testing.T) {
103103
},
104104
},
105105
{
106-
validation.NewFieldInvalid("field[0].name", "bar", "detail"),
106+
validation.NewInvalidError("field[0].name", "bar", "detail"),
107107
&unversioned.StatusDetails{
108108
Kind: "kind",
109109
Name: "name",
@@ -114,7 +114,7 @@ func TestNewInvalid(t *testing.T) {
114114
},
115115
},
116116
{
117-
validation.NewFieldNotFound("field[0].name", "bar"),
117+
validation.NewNotFoundError("field[0].name", "bar"),
118118
&unversioned.StatusDetails{
119119
Kind: "kind",
120120
Name: "name",
@@ -125,7 +125,7 @@ func TestNewInvalid(t *testing.T) {
125125
},
126126
},
127127
{
128-
validation.NewFieldNotSupported("field[0].name", "bar", nil),
128+
validation.NewNotSupportedError("field[0].name", "bar", nil),
129129
&unversioned.StatusDetails{
130130
Kind: "kind",
131131
Name: "name",
@@ -136,7 +136,7 @@ func TestNewInvalid(t *testing.T) {
136136
},
137137
},
138138
{
139-
validation.NewFieldRequired("field[0].name"),
139+
validation.NewRequiredError("field[0].name"),
140140
&unversioned.StatusDetails{
141141
Kind: "kind",
142142
Name: "name",

pkg/api/validation/events.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ func ValidateEvent(event *api.Event) validation.ErrorList {
2727
// TODO: There is no namespace required for node.
2828
if event.InvolvedObject.Kind != "Node" &&
2929
event.Namespace != event.InvolvedObject.Namespace {
30-
allErrs = append(allErrs, validation.NewFieldInvalid("involvedObject.namespace", event.InvolvedObject.Namespace, "namespace does not match involvedObject"))
30+
allErrs = append(allErrs, validation.NewInvalidError("involvedObject.namespace", event.InvolvedObject.Namespace, "namespace does not match involvedObject"))
3131
}
3232
if !validation.IsDNS1123Subdomain(event.Namespace) {
33-
allErrs = append(allErrs, validation.NewFieldInvalid("namespace", event.Namespace, ""))
33+
allErrs = append(allErrs, validation.NewInvalidError("namespace", event.Namespace, ""))
3434
}
3535
return allErrs
3636
}

pkg/api/validation/validation.go

Lines changed: 187 additions & 187 deletions
Large diffs are not rendered by default.

pkg/apis/extensions/validation/validation.go

Lines changed: 49 additions & 49 deletions
Large diffs are not rendered by default.

pkg/kubectl/cmd/util/helpers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ func TestCheckInvalidErr(t *testing.T) {
274274
expected string
275275
}{
276276
{
277-
errors.NewInvalid("Invalid1", "invalidation", validation.ErrorList{validation.NewFieldInvalid("Cause", "single", "details")}),
277+
errors.NewInvalid("Invalid1", "invalidation", validation.ErrorList{validation.NewInvalidError("Cause", "single", "details")}),
278278
`Error from server: Invalid1 "invalidation" is invalid: Cause: invalid value 'single', Details: details`,
279279
},
280280
{
281-
errors.NewInvalid("Invalid2", "invalidation", validation.ErrorList{validation.NewFieldInvalid("Cause", "multi1", "details"), validation.NewFieldInvalid("Cause", "multi2", "details")}),
281+
errors.NewInvalid("Invalid2", "invalidation", validation.ErrorList{validation.NewInvalidError("Cause", "multi1", "details"), validation.NewInvalidError("Cause", "multi2", "details")}),
282282
`Error from server: Invalid2 "invalidation" is invalid: [Cause: invalid value 'multi1', Details: details, Cause: invalid value 'multi2', Details: details]`,
283283
},
284284
{

pkg/kubelet/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func filterInvalidPods(pods []*api.Pod, source string, recorder record.EventReco
317317
} else {
318318
name := kubecontainer.GetPodFullName(pod)
319319
if names.Has(name) {
320-
errlist = append(errlist, utilvalidation.NewFieldDuplicate("name", pod.Name))
320+
errlist = append(errlist, utilvalidation.NewDuplicateError("name", pod.Name))
321321
} else {
322322
names.Insert(name)
323323
}

pkg/labels/selector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,14 +701,14 @@ const qualifiedNameErrorMsg string = "must match regex [" + validation.DNS1123Su
701701

702702
func validateLabelKey(k string) error {
703703
if !validation.IsQualifiedName(k) {
704-
return validation.NewFieldInvalid("label key", k, qualifiedNameErrorMsg)
704+
return validation.NewInvalidError("label key", k, qualifiedNameErrorMsg)
705705
}
706706
return nil
707707
}
708708

709709
func validateLabelValue(v string) error {
710710
if !validation.IsValidLabelValue(v) {
711-
return validation.NewFieldInvalid("label value", v, qualifiedNameErrorMsg)
711+
return validation.NewInvalidError("label value", v, qualifiedNameErrorMsg)
712712
}
713713
return nil
714714
}

pkg/registry/pod/etcd/etcd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ func (r *BindingREST) Create(ctx api.Context, obj runtime.Object) (out runtime.O
129129
binding := obj.(*api.Binding)
130130
// TODO: move me to a binding strategy
131131
if len(binding.Target.Kind) != 0 && binding.Target.Kind != "Node" {
132-
return nil, errors.NewInvalid("binding", binding.Name, validation.ErrorList{validation.NewFieldInvalid("to.kind", binding.Target.Kind, "must be empty or 'Node'")})
132+
return nil, errors.NewInvalid("binding", binding.Name, validation.ErrorList{validation.NewInvalidError("to.kind", binding.Target.Kind, "must be empty or 'Node'")})
133133
}
134134
if len(binding.Target.Name) == 0 {
135-
return nil, errors.NewInvalid("binding", binding.Name, validation.ErrorList{validation.NewFieldRequired("to.name")})
135+
return nil, errors.NewInvalid("binding", binding.Name, validation.ErrorList{validation.NewRequiredError("to.name")})
136136
}
137137
err = r.assignPod(ctx, binding.Name, binding.Target.Name, binding.Annotations)
138138
out = &unversioned.Status{Status: unversioned.StatusSuccess}

pkg/registry/service/rest.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
8484
// Allocate next available.
8585
ip, err := rs.serviceIPs.AllocateNext()
8686
if err != nil {
87-
el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("spec.clusterIP", service.Spec.ClusterIP, err.Error())}
87+
el := utilvalidation.ErrorList{utilvalidation.NewInvalidError("spec.clusterIP", service.Spec.ClusterIP, err.Error())}
8888
return nil, errors.NewInvalid("Service", service.Name, el)
8989
}
9090
service.Spec.ClusterIP = ip.String()
9191
releaseServiceIP = true
9292
} else if api.IsServiceIPSet(service) {
9393
// Try to respect the requested IP.
9494
if err := rs.serviceIPs.Allocate(net.ParseIP(service.Spec.ClusterIP)); err != nil {
95-
el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("spec.clusterIP", service.Spec.ClusterIP, err.Error())}
95+
el := utilvalidation.ErrorList{utilvalidation.NewInvalidError("spec.clusterIP", service.Spec.ClusterIP, err.Error())}
9696
return nil, errors.NewInvalid("Service", service.Name, el)
9797
}
9898
releaseServiceIP = true
@@ -104,13 +104,13 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
104104
if servicePort.NodePort != 0 {
105105
err := nodePortOp.Allocate(servicePort.NodePort)
106106
if err != nil {
107-
el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("nodePort", servicePort.NodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
107+
el := utilvalidation.ErrorList{utilvalidation.NewInvalidError("nodePort", servicePort.NodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
108108
return nil, errors.NewInvalid("Service", service.Name, el)
109109
}
110110
} else if assignNodePorts {
111111
nodePort, err := nodePortOp.AllocateNext()
112112
if err != nil {
113-
el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("nodePort", servicePort.NodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
113+
el := utilvalidation.ErrorList{utilvalidation.NewInvalidError("nodePort", servicePort.NodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
114114
return nil, errors.NewInvalid("Service", service.Name, el)
115115
}
116116
servicePort.NodePort = nodePort
@@ -223,14 +223,14 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
223223
if !contains(oldNodePorts, nodePort) {
224224
err := nodePortOp.Allocate(nodePort)
225225
if err != nil {
226-
el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("nodePort", nodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
226+
el := utilvalidation.ErrorList{utilvalidation.NewInvalidError("nodePort", nodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
227227
return nil, false, errors.NewInvalid("Service", service.Name, el)
228228
}
229229
}
230230
} else {
231231
nodePort, err = nodePortOp.AllocateNext()
232232
if err != nil {
233-
el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("nodePort", nodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
233+
el := utilvalidation.ErrorList{utilvalidation.NewInvalidError("nodePort", nodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
234234
return nil, false, errors.NewInvalid("Service", service.Name, el)
235235
}
236236
servicePort.NodePort = nodePort

pkg/storage/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func ParseWatchResourceVersion(resourceVersion, kind string) (uint64, error) {
4848
version, err := strconv.ParseUint(resourceVersion, 10, 64)
4949
if err != nil {
5050
// TODO: Does this need to be a ErrorList? I can't convince myself it does.
51-
return 0, errors.NewInvalid(kind, "", utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("resourceVersion", resourceVersion, err.Error())})
51+
return 0, errors.NewInvalid(kind, "", utilvalidation.ErrorList{utilvalidation.NewInvalidError("resourceVersion", resourceVersion, err.Error())})
5252
}
5353
return version + 1, nil
5454
}

pkg/util/validation/errors.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,29 @@ type ErrorType string
6565
// TODO: These values are duplicated in api/types.go, but there's a circular dep. Fix it.
6666
const (
6767
// ErrorTypeNotFound is used to report failure to find a requested value
68-
// (e.g. looking up an ID). See NewFieldNotFound.
68+
// (e.g. looking up an ID). See NewNotFoundError.
6969
ErrorTypeNotFound ErrorType = "FieldValueNotFound"
7070
// ErrorTypeRequired is used to report required values that are not
7171
// provided (e.g. empty strings, null values, or empty arrays). See
72-
// NewFieldRequired.
72+
// NewRequiredError.
7373
ErrorTypeRequired ErrorType = "FieldValueRequired"
7474
// ErrorTypeDuplicate is used to report collisions of values that must be
75-
// unique (e.g. unique IDs). See NewFieldDuplicate.
75+
// unique (e.g. unique IDs). See NewDuplicateError.
7676
ErrorTypeDuplicate ErrorType = "FieldValueDuplicate"
7777
// ErrorTypeInvalid is used to report malformed values (e.g. failed regex
78-
// match, too long, out of bounds). See NewFieldInvalid.
78+
// match, too long, out of bounds). See NewInvalidError.
7979
ErrorTypeInvalid ErrorType = "FieldValueInvalid"
8080
// ErrorTypeNotSupported is used to report unknown values for enumerated
81-
// fields (e.g. a list of valid values). See NewFieldNotSupported.
81+
// fields (e.g. a list of valid values). See NewNotSupportedError.
8282
ErrorTypeNotSupported ErrorType = "FieldValueNotSupported"
8383
// ErrorTypeForbidden is used to report valid (as per formatting rules)
8484
// values which would be accepted under some conditions, but which are not
8585
// permitted by the current conditions (such as security policy). See
86-
// NewFieldForbidden.
86+
// NewForbiddenError.
8787
ErrorTypeForbidden ErrorType = "FieldValueForbidden"
8888
// ErrorTypeTooLong is used to report that the given value is too long.
8989
// This is similar to ErrorTypeInvalid, but the error will not include the
90-
// too-long value. See NewFieldTooLong.
90+
// too-long value. See NewTooLongError.
9191
ErrorTypeTooLong ErrorType = "FieldValueTooLong"
9292
// ErrorTypeInternal is used to report other errors that are not related
9393
// to user input.
@@ -119,55 +119,55 @@ func (t ErrorType) String() string {
119119
}
120120
}
121121

122-
// NewFieldNotFound returns a *Error indicating "value not found". This is
122+
// NewNotFoundError returns a *Error indicating "value not found". This is
123123
// used to report failure to find a requested value (e.g. looking up an ID).
124-
func NewFieldNotFound(field string, value interface{}) *Error {
124+
func NewNotFoundError(field string, value interface{}) *Error {
125125
return &Error{ErrorTypeNotFound, field, value, ""}
126126
}
127127

128-
// NewFieldRequired returns a *Error indicating "value required". This is used
128+
// NewRequiredError returns a *Error indicating "value required". This is used
129129
// to report required values that are not provided (e.g. empty strings, null
130130
// values, or empty arrays).
131-
func NewFieldRequired(field string) *Error {
131+
func NewRequiredError(field string) *Error {
132132
return &Error{ErrorTypeRequired, field, "", ""}
133133
}
134134

135-
// NewFieldDuplicate returns a *Error indicating "duplicate value". This is
135+
// NewDuplicateError returns a *Error indicating "duplicate value". This is
136136
// used to report collisions of values that must be unique (e.g. names or IDs).
137-
func NewFieldDuplicate(field string, value interface{}) *Error {
137+
func NewDuplicateError(field string, value interface{}) *Error {
138138
return &Error{ErrorTypeDuplicate, field, value, ""}
139139
}
140140

141-
// NewFieldInvalid returns a *Error indicating "invalid value". This is used
141+
// NewInvalidError returns a *Error indicating "invalid value". This is used
142142
// to report malformed values (e.g. failed regex match, too long, out of bounds).
143-
func NewFieldInvalid(field string, value interface{}, detail string) *Error {
143+
func NewInvalidError(field string, value interface{}, detail string) *Error {
144144
return &Error{ErrorTypeInvalid, field, value, detail}
145145
}
146146

147-
// NewFieldNotSupported returns a *Error indicating "unsupported value".
147+
// NewNotSupportedError returns a *Error indicating "unsupported value".
148148
// This is used to report unknown values for enumerated fields (e.g. a list of
149149
// valid values).
150-
func NewFieldNotSupported(field string, value interface{}, validValues []string) *Error {
150+
func NewNotSupportedError(field string, value interface{}, validValues []string) *Error {
151151
detail := ""
152152
if validValues != nil && len(validValues) > 0 {
153153
detail = "supported values: " + strings.Join(validValues, ", ")
154154
}
155155
return &Error{ErrorTypeNotSupported, field, value, detail}
156156
}
157157

158-
// NewFieldForbidden returns a *Error indicating "forbidden". This is used to
158+
// NewForbiddenError returns a *Error indicating "forbidden". This is used to
159159
// report valid (as per formatting rules) values which would be accepted under
160160
// some conditions, but which are not permitted by current conditions (e.g.
161161
// security policy).
162-
func NewFieldForbidden(field string, value interface{}) *Error {
162+
func NewForbiddenError(field string, value interface{}) *Error {
163163
return &Error{ErrorTypeForbidden, field, value, ""}
164164
}
165165

166-
// NewFieldTooLong returns a *Error indicating "too long". This is used to
166+
// NewTooLongError returns a *Error indicating "too long". This is used to
167167
// report that the given value is too long. This is similar to
168-
// NewFieldInvalid, but the returned error will not include the too-long
168+
// NewInvalidError, but the returned error will not include the too-long
169169
// value.
170-
func NewFieldTooLong(field string, value interface{}, maxLength int) *Error {
170+
func NewTooLongError(field string, value interface{}, maxLength int) *Error {
171171
return &Error{ErrorTypeTooLong, field, value, fmt.Sprintf("must have at most %d characters", maxLength)}
172172
}
173173

pkg/util/validation/errors_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ func TestMakeFuncs(t *testing.T) {
2828
expected ErrorType
2929
}{
3030
{
31-
func() *Error { return NewFieldInvalid("f", "v", "d") },
31+
func() *Error { return NewInvalidError("f", "v", "d") },
3232
ErrorTypeInvalid,
3333
},
3434
{
35-
func() *Error { return NewFieldNotSupported("f", "v", nil) },
35+
func() *Error { return NewNotSupportedError("f", "v", nil) },
3636
ErrorTypeNotSupported,
3737
},
3838
{
39-
func() *Error { return NewFieldDuplicate("f", "v") },
39+
func() *Error { return NewDuplicateError("f", "v") },
4040
ErrorTypeDuplicate,
4141
},
4242
{
43-
func() *Error { return NewFieldNotFound("f", "v") },
43+
func() *Error { return NewNotFoundError("f", "v") },
4444
ErrorTypeNotFound,
4545
},
4646
{
47-
func() *Error { return NewFieldRequired("f") },
47+
func() *Error { return NewRequiredError("f") },
4848
ErrorTypeRequired,
4949
},
5050
{
@@ -62,7 +62,7 @@ func TestMakeFuncs(t *testing.T) {
6262
}
6363

6464
func TestErrorUsefulMessage(t *testing.T) {
65-
s := NewFieldInvalid("foo", "bar", "deet").Error()
65+
s := NewInvalidError("foo", "bar", "deet").Error()
6666
t.Logf("message: %v", s)
6767
for _, part := range []string{"foo", "bar", "deet", ErrorTypeInvalid.String()} {
6868
if !strings.Contains(s, part) {
@@ -76,7 +76,7 @@ func TestErrorUsefulMessage(t *testing.T) {
7676
Inner interface{}
7777
KV map[string]int
7878
}
79-
s = NewFieldInvalid(
79+
s = NewInvalidError(
8080
"foo",
8181
&complicated{
8282
Baz: 1,
@@ -102,8 +102,8 @@ func TestToAggregate(t *testing.T) {
102102
testCases := []ErrorList{
103103
nil,
104104
{},
105-
{NewFieldInvalid("f", "v", "d")},
106-
{NewFieldInvalid("f", "v", "d"), NewInternalError("", fmt.Errorf("e"))},
105+
{NewInvalidError("f", "v", "d")},
106+
{NewInvalidError("f", "v", "d"), NewInternalError("", fmt.Errorf("e"))},
107107
}
108108
for i, tc := range testCases {
109109
agg := tc.ToAggregate()
@@ -121,9 +121,9 @@ func TestToAggregate(t *testing.T) {
121121

122122
func TestErrListFilter(t *testing.T) {
123123
list := ErrorList{
124-
NewFieldInvalid("test.field", "", ""),
125-
NewFieldInvalid("field.test", "", ""),
126-
NewFieldDuplicate("test", "value"),
124+
NewInvalidError("test.field", "", ""),
125+
NewInvalidError("field.test", "", ""),
126+
NewDuplicateError("test", "value"),
127127
}
128128
if len(list.Filter(NewErrorTypeMatcher(ErrorTypeDuplicate))) != 2 {
129129
t.Errorf("should not filter")
@@ -139,15 +139,15 @@ func TestErrListPrefix(t *testing.T) {
139139
Expected string
140140
}{
141141
{
142-
NewFieldNotFound("[0].bar", "value"),
142+
NewNotFoundError("[0].bar", "value"),
143143
"foo[0].bar",
144144
},
145145
{
146-
NewFieldInvalid("field", "value", ""),
146+
NewInvalidError("field", "value", ""),
147147
"foo.field",
148148
},
149149
{
150-
NewFieldDuplicate("", "value"),
150+
NewDuplicateError("", "value"),
151151
"foo",
152152
},
153153
}
@@ -169,15 +169,15 @@ func TestErrListPrefixIndex(t *testing.T) {
169169
Expected string
170170
}{
171171
{
172-
NewFieldNotFound("[0].bar", "value"),
172+
NewNotFoundError("[0].bar", "value"),
173173
"[1][0].bar",
174174
},
175175
{
176-
NewFieldInvalid("field", "value", ""),
176+
NewInvalidError("field", "value", ""),
177177
"[1].field",
178178
},
179179
{
180-
NewFieldDuplicate("", "value"),
180+
NewDuplicateError("", "value"),
181181
"[1]",
182182
},
183183
}

0 commit comments

Comments
 (0)