Skip to content

Commit 563431e

Browse files
144: Accept empty string values in feature state resources (#145)
144: simplify test
1 parent 3657527 commit 563431e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

flagsmith/resource_feature_state.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ func (t *featureStateResource) Schema(ctx context.Context, req resource.SchemaRe
9797
Optional: true,
9898
Validators: []validator.String{
9999
// Validate string value satisfies the regular expression for no leading or trailing whitespace
100+
// but allow empty string
100101
stringvalidator.RegexMatches(
101-
regexp.MustCompile(`^\S[\s\S]*\S$`),
102+
regexp.MustCompile(`^\S[\s\S]*\S$|^$`),
102103
"Leading and trailing whitespace is not allowed",
103104
),
104105
},

flagsmith/resource_feature_state_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ func TestAccEnvironmentFeatureStateResource(t *testing.T) {
2727
Config: testAccEnvironmentFeatureStateResourceConfig(" some_value ", true),
2828
ExpectError: regexp.MustCompile(`Attribute feature_state_value.string_value Leading and trailing whitespace is\n.*not allowed`),
2929
},
30-
30+
// Ensure that empty strings pass validation
31+
{
32+
Config: testAccEnvironmentFeatureStateResourceConfig("", true),
33+
ExpectError: nil,
34+
},
3135
// Create and Read testing
3236
{
3337
Config: testAccEnvironmentFeatureStateResourceConfig("one", true),

0 commit comments

Comments
 (0)