Skip to content

Commit

Permalink
144: Accept empty string values in feature state resources (#145)
Browse files Browse the repository at this point in the history
144: simplify test
  • Loading branch information
noah-troncoso authored May 16, 2024
1 parent 3657527 commit 563431e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion flagsmith/resource_feature_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
},
Expand Down
6 changes: 5 additions & 1 deletion flagsmith/resource_feature_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 563431e

Please sign in to comment.