mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-05-28 04:04:39 -04:00
use tweak pattern
This commit is contained in:
parent
97f9819f7e
commit
9c32e488db
1 changed files with 13 additions and 7 deletions
|
|
@ -53,31 +53,31 @@ func TestDeclarativeValidate(t *testing.T) {
|
|||
},
|
||||
// metadata.name
|
||||
"name: empty": {
|
||||
input: mkDeviceClass(func(dc *resource.DeviceClass) { dc.Name = "" }),
|
||||
input: mkDeviceClass(tweakName("")),
|
||||
expectedErrs: field.ErrorList{
|
||||
field.Required(field.NewPath("metadata", "name"), ""),
|
||||
},
|
||||
},
|
||||
"name: valid": {
|
||||
input: mkDeviceClass(func(dc *resource.DeviceClass) { dc.Name = "example.com" }),
|
||||
input: mkDeviceClass(tweakName("example.com")),
|
||||
},
|
||||
"name: invalid (uppercase)": {
|
||||
input: mkDeviceClass(func(dc *resource.DeviceClass) { dc.Name = "Invalid-Name" }),
|
||||
input: mkDeviceClass(tweakName("Invalid-Name")),
|
||||
expectedErrs: field.ErrorList{
|
||||
field.Invalid(field.NewPath("metadata", "name"), "Invalid-Name", "").WithOrigin("format=k8s-long-name"),
|
||||
},
|
||||
},
|
||||
"name: invalid (start with dash)": {
|
||||
input: mkDeviceClass(func(dc *resource.DeviceClass) { dc.Name = "-invalid" }),
|
||||
input: mkDeviceClass(tweakName("-invalid")),
|
||||
expectedErrs: field.ErrorList{
|
||||
field.Invalid(field.NewPath("metadata", "name"), "-invalid", "").WithOrigin("format=k8s-long-name"),
|
||||
},
|
||||
},
|
||||
"name: max length": {
|
||||
input: mkDeviceClass(func(dc *resource.DeviceClass) { dc.Name = strings.Repeat("a", 253) }),
|
||||
input: mkDeviceClass(tweakName(strings.Repeat("a", 253))),
|
||||
},
|
||||
"name: too long": {
|
||||
input: mkDeviceClass(func(dc *resource.DeviceClass) { dc.Name = strings.Repeat("a", 254) }),
|
||||
input: mkDeviceClass(tweakName(strings.Repeat("a", 254))),
|
||||
expectedErrs: field.ErrorList{
|
||||
field.Invalid(field.NewPath("metadata", "name"), strings.Repeat("a", 254), "").WithOrigin("format=k8s-long-name"),
|
||||
},
|
||||
|
|
@ -172,7 +172,7 @@ func TestDeclarativeValidateUpdate(t *testing.T) {
|
|||
// metadata.name
|
||||
"name: changed": {
|
||||
old: mkDeviceClass(),
|
||||
update: mkDeviceClass(func(dc *resource.DeviceClass) { dc.Name += "x" }),
|
||||
update: mkDeviceClass(tweakName("test-classx")),
|
||||
expectedErrs: field.ErrorList{
|
||||
field.Invalid(field.NewPath("metadata", "name"), "test-classx", "field is immutable"),
|
||||
},
|
||||
|
|
@ -289,6 +289,12 @@ func mkDeviceClass(mutators ...func(*resource.DeviceClass)) resource.DeviceClass
|
|||
return dc
|
||||
}
|
||||
|
||||
func tweakName(name string) func(*resource.DeviceClass) {
|
||||
return func(dc *resource.DeviceClass) {
|
||||
dc.Name = name
|
||||
}
|
||||
}
|
||||
|
||||
func tweakSelectors(count int) func(*resource.DeviceClass) {
|
||||
return func(dc *resource.DeviceClass) {
|
||||
dc.Spec.Selectors = []resource.DeviceSelector{}
|
||||
|
|
|
|||
Loading…
Reference in a new issue