Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fs/value): Add validator for feature state string value #112

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ permissions:
env:
# Go language version to use for building. This value should also be updated
# in the release workflow if changed.
GO_VERSION: '1.19'
GO_VERSION: '1.20'

jobs:
# Ensure project builds before running testing matrix
Expand Down Expand Up @@ -63,8 +63,8 @@ jobs:
matrix:
# list whatever Terraform versions here you would like to support
terraform:
- '1.0.*'
- '1.1.*'
- '1.4.*'
- '1.5.*'
steps:
- uses: actions/setup-go@v4
with:
Expand Down
8 changes: 8 additions & 0 deletions flagsmith/resource_feature_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flagsmith
import (
"context"
"fmt"
"regexp"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
Expand Down Expand Up @@ -94,6 +95,13 @@ func (t *featureStateResource) Schema(ctx context.Context, req resource.SchemaRe
"string_value": schema.StringAttribute{
MarkdownDescription: "String value of the feature if the type is `unicode`.",
Optional: true,
Validators: []validator.String{
// Validate string value satisfies the regular expression for no leading or trailing whitespace
stringvalidator.RegexMatches(
regexp.MustCompile(`^\S[\s\S]*\S$`),
"Leading and trailing whitespace is not allowed",
),
},
},
"integer_value": schema.Int64Attribute{
MarkdownDescription: "Integer value of the feature if the type is `int`",
Expand Down
6 changes: 6 additions & 0 deletions flagsmith/resource_feature_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func TestAccEnvironmentFeatureStateResource(t *testing.T) {
Config: testAccInvalidFeatureStateValueConfig(),
ExpectError: regexp.MustCompile(`Exactly one of these attributes must be configured:\n\[feature_state_value.string_value,feature_state_value.integer_value,feature_state_value.boolean_value\]`),

},
// Test feature State string value validator
{
Config: testAccEnvironmentFeatureStateResourceConfig(" some_value ", true),
ExpectError: regexp.MustCompile(`Attribute feature_state_value.string_value Leading and trailing whitespace is\n.*not allowed`),

},

// Create and Read testing
Expand Down