From 3f94215f32560ad64f9e78f4303500a35fb54e02 Mon Sep 17 00:00:00 2001 From: Frank Villaro-Dixon Date: Tue, 29 Aug 2023 11:22:48 +0200 Subject: [PATCH] helper/validation: `StringInSlice`: Single quote slice elements The validation function's error is ambiguous when dealing with slices containing spaces. For example: ``` expected role_name to be one of [Apache Spark Administrator Synapse Credential User Synapse Administrator] ``` By changing the format verb, the error becomes more user friendly: ``` expected role_name to be one of ["Apache Spark Administrator" "Synapse Credential User" "Synapse Administrator"] ``` This fixes #464 Signed-off-by: Frank Villaro-Dixon --- helper/validation/strings.go | 2 +- helper/validation/strings_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helper/validation/strings.go b/helper/validation/strings.go index 19c9055f39b..375a698f2c2 100644 --- a/helper/validation/strings.go +++ b/helper/validation/strings.go @@ -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 } } diff --git a/helper/validation/strings_test.go b/helper/validation/strings_test.go index c01e9a50287..9068c4f72f3 100644 --- a/helper/validation/strings_test.go +++ b/helper/validation/strings_test.go @@ -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,