mirror of https://github.com/docker/cli.git
Tweak validation messages
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
b5d0d179e7
commit
e5702e000c
|
@ -100,7 +100,7 @@ func TestParseEnvFileBadlyFormattedFile(t *testing.T) {
|
|||
if _, ok := err.(ErrBadKey); !ok {
|
||||
t.Fatalf("Expected an ErrBadKey, got [%v]", err)
|
||||
}
|
||||
expectedMessage := "poorly formatted environment: variable 'f ' has white spaces"
|
||||
expectedMessage := "poorly formatted environment: variable 'f ' contains whitespaces"
|
||||
if err.Error() != expectedMessage {
|
||||
t.Fatalf("Expected [%v], got [%v]", expectedMessage, err.Error())
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ another invalid line`
|
|||
if _, ok := err.(ErrBadKey); !ok {
|
||||
t.Fatalf("Expected an ErrBadKey, got [%v]", err)
|
||||
}
|
||||
expectedMessage := "poorly formatted environment: variable 'first line' has white spaces"
|
||||
expectedMessage := "poorly formatted environment: variable 'first line' contains whitespaces"
|
||||
if err.Error() != expectedMessage {
|
||||
t.Fatalf("Expected [%v], got [%v]", expectedMessage, err.Error())
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ func parseKeyValueFile(filename string, emptyFn func(string) (string, bool)) ([]
|
|||
// trim the front of a variable, but nothing else
|
||||
variable := strings.TrimLeft(data[0], whiteSpaces)
|
||||
if strings.ContainsAny(variable, whiteSpaces) {
|
||||
return []string{}, ErrBadKey{fmt.Sprintf("variable '%s' has white spaces", variable)}
|
||||
return []string{}, ErrBadKey{fmt.Sprintf("variable '%s' contains whitespaces", variable)}
|
||||
}
|
||||
if len(variable) == 0 {
|
||||
return []string{}, ErrBadKey{fmt.Sprintf("no variable name on line '%s'", line)}
|
||||
|
|
|
@ -281,10 +281,10 @@ func ValidateLabel(val string) (string, error) {
|
|||
arr := strings.SplitN(val, "=", 2)
|
||||
key := strings.TrimLeft(arr[0], whiteSpaces)
|
||||
if key == "" {
|
||||
return "", fmt.Errorf("empty label name: '%s'", val)
|
||||
return "", fmt.Errorf("invalid label '%s': empty name", val)
|
||||
}
|
||||
if strings.ContainsAny(key, whiteSpaces) {
|
||||
return "", fmt.Errorf("label '%s' has white spaces", key)
|
||||
return "", fmt.Errorf("label '%s' contains whitespaces", key)
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
|
|
|
@ -184,17 +184,17 @@ func TestValidateLabel(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
name: "empty",
|
||||
expectedErr: `empty label name: ''`,
|
||||
expectedErr: `invalid label '': empty name`,
|
||||
},
|
||||
{
|
||||
name: "whitespace only ",
|
||||
value: " ",
|
||||
expectedErr: `empty label name: ' '`,
|
||||
expectedErr: `invalid label ' ': empty name`,
|
||||
},
|
||||
{
|
||||
name: "whitespace around equal-sign",
|
||||
value: " = ",
|
||||
expectedErr: `empty label name: ' = '`,
|
||||
expectedErr: `invalid label ' = ': empty name`,
|
||||
},
|
||||
{
|
||||
name: "leading whitespace",
|
||||
|
@ -203,12 +203,12 @@ func TestValidateLabel(t *testing.T) {
|
|||
{
|
||||
name: "whitespaces in key without value",
|
||||
value: "this is a label without value",
|
||||
expectedErr: `label 'this is a label without value' has white spaces`,
|
||||
expectedErr: `label 'this is a label without value' contains whitespaces`,
|
||||
},
|
||||
{
|
||||
name: "whitespaces in key",
|
||||
value: "this is a label=value",
|
||||
expectedErr: `label 'this is a label' has white spaces`,
|
||||
expectedErr: `label 'this is a label' contains whitespaces`,
|
||||
},
|
||||
{
|
||||
name: "whitespaces in value",
|
||||
|
@ -229,7 +229,7 @@ func TestValidateLabel(t *testing.T) {
|
|||
{
|
||||
name: "no key",
|
||||
value: "=label",
|
||||
expectedErr: `empty label name: '=label'`,
|
||||
expectedErr: `invalid label '=label': empty name`,
|
||||
},
|
||||
{
|
||||
name: "empty value",
|
||||
|
|
Loading…
Reference in New Issue