Commit 536313c8 authored by Dawn Chen's avatar Dawn Chen

Merge pull request #9472 from deads2k/expose-name-validation

expose common name validation methods
parents 2abf5dfb d73faa82
...@@ -107,7 +107,7 @@ func TestValidateObjectMetaUpdateIgnoresCreationTimestamp(t *testing.T) { ...@@ -107,7 +107,7 @@ func TestValidateObjectMetaUpdateIgnoresCreationTimestamp(t *testing.T) {
// Ensure trailing slash is allowed in generate name // Ensure trailing slash is allowed in generate name
func TestValidateObjectMetaTrimsTrailingSlash(t *testing.T) { func TestValidateObjectMetaTrimsTrailingSlash(t *testing.T) {
errs := ValidateObjectMeta(&api.ObjectMeta{Name: "test", GenerateName: "foo-"}, false, nameIsDNSSubdomain) errs := ValidateObjectMeta(&api.ObjectMeta{Name: "test", GenerateName: "foo-"}, false, NameIsDNSSubdomain)
if len(errs) != 0 { if len(errs) != 0 {
t.Fatalf("unexpected errors: %v", errs) t.Fatalf("unexpected errors: %v", errs)
} }
...@@ -504,8 +504,8 @@ func TestValidateVolumes(t *testing.T) { ...@@ -504,8 +504,8 @@ func TestValidateVolumes(t *testing.T) {
t.Errorf("%s: expected errors to have field %s: %v", k, v.F, errs[i]) t.Errorf("%s: expected errors to have field %s: %v", k, v.F, errs[i])
} }
detail := errs[i].(*errors.ValidationError).Detail detail := errs[i].(*errors.ValidationError).Detail
if detail != "" && detail != dns1123LabelErrorMsg { if detail != "" && detail != DNS1123LabelErrorMsg {
t.Errorf("%s: expected error detail either empty or %s, got %s", k, dns1123LabelErrorMsg, detail) t.Errorf("%s: expected error detail either empty or %s, got %s", k, DNS1123LabelErrorMsg, detail)
} }
} }
} }
...@@ -2804,11 +2804,11 @@ func TestValidateLimitRange(t *testing.T) { ...@@ -2804,11 +2804,11 @@ func TestValidateLimitRange(t *testing.T) {
}, },
"invalid Name": { "invalid Name": {
api.LimitRange{ObjectMeta: api.ObjectMeta{Name: "^Invalid", Namespace: "foo"}, Spec: spec}, api.LimitRange{ObjectMeta: api.ObjectMeta{Name: "^Invalid", Namespace: "foo"}, Spec: spec},
dnsSubdomainErrorMsg, DNSSubdomainErrorMsg,
}, },
"invalid Namespace": { "invalid Namespace": {
api.LimitRange{ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: "^Invalid"}, Spec: spec}, api.LimitRange{ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: "^Invalid"}, Spec: spec},
dns1123LabelErrorMsg, DNS1123LabelErrorMsg,
}, },
"duplicate limit type": { "duplicate limit type": {
api.LimitRange{ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: "foo"}, Spec: invalidSpecDuplicateType}, api.LimitRange{ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: "foo"}, Spec: invalidSpecDuplicateType},
...@@ -2879,11 +2879,11 @@ func TestValidateResourceQuota(t *testing.T) { ...@@ -2879,11 +2879,11 @@ func TestValidateResourceQuota(t *testing.T) {
}, },
"invalid Name": { "invalid Name": {
api.ResourceQuota{ObjectMeta: api.ObjectMeta{Name: "^Invalid", Namespace: "foo"}, Spec: spec}, api.ResourceQuota{ObjectMeta: api.ObjectMeta{Name: "^Invalid", Namespace: "foo"}, Spec: spec},
dnsSubdomainErrorMsg, DNSSubdomainErrorMsg,
}, },
"invalid Namespace": { "invalid Namespace": {
api.ResourceQuota{ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: "^Invalid"}, Spec: spec}, api.ResourceQuota{ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: "^Invalid"}, Spec: spec},
dns1123LabelErrorMsg, DNS1123LabelErrorMsg,
}, },
} }
for k, v := range errorCases { for k, v := range errorCases {
...@@ -3341,12 +3341,12 @@ func TestValidateEndpoints(t *testing.T) { ...@@ -3341,12 +3341,12 @@ func TestValidateEndpoints(t *testing.T) {
"invalid namespace": { "invalid namespace": {
endpoints: api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "mysvc", Namespace: "no@#invalid.;chars\"allowed"}}, endpoints: api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "mysvc", Namespace: "no@#invalid.;chars\"allowed"}},
errorType: "FieldValueInvalid", errorType: "FieldValueInvalid",
errorDetail: dns1123LabelErrorMsg, errorDetail: DNS1123LabelErrorMsg,
}, },
"invalid name": { "invalid name": {
endpoints: api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "-_Invliad^&Characters", Namespace: "namespace"}}, endpoints: api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "-_Invliad^&Characters", Namespace: "namespace"}},
errorType: "FieldValueInvalid", errorType: "FieldValueInvalid",
errorDetail: dnsSubdomainErrorMsg, errorDetail: DNSSubdomainErrorMsg,
}, },
"empty addresses": { "empty addresses": {
endpoints: api.Endpoints{ endpoints: api.Endpoints{
......
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