Skip to content

Commit 946fad5

Browse files
trentrosenbaumburythehammer
authored andcommitted
Updates to check that the QPF is within 2x to 16x range
1 parent fda318d commit 946fad5

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

provider/resource_rediscloud_pro_subscription.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,18 @@ func resourceRedisCloudProSubscription() *schema.Resource {
294294
Type: schema.TypeString,
295295
Optional: true,
296296
Computed: true,
297+
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
298+
v := val.(string)
299+
matched, err := regexp.MatchString(`^(2|4|6|8|10|12|14|16)x$`, v)
300+
if err != nil {
301+
errs = append(errs, fmt.Errorf("regex match failed: %s", err))
302+
return
303+
}
304+
if !matched {
305+
errs = append(errs, fmt.Errorf("%q must be an even value between 2x and 16x (inclusive), got: %s", key, v))
306+
}
307+
return
308+
},
297309
},
298310
"throughput_measurement_by": {
299311
Description: "Throughput measurement method, (either ‘number-of-shards’ or ‘operations-per-second’)",

provider/resource_rediscloud_pro_subscription_qpf_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,23 @@ func TestAccResourceRedisCloudProSubscription_missingRediSearchModule(t *testing
127127

128128
testSubErrorCase(t, config, regexp.MustCompile("query_performance_factor\" requires the \"modules\" list to contain \"RediSearch"))
129129
}
130+
131+
func TestAccRedisCloudDatabase_invalidQueryPerformanceFactors(t *testing.T) {
132+
name := acctest.RandomWithPrefix("tf-test")
133+
password := acctest.RandString(20)
134+
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")
135+
136+
config := formatDatabaseConfig(name, testCloudAccountName, password, "5x", `modules = [{ name = "RediSearch" }]`)
137+
138+
testSubErrorCase(t, config, regexp.MustCompile(`"creation_plan\.0\.query_performance_factor" must be an even value between 2x and 16x \(inclusive\), got: 5x`))
139+
}
140+
141+
func TestAccRedisCloudDatabase_invalidQueryPerformanceFactors_outOfRange(t *testing.T) {
142+
name := acctest.RandomWithPrefix("tf-test")
143+
password := acctest.RandString(20)
144+
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")
145+
146+
config := formatDatabaseConfig(name, testCloudAccountName, password, "30x", `modules = [{ name = "RediSearch" }]`)
147+
148+
testSubErrorCase(t, config, regexp.MustCompile(`"creation_plan\.0\.query_performance_factor" must be an even value between 2x and 16x \(inclusive\), got: 30x`))
149+
}

0 commit comments

Comments
 (0)