Fixed empty name error and also changed tests

This commit is contained in:
Manan Saraf
2015-06-09 15:19:04 -07:00
parent 366b382901
commit b2ebfeef25
3 changed files with 16 additions and 10 deletions

View File

@@ -212,10 +212,11 @@ func ValidateObjectMeta(meta *api.ObjectMeta, requiresNamespace bool, nameFn Val
allErrs = append(allErrs, errs.NewFieldInvalid("generateName", meta.GenerateName, qualifier))
}
}
// if the generated name validates, but the calculated value does not, it's a problem with generation, and we
// If the generated name validates, but the calculated value does not, it's a problem with generation, and we
// report it here. This may confuse users, but indicates a programming bug and still must be validated.
// If there are multiple fields out of which one is required then add a or as a seperator
if len(meta.Name) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("name"))
allErrs = append(allErrs, errs.NewFieldRequired("name or generateName"))
} else {
if ok, qualifier := nameFn(meta.Name, false); !ok {
allErrs = append(allErrs, errs.NewFieldInvalid("name", meta.Name, qualifier))