-
Notifications
You must be signed in to change notification settings - Fork 38.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation cleanup part 7 #18694
Validation cleanup part 7 #18694
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,15 +65,15 @@ func TestValidateObjectMetaCustomName(t *testing.T) { | |
func TestValidateObjectMetaNamespaces(t *testing.T) { | ||
errs := ValidateObjectMeta( | ||
&api.ObjectMeta{Name: "test", Namespace: "foo.bar"}, | ||
false, | ||
true, | ||
func(s string, prefix bool) (bool, string) { | ||
return true, "" | ||
}, | ||
field.NewPath("field")) | ||
if len(errs) != 1 { | ||
t.Fatalf("unexpected errors: %v", errs) | ||
} | ||
if !strings.Contains(errs[0].Error(), "invalid value 'foo.bar'") { | ||
if !strings.Contains(errs[0].Error(), `Invalid value: "foo.bar"`) { | ||
t.Errorf("unexpected error message: %v", errs) | ||
} | ||
maxLength := 63 | ||
|
@@ -84,15 +84,15 @@ func TestValidateObjectMetaNamespaces(t *testing.T) { | |
} | ||
errs = ValidateObjectMeta( | ||
&api.ObjectMeta{Name: "test", Namespace: string(b)}, | ||
false, | ||
true, | ||
func(s string, prefix bool) (bool, string) { | ||
return true, "" | ||
}, | ||
field.NewPath("field")) | ||
if len(errs) != 1 { | ||
t.Fatalf("unexpected errors: %v", errs) | ||
} | ||
if !strings.Contains(errs[0].Error(), "invalid value") { | ||
if !strings.Contains(errs[0].Error(), "Invalid value") { | ||
t.Errorf("unexpected error message: %v", errs) | ||
} | ||
} | ||
|
@@ -629,23 +629,23 @@ func TestValidateVolumes(t *testing.T) { | |
}, | ||
"absolute path": { | ||
[]api.Volume{{Name: "absolutepath", VolumeSource: absolutePathName}}, | ||
field.ErrorTypeForbidden, | ||
field.ErrorTypeInvalid, | ||
"downwardAPI.path", "", | ||
}, | ||
"dot dot path": { | ||
[]api.Volume{{Name: "dotdotpath", VolumeSource: dotDotInPath}}, | ||
field.ErrorTypeInvalid, | ||
"downwardAPI.path", `must not contain ".."`, | ||
"downwardAPI.path", `must not contain '..'`, | ||
}, | ||
"dot dot file name": { | ||
[]api.Volume{{Name: "dotdotfilename", VolumeSource: dotDotPathName}}, | ||
field.ErrorTypeInvalid, | ||
"downwardAPI.path", `must not start with ".."`, | ||
"downwardAPI.path", `must not start with '..'`, | ||
}, | ||
"dot dot first level dirent": { | ||
[]api.Volume{{Name: "dotdotdirfilename", VolumeSource: dotDotFirstLevelDirent}}, | ||
field.ErrorTypeInvalid, | ||
"downwardAPI.path", `must not start with ".."`, | ||
"downwardAPI.path", `must not start with '..'`, | ||
}, | ||
"empty wwn": { | ||
[]api.Volume{{Name: "badimage", VolumeSource: zeroWWN}}, | ||
|
@@ -665,16 +665,16 @@ func TestValidateVolumes(t *testing.T) { | |
"starts with '..'": { | ||
[]api.Volume{{Name: "badprefix", VolumeSource: startsWithDots}}, | ||
field.ErrorTypeInvalid, | ||
"gitRepo.directory", `must not start with ".."`, | ||
"gitRepo.directory", `must not start with '..'`, | ||
}, | ||
"contains '..'": { | ||
[]api.Volume{{Name: "containsdots", VolumeSource: containsDots}}, | ||
field.ErrorTypeInvalid, | ||
"gitRepo.directory", `must not contain ".."`, | ||
"gitRepo.directory", `must not contain '..'`, | ||
}, | ||
"absolute target": { | ||
[]api.Volume{{Name: "absolutetarget", VolumeSource: absPath}}, | ||
field.ErrorTypeForbidden, | ||
field.ErrorTypeInvalid, | ||
"gitRepo.directory", "", | ||
}, | ||
} | ||
|
@@ -824,12 +824,12 @@ func TestValidateEnv(t *testing.T) { | |
{ | ||
name: "zero-length name", | ||
envs: []api.EnvVar{{Name: ""}}, | ||
expectedError: "[0].name: required value", | ||
expectedError: "[0].name: Required value", | ||
}, | ||
{ | ||
name: "name not a C identifier", | ||
envs: []api.EnvVar{{Name: "a.b.c"}}, | ||
expectedError: `[0].name: invalid value 'a.b.c', Details: must be a C identifier (matching regex [A-Za-z_][A-Za-z0-9_]*): e.g. "my_name" or "MyName"`, | ||
expectedError: `[0].name: Invalid value: "a.b.c": must be a C identifier (matching regex [A-Za-z_][A-Za-z0-9_]*): e.g. "my_name" or "MyName"`, | ||
}, | ||
{ | ||
name: "value and valueFrom specified", | ||
|
@@ -843,7 +843,7 @@ func TestValidateEnv(t *testing.T) { | |
}, | ||
}, | ||
}}, | ||
expectedError: "[0].valueFrom: invalid value '', Details: sources cannot be specified when value is not empty", | ||
expectedError: "[0].valueFrom: Invalid value: \"\": may not be specified when `value` is not empty", | ||
}, | ||
{ | ||
name: "missing FieldPath on ObjectFieldSelector", | ||
|
@@ -855,7 +855,7 @@ func TestValidateEnv(t *testing.T) { | |
}, | ||
}, | ||
}}, | ||
expectedError: "[0].valueFrom.fieldRef.fieldPath: required value", | ||
expectedError: `[0].valueFrom.fieldRef.fieldPath: Required value`, | ||
}, | ||
{ | ||
name: "missing APIVersion on ObjectFieldSelector", | ||
|
@@ -867,7 +867,7 @@ func TestValidateEnv(t *testing.T) { | |
}, | ||
}, | ||
}}, | ||
expectedError: "[0].valueFrom.fieldRef.apiVersion: required value", | ||
expectedError: `[0].valueFrom.fieldRef.apiVersion: Required value`, | ||
}, | ||
{ | ||
name: "invalid fieldPath", | ||
|
@@ -880,7 +880,7 @@ func TestValidateEnv(t *testing.T) { | |
}, | ||
}, | ||
}}, | ||
expectedError: "[0].valueFrom.fieldRef.fieldPath: invalid value 'metadata.whoops', Details: error converting fieldPath", | ||
expectedError: `[0].valueFrom.fieldRef.fieldPath: Invalid value: "metadata.whoops": error converting fieldPath`, | ||
}, | ||
{ | ||
name: "invalid fieldPath labels", | ||
|
@@ -893,7 +893,7 @@ func TestValidateEnv(t *testing.T) { | |
}, | ||
}, | ||
}}, | ||
expectedError: "[0].valueFrom.fieldRef.fieldPath: unsupported value 'metadata.labels', Details: supported values: metadata.name, metadata.namespace, status.podIP", | ||
expectedError: `[0].valueFrom.fieldRef.fieldPath: Unsupported value: "metadata.labels": supported values: metadata.name, metadata.namespace, status.podIP`, | ||
}, | ||
{ | ||
name: "invalid fieldPath annotations", | ||
|
@@ -906,7 +906,7 @@ func TestValidateEnv(t *testing.T) { | |
}, | ||
}, | ||
}}, | ||
expectedError: "[0].valueFrom.fieldRef.fieldPath: unsupported value 'metadata.annotations', Details: supported values: metadata.name, metadata.namespace, status.podIP", | ||
expectedError: `[0].valueFrom.fieldRef.fieldPath: Unsupported value: "metadata.annotations": supported values: metadata.name, metadata.namespace, status.podIP`, | ||
}, | ||
{ | ||
name: "unsupported fieldPath", | ||
|
@@ -919,7 +919,7 @@ func TestValidateEnv(t *testing.T) { | |
}, | ||
}, | ||
}}, | ||
expectedError: "valueFrom.fieldRef.fieldPath: unsupported value 'status.phase', Details: supported values: metadata.name, metadata.namespace, status.podIP", | ||
expectedError: `valueFrom.fieldRef.fieldPath: Unsupported value: "status.phase": supported values: metadata.name, metadata.namespace, status.podIP`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The multiple colons in a single sentence still makes me frown. Is this following some tradition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's pretty go-style - add details: at the front. On Tue, Dec 15, 2015 at 11:42 PM, Chao Xu notifications@github.com wrote:
|
||
}, | ||
} | ||
for _, tc := range errorCases { | ||
|
@@ -3314,7 +3314,7 @@ func TestValidateLimitRange(t *testing.T) { | |
}, | ||
}, | ||
}}, | ||
"not supported when limit type is Pod", | ||
"may not be specified when `type` is 'Pod'", | ||
}, | ||
"default-request-limit-type-pod": { | ||
api.LimitRange{ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: "foo"}, Spec: api.LimitRangeSpec{ | ||
|
@@ -3327,7 +3327,7 @@ func TestValidateLimitRange(t *testing.T) { | |
}, | ||
}, | ||
}}, | ||
"not supported when limit type is Pod", | ||
"may not be specified when `type` is 'Pod'", | ||
}, | ||
"min value 100m is greater than max value 10m": { | ||
api.LimitRange{ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: "foo"}, Spec: api.LimitRangeSpec{ | ||
|
@@ -4002,7 +4002,7 @@ func TestValidateEndpoints(t *testing.T) { | |
}, | ||
}, | ||
errorType: "FieldValueInvalid", | ||
errorDetail: "invalid IPv4 address", | ||
errorDetail: "must be a valid IPv4 address", | ||
}, | ||
"Multiple ports, one without name": { | ||
endpoints: api.Endpoints{ | ||
|
@@ -4052,7 +4052,7 @@ func TestValidateEndpoints(t *testing.T) { | |
}, | ||
}, | ||
errorType: "FieldValueInvalid", | ||
errorDetail: "invalid IPv4 address", | ||
errorDetail: "must be a valid IPv4 address", | ||
}, | ||
"Port missing number": { | ||
endpoints: api.Endpoints{ | ||
|
@@ -4122,7 +4122,7 @@ func TestValidateEndpoints(t *testing.T) { | |
|
||
for k, v := range errorCases { | ||
if errs := ValidateEndpoints(&v.endpoints); len(errs) == 0 || errs[0].Type != v.errorType || !strings.Contains(errs[0].Detail, v.errorDetail) { | ||
t.Errorf("Expected error type %s with detail %s for %s, got %v", v.errorType, v.errorDetail, k, errs) | ||
t.Errorf("[%s] Expected error type %s with detail %q, got %v", k, v.errorType, v.errorDetail, errs) | ||
} | ||
} | ||
} | ||
|
@@ -4172,7 +4172,7 @@ func TestValidateSecurityContext(t *testing.T) { | |
} | ||
for k, v := range successCases { | ||
if errs := ValidateSecurityContext(v.sc, field.NewPath("field")); len(errs) != 0 { | ||
t.Errorf("Expected success for %s, got %v", k, errs) | ||
t.Errorf("[%s] Expected success, got %v", k, errs) | ||
} | ||
} | ||
|
||
|
@@ -4192,17 +4192,17 @@ func TestValidateSecurityContext(t *testing.T) { | |
"request privileged when capabilities forbids": { | ||
sc: privRequestWithGlobalDeny, | ||
errorType: "FieldValueForbidden", | ||
errorDetail: "", | ||
errorDetail: "disallowed by policy", | ||
}, | ||
"negative RunAsUser": { | ||
sc: negativeRunAsUser, | ||
errorType: "FieldValueInvalid", | ||
errorDetail: "runAsUser cannot be negative", | ||
errorDetail: isNegativeErrorMsg, | ||
}, | ||
} | ||
for k, v := range errorCases { | ||
if errs := ValidateSecurityContext(v.sc, field.NewPath("field")); len(errs) == 0 || errs[0].Type != v.errorType || errs[0].Detail != v.errorDetail { | ||
t.Errorf("Expected error type %s with detail %s for %s, got %v", v.errorType, v.errorDetail, k, errs) | ||
if errs := ValidateSecurityContext(v.sc, field.NewPath("field")); len(errs) == 0 || errs[0].Type != v.errorType || !strings.Contains(errs[0].Detail, v.errorDetail) { | ||
t.Errorf("[%s] Expected error type %q with detail %q, got %v", k, v.errorType, v.errorDetail, errs) | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
formatting requirement
? It should be consistent with the next point.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I specifically split the negative case into formatting and behavioral, but in the positive sense there is no difference in words.