Merge pull request #25801 from thaJeztah/improve-volume-validation-message
improve error message for volume names that are too short
This commit is contained in:
commit
b0b3249bc2
|
@ -256,6 +256,9 @@ func (r *Root) Scope() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Root) validateName(name string) error {
|
func (r *Root) validateName(name string) error {
|
||||||
|
if len(name) == 1 {
|
||||||
|
return validationError{fmt.Errorf("volume name is too short, names should be at least two alphanumeric characters")}
|
||||||
|
}
|
||||||
if !volumeNameRegex.MatchString(name) {
|
if !volumeNameRegex.MatchString(name) {
|
||||||
return validationError{fmt.Errorf("%q includes invalid characters for a local volume name, only %q are allowed", name, utils.RestrictedNameChars)}
|
return validationError{fmt.Errorf("%q includes invalid characters for a local volume name, only %q are allowed", name, utils.RestrictedNameChars)}
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,6 +138,7 @@ func TestCreate(t *testing.T) {
|
||||||
func TestValidateName(t *testing.T) {
|
func TestValidateName(t *testing.T) {
|
||||||
r := &Root{}
|
r := &Root{}
|
||||||
names := map[string]bool{
|
names := map[string]bool{
|
||||||
|
"x": false,
|
||||||
"/testvol": false,
|
"/testvol": false,
|
||||||
"thing.d": true,
|
"thing.d": true,
|
||||||
"hello-world": true,
|
"hello-world": true,
|
||||||
|
|
Loading…
Reference in New Issue