Skip to content
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

helper/validation: StringInSlice: Single quote slice elements #1237

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/ENHANCEMENTS-20230829-141309.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: ENHANCEMENTS
body: 'helper/validation: Added quoting in `StringInSlice` error diagnostic output to
prevent confusion with values that contain spaces'
time: 2023-08-29T14:13:09.735543+02:00
custom:
Issue: "464"
2 changes: 1 addition & 1 deletion helper/validation/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func StringInSlice(valid []string, ignoreCase bool) schema.SchemaValidateFunc {
}
}

errors = append(errors, fmt.Errorf("expected %s to be one of %v, got %s", k, valid, v))
errors = append(errors, fmt.Errorf("expected %s to be one of %q, got %s", k, valid, v))
return warnings, errors
}
}
Expand Down
4 changes: 2 additions & 2 deletions helper/validation/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,12 @@ func TestValidationStringInSlice(t *testing.T) {
{
val: "VALIDVALUE",
f: StringInSlice([]string{"ValidValue", "AnotherValidValue"}, false),
expectedErr: regexp.MustCompile(`expected [\w]+ to be one of \[ValidValue AnotherValidValue\], got VALIDVALUE`),
expectedErr: regexp.MustCompile(`expected [\w]+ to be one of \["ValidValue" "AnotherValidValue"\], got VALIDVALUE`),
},
{
val: "InvalidValue",
f: StringInSlice([]string{"ValidValue", "AnotherValidValue"}, false),
expectedErr: regexp.MustCompile(`expected [\w]+ to be one of \[ValidValue AnotherValidValue\], got InvalidValue`),
expectedErr: regexp.MustCompile(`expected [\w]+ to be one of \["ValidValue" "AnotherValidValue"\], got InvalidValue`),
},
{
val: 1,
Expand Down
Loading