Skip to content

Commit

Permalink
Tweak validation messages
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Mar 19, 2019
1 parent b5d0d17 commit e5702e0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions opts/envfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion opts/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
4 changes: 2 additions & 2 deletions opts/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions opts/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit e5702e0

Please sign in to comment.