From 563431e05c56ad8bacecdd076bb70fa7a8fc738c Mon Sep 17 00:00:00 2001 From: noah-troncoso <123982978+noah-troncoso@users.noreply.github.com> Date: Thu, 16 May 2024 00:21:59 -0400 Subject: [PATCH] 144: Accept empty string values in feature state resources (#145) 144: simplify test --- flagsmith/resource_feature_state.go | 3 ++- flagsmith/resource_feature_state_test.go | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/flagsmith/resource_feature_state.go b/flagsmith/resource_feature_state.go index 2fbc8bb..220113c 100644 --- a/flagsmith/resource_feature_state.go +++ b/flagsmith/resource_feature_state.go @@ -97,8 +97,9 @@ func (t *featureStateResource) Schema(ctx context.Context, req resource.SchemaRe Optional: true, Validators: []validator.String{ // Validate string value satisfies the regular expression for no leading or trailing whitespace + // but allow empty string stringvalidator.RegexMatches( - regexp.MustCompile(`^\S[\s\S]*\S$`), + regexp.MustCompile(`^\S[\s\S]*\S$|^$`), "Leading and trailing whitespace is not allowed", ), }, diff --git a/flagsmith/resource_feature_state_test.go b/flagsmith/resource_feature_state_test.go index 6a8640f..2ead224 100644 --- a/flagsmith/resource_feature_state_test.go +++ b/flagsmith/resource_feature_state_test.go @@ -27,7 +27,11 @@ func TestAccEnvironmentFeatureStateResource(t *testing.T) { Config: testAccEnvironmentFeatureStateResourceConfig(" some_value ", true), ExpectError: regexp.MustCompile(`Attribute feature_state_value.string_value Leading and trailing whitespace is\n.*not allowed`), }, - + // Ensure that empty strings pass validation + { + Config: testAccEnvironmentFeatureStateResourceConfig("", true), + ExpectError: nil, + }, // Create and Read testing { Config: testAccEnvironmentFeatureStateResourceConfig("one", true),