Skip to content

Commit a3b98e6

Browse files
trentrosenbaumburythehammer
authored andcommitted
Udpates to validate QPF range value
1 parent 946fad5 commit a3b98e6

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

provider/resource_rediscloud_pro_database.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provider
33
import (
44
"context"
55
"fmt"
6+
"regexp"
67
"strconv"
78
"strings"
89
"time"
@@ -221,6 +222,18 @@ func resourceRedisCloudProDatabase() *schema.Resource {
221222
Optional: true,
222223
Computed: true,
223224
ForceNew: true,
225+
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
226+
v := val.(string)
227+
matched, err := regexp.MatchString(`^(2|4|6|8|10|12|14|16)x$`, v)
228+
if err != nil {
229+
errs = append(errs, fmt.Errorf("regex match failed: %s", err))
230+
return
231+
}
232+
if !matched {
233+
errs = append(errs, fmt.Errorf("%q must be an even value between 2x and 16x (inclusive), got: %s", key, v))
234+
}
235+
return
236+
},
224237
},
225238
"modules": {
226239
Description: "Modules to be provisioned in the database",

provider/resource_rediscloud_pro_database_qpf_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,23 @@ func TestAccResourceRedisCloudProDatabase_missingRediSearchModule(t *testing.T)
161161

162162
testErrorCase(t, config, regexp.MustCompile("query_performance_factor\" requires the \"modules\" list to contain \"RediSearch"))
163163
}
164+
165+
func TestAccResourceRedisCloudProDatabase_invalidQueryPerformanceFactors(t *testing.T) {
166+
name := acctest.RandomWithPrefix("tf-test")
167+
password := acctest.RandString(20)
168+
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")
169+
170+
config := formatDatabaseConfig(name, testCloudAccountName, password, "5x", `modules = [{ name = "RediSearch" }]`)
171+
172+
testSubErrorCase(t, config, regexp.MustCompile(`"creation_plan\.0\.query_performance_factor" must be an even value between 2x and 16x \(inclusive\), got: 5x`))
173+
}
174+
175+
func TestAccResourceRedisCloudProDatabase_invalidQueryPerformanceFactors_outOfRange(t *testing.T) {
176+
name := acctest.RandomWithPrefix("tf-test")
177+
password := acctest.RandString(20)
178+
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")
179+
180+
config := formatDatabaseConfig(name, testCloudAccountName, password, "30x", `modules = [{ name = "RediSearch" }]`)
181+
182+
testSubErrorCase(t, config, regexp.MustCompile(`"creation_plan\.0\.query_performance_factor" must be an even value between 2x and 16x \(inclusive\), got: 30x`))
183+
}

provider/resource_rediscloud_pro_subscription_qpf_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func TestAccResourceRedisCloudProSubscription_missingRediSearchModule(t *testing
128128
testSubErrorCase(t, config, regexp.MustCompile("query_performance_factor\" requires the \"modules\" list to contain \"RediSearch"))
129129
}
130130

131-
func TestAccRedisCloudDatabase_invalidQueryPerformanceFactors(t *testing.T) {
131+
func TestAccResourceRedisCloudProSubscription_invalidQueryPerformanceFactors(t *testing.T) {
132132
name := acctest.RandomWithPrefix("tf-test")
133133
password := acctest.RandString(20)
134134
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")
@@ -138,7 +138,7 @@ func TestAccRedisCloudDatabase_invalidQueryPerformanceFactors(t *testing.T) {
138138
testSubErrorCase(t, config, regexp.MustCompile(`"creation_plan\.0\.query_performance_factor" must be an even value between 2x and 16x \(inclusive\), got: 5x`))
139139
}
140140

141-
func TestAccRedisCloudDatabase_invalidQueryPerformanceFactors_outOfRange(t *testing.T) {
141+
func TestAccResourceRedisCloudProSubscription_invalidQueryPerformanceFactors_outOfRange(t *testing.T) {
142142
name := acctest.RandomWithPrefix("tf-test")
143143
password := acctest.RandString(20)
144144
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")

0 commit comments

Comments
 (0)