mirror of https://github.com/knative/caching.git
Check multiple entries in the validation. (#367)
This is a list and we check all of them to be conformant, but return only first error, which is a departure from what we do in most of the serving.
This commit is contained in:
parent
9d8ef6a9d2
commit
7646d730f2
|
@ -30,7 +30,7 @@ func (rt *Image) Validate(ctx context.Context) *apis.FieldError {
|
|||
return rt.Spec.Validate(ctx).ViaField("spec")
|
||||
}
|
||||
|
||||
func (rs *ImageSpec) Validate(ctx context.Context) *apis.FieldError {
|
||||
func (rs *ImageSpec) Validate(ctx context.Context) (errs *apis.FieldError) {
|
||||
if rs.Image == "" {
|
||||
return apis.ErrMissingField("image")
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ func (rs *ImageSpec) Validate(ctx context.Context) *apis.FieldError {
|
|||
// https://github.com/google/go-containerregistry/blob/2f3e3e1/pkg/name/ref.go#L41
|
||||
for index, ips := range rs.ImagePullSecrets {
|
||||
if equality.Semantic.DeepEqual(ips, corev1.LocalObjectReference{}) {
|
||||
return apis.ErrMissingField(fmt.Sprintf("imagePullSecrets[%d].name", index))
|
||||
errs = errs.Also(apis.ErrMissingField(fmt.Sprintf("imagePullSecrets[%d].name", index)))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return errs
|
||||
}
|
||||
|
|
|
@ -51,6 +51,18 @@ func TestImageValidation(t *testing.T) {
|
|||
},
|
||||
},
|
||||
want: apis.ErrMissingField("spec.imagePullSecrets[0].name"),
|
||||
}, {
|
||||
name: "nested multiple spec errors",
|
||||
r: &Image{
|
||||
Spec: ImageSpec{
|
||||
Image: "busybox",
|
||||
ImagePullSecrets: []corev1.LocalObjectReference{{
|
||||
Name: "frankie",
|
||||
}, {}, {}},
|
||||
},
|
||||
},
|
||||
want: apis.ErrMissingField("spec.imagePullSecrets[1].name").
|
||||
Also(apis.ErrMissingField("spec.imagePullSecrets[2].name")),
|
||||
}}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
Loading…
Reference in New Issue