Skip to content

Commit c3ae185

Browse files
authored
Remove double quoting in string validator descriptions (#152)
* Remove double quoting in string validator descriptions (#149) * Adding changelog entry (#149)
1 parent 5fe0aad commit c3ae185

9 files changed

+142
-6
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: BUG FIXES
2+
body: 'stringvalidator: Removed double quoting in `Description` returned from `NoneOf`,
3+
`NoneOfCaseInsensitive`, `OneOf` and `OneOfCaseInsensitive` validators'
4+
time: 2023-08-01T10:47:45.629204+01:00
5+
custom:
6+
Issue: "152"

stringvalidator/none_of.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (v noneOfValidator) Description(ctx context.Context) string {
2525
}
2626

2727
func (v noneOfValidator) MarkdownDescription(_ context.Context) string {
28-
return fmt.Sprintf("value must be none of: %q", v.values)
28+
return fmt.Sprintf("value must be none of: %s", v.values)
2929
}
3030

3131
func (v noneOfValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) {

stringvalidator/none_of_case_insensitive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (v noneOfCaseInsensitiveValidator) Description(ctx context.Context) string
2626
}
2727

2828
func (v noneOfCaseInsensitiveValidator) MarkdownDescription(_ context.Context) string {
29-
return fmt.Sprintf("value must be none of: %q", v.values)
29+
return fmt.Sprintf("value must be none of: %s", v.values)
3030
}
3131

3232
func (v noneOfCaseInsensitiveValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) {

stringvalidator/none_of_case_insensitive_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import (
77
"context"
88
"testing"
99

10-
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
10+
"github.com/google/go-cmp/cmp"
1111
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1212
"github.com/hashicorp/terraform-plugin-framework/types"
13+
14+
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1315
)
1416

1517
func TestNoneOfCaseInsensitiveValidator(t *testing.T) {
@@ -93,3 +95,34 @@ func TestNoneOfCaseInsensitiveValidator(t *testing.T) {
9395
})
9496
}
9597
}
98+
99+
func TestNoneOfCaseInsensitiveValidator_Description(t *testing.T) {
100+
t.Parallel()
101+
102+
type testCase struct {
103+
in []string
104+
expected string
105+
}
106+
107+
testCases := map[string]testCase{
108+
"quoted-once": {
109+
in: []string{"foo", "bar", "baz"},
110+
expected: `value must be none of: ["foo" "bar" "baz"]`,
111+
},
112+
}
113+
114+
for name, test := range testCases {
115+
name, test := name, test
116+
t.Run(name, func(t *testing.T) {
117+
t.Parallel()
118+
119+
v := stringvalidator.NoneOfCaseInsensitive(test.in...)
120+
121+
got := v.MarkdownDescription(context.Background())
122+
123+
if diff := cmp.Diff(got, test.expected); diff != "" {
124+
t.Errorf("unexpected difference: %s", diff)
125+
}
126+
})
127+
}
128+
}

stringvalidator/none_of_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"testing"
99

10+
"github.com/google/go-cmp/cmp"
1011
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1112
"github.com/hashicorp/terraform-plugin-framework/types"
1213

@@ -94,3 +95,34 @@ func TestNoneOfValidator(t *testing.T) {
9495
})
9596
}
9697
}
98+
99+
func TestNoneOfValidator_Description(t *testing.T) {
100+
t.Parallel()
101+
102+
type testCase struct {
103+
in []string
104+
expected string
105+
}
106+
107+
testCases := map[string]testCase{
108+
"quoted-once": {
109+
in: []string{"foo", "bar", "baz"},
110+
expected: `value must be none of: ["foo" "bar" "baz"]`,
111+
},
112+
}
113+
114+
for name, test := range testCases {
115+
name, test := name, test
116+
t.Run(name, func(t *testing.T) {
117+
t.Parallel()
118+
119+
v := stringvalidator.NoneOf(test.in...)
120+
121+
got := v.MarkdownDescription(context.Background())
122+
123+
if diff := cmp.Diff(got, test.expected); diff != "" {
124+
t.Errorf("unexpected difference: %s", diff)
125+
}
126+
})
127+
}
128+
}

stringvalidator/one_of.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (v oneOfValidator) Description(ctx context.Context) string {
2525
}
2626

2727
func (v oneOfValidator) MarkdownDescription(_ context.Context) string {
28-
return fmt.Sprintf("value must be one of: %q", v.values)
28+
return fmt.Sprintf("value must be one of: %s", v.values)
2929
}
3030

3131
func (v oneOfValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) {

stringvalidator/one_of_case_insensitive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (v oneOfCaseInsensitiveValidator) Description(ctx context.Context) string {
2626
}
2727

2828
func (v oneOfCaseInsensitiveValidator) MarkdownDescription(_ context.Context) string {
29-
return fmt.Sprintf("value must be one of: %q", v.values)
29+
return fmt.Sprintf("value must be one of: %s", v.values)
3030
}
3131

3232
func (v oneOfCaseInsensitiveValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) {

stringvalidator/one_of_case_insensitive_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import (
77
"context"
88
"testing"
99

10-
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
10+
"github.com/google/go-cmp/cmp"
1111
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1212
"github.com/hashicorp/terraform-plugin-framework/types"
13+
14+
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1315
)
1416

1517
func TestOneOfCaseInsensitiveValidator(t *testing.T) {
@@ -93,3 +95,34 @@ func TestOneOfCaseInsensitiveValidator(t *testing.T) {
9395
})
9496
}
9597
}
98+
99+
func TestOneOfCaseInsensitiveValidator_Description(t *testing.T) {
100+
t.Parallel()
101+
102+
type testCase struct {
103+
in []string
104+
expected string
105+
}
106+
107+
testCases := map[string]testCase{
108+
"quoted-once": {
109+
in: []string{"foo", "bar", "baz"},
110+
expected: `value must be one of: ["foo" "bar" "baz"]`,
111+
},
112+
}
113+
114+
for name, test := range testCases {
115+
name, test := name, test
116+
t.Run(name, func(t *testing.T) {
117+
t.Parallel()
118+
119+
v := stringvalidator.OneOfCaseInsensitive(test.in...)
120+
121+
got := v.MarkdownDescription(context.Background())
122+
123+
if diff := cmp.Diff(got, test.expected); diff != "" {
124+
t.Errorf("unexpected difference: %s", diff)
125+
}
126+
})
127+
}
128+
}

stringvalidator/one_of_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"testing"
99

10+
"github.com/google/go-cmp/cmp"
1011
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1112
"github.com/hashicorp/terraform-plugin-framework/types"
1213

@@ -94,3 +95,34 @@ func TestOneOfValidator(t *testing.T) {
9495
})
9596
}
9697
}
98+
99+
func TestOneOfValidator_Description(t *testing.T) {
100+
t.Parallel()
101+
102+
type testCase struct {
103+
in []string
104+
expected string
105+
}
106+
107+
testCases := map[string]testCase{
108+
"quoted-once": {
109+
in: []string{"foo", "bar", "baz"},
110+
expected: `value must be one of: ["foo" "bar" "baz"]`,
111+
},
112+
}
113+
114+
for name, test := range testCases {
115+
name, test := name, test
116+
t.Run(name, func(t *testing.T) {
117+
t.Parallel()
118+
119+
v := stringvalidator.OneOf(test.in...)
120+
121+
got := v.MarkdownDescription(context.Background())
122+
123+
if diff := cmp.Diff(got, test.expected); diff != "" {
124+
t.Errorf("unexpected difference: %s", diff)
125+
}
126+
})
127+
}
128+
}

0 commit comments

Comments
 (0)