@@ -16,8 +16,8 @@ import (
1616 "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1717)
1818
19- // Checks CRUDI (CREATE, READ, UPDATE, IMPORT) operations on the database resource with Redis 8.
20- func TestAccResourceRedisCloudProDatabase_Redis8_CRUDI (t * testing.T ) {
19+ // checks that a redis 8 database can be provisioned
20+ func TestAccResourceRedisCloudProDatabase_Redis8 (t * testing.T ) {
2121
2222 utils .AccRequiresEnvVar (t , "EXECUTE_TESTS" )
2323
@@ -34,9 +34,90 @@ func TestAccResourceRedisCloudProDatabase_Redis8_CRUDI(t *testing.T) {
3434 ProviderFactories : providerFactories ,
3535 CheckDestroy : testAccCheckProSubscriptionDestroy ,
3636 Steps : []resource.TestStep {
37- // Test database and replica database creation with Redis 7.2
3837 {
3938 Config : getRedis8DatabaseConfig (t , testCloudAccountName , name , password ),
39+ Check : resource .ComposeAggregateTestCheckFunc (
40+ resource .TestCheckResourceAttr (resourceName , "name" , "example" ),
41+ resource .TestCheckResourceAttr (resourceName , "protocol" , "redis" ),
42+ resource .TestCheckResourceAttr (resourceName , "dataset_size_in_gb" , "3" ),
43+ resource .TestCheckResourceAttr (resourceName , "replication" , "false" ),
44+ resource .TestCheckResourceAttr (resourceName , "support_oss_cluster_api" , "false" ),
45+ resource .TestCheckResourceAttr (resourceName , "resp_version" , "resp3" ),
46+ resource .TestCheckResourceAttr (resourceName , "throughput_measurement_by" , "operations-per-second" ),
47+ resource .TestCheckResourceAttr (resourceName , "throughput_measurement_value" , "1000" ),
48+ resource .TestCheckResourceAttr (resourceName , "data_persistence" , "none" ),
49+ resource .TestCheckResourceAttr (resourceName , "data_eviction" , "allkeys-random" ),
50+ resource .TestCheckResourceAttr (resourceName , "average_item_size_in_bytes" , "0" ),
51+ resource .TestCheckResourceAttr (resourceName , "client_ssl_certificate" , "" ),
52+ resource .TestCheckResourceAttr (resourceName , "periodic_backup_path" , "" ),
53+ resource .TestCheckResourceAttr (resourceName , "external_endpoint_for_oss_cluster_api" , "false" ),
54+ resource .TestCheckResourceAttr (resourceName , "password" , password ),
55+ resource .TestCheckResourceAttr (resourceName , "alert.#" , "1" ),
56+ resource .TestCheckResourceAttr (resourceName , "alert.0.name" , "dataset-size" ),
57+ resource .TestCheckResourceAttr (resourceName , "alert.0.value" , "1" ),
58+ resource .TestCheckResourceAttr (resourceName , "enable_default_user" , "true" ),
59+ resource .TestCheckResourceAttr (resourceName , "redis_version" , "8.0" ),
60+
61+ resource .TestCheckResourceAttr (resourceName , "tags.market" , "emea" ),
62+ resource .TestCheckResourceAttr (resourceName , "tags.material" , "cardboard" ),
63+
64+ // Test databases exist
65+ func (s * terraform.State ) error {
66+ r := s .RootModule ().Resources [subscriptionResourceName ]
67+
68+ var err error
69+ subId , err = strconv .Atoi (r .Primary .ID )
70+ if err != nil {
71+ return fmt .Errorf ("couldn't parse the subscription ID: %s" , redis .StringValue (& r .Primary .ID ))
72+ }
73+
74+ apiClient := testProvider .Meta ().(* client.ApiClient )
75+ sub , err := apiClient .Client .Subscription .Get (context .TODO (), subId )
76+ if err != nil {
77+ return err
78+ }
79+
80+ if redis .StringValue (sub .Name ) != name {
81+ return fmt .Errorf ("unexpected name value: %s" , redis .StringValue (sub .Name ))
82+ }
83+
84+ listDb := apiClient .Client .Database .List (context .TODO (), subId )
85+ if listDb .Next () != true {
86+ return fmt .Errorf ("no database found: %s" , listDb .Err ())
87+ }
88+ if listDb .Err () != nil {
89+ return listDb .Err ()
90+ }
91+
92+ return nil
93+ },
94+ ),
95+ },
96+ },
97+ })
98+ }
99+
100+ // Checks that users can upgrade from 7.2 to 8.0
101+ func TestAccResourceRedisCloudProDatabase_Redis8_Upgrade (t * testing.T ) {
102+
103+ utils .AccRequiresEnvVar (t , "EXECUTE_TESTS" )
104+
105+ name := acctest .RandomWithPrefix (testResourcePrefix )
106+ password := acctest .RandString (20 )
107+ const resourceName = "rediscloud_subscription_database.example"
108+ const subscriptionResourceName = "rediscloud_subscription.example"
109+ testCloudAccountName := os .Getenv ("AWS_TEST_CLOUD_ACCOUNT_NAME" )
110+
111+ var subId int
112+
113+ resource .ParallelTest (t , resource.TestCase {
114+ PreCheck : func () { testAccPreCheck (t ); testAccAwsPreExistingCloudAccountPreCheck (t ) },
115+ ProviderFactories : providerFactories ,
116+ CheckDestroy : testAccCheckProSubscriptionDestroy ,
117+ Steps : []resource.TestStep {
118+ // Test database and replica database creation with Redis 7.2
119+ {
120+ Config : getRedis7DatabaseConfig (t , testCloudAccountName , name , password ),
40121 Check : resource .ComposeAggregateTestCheckFunc (
41122 resource .TestCheckResourceAttr (resourceName , "name" , "example" ),
42123 resource .TestCheckResourceAttr (resourceName , "protocol" , "redis" ),
@@ -96,7 +177,7 @@ func TestAccResourceRedisCloudProDatabase_Redis8_CRUDI(t *testing.T) {
96177 },
97178 // Test database is updated successfully to Redis 8.0
98179 {
99- Config : getRedis8DatabaseUpdateConfig (t , testCloudAccountName , name , password ),
180+ Config : getRedis8DatabaseConfig (t , testCloudAccountName , name , password ),
100181 Check : resource .ComposeAggregateTestCheckFunc (
101182 resource .TestCheckResourceAttr (resourceName , "redis_version" , "8.0" ),
102183 ),
@@ -126,13 +207,13 @@ func TestAccResourceRedisCloudProDatabase_Redis8_ModulesBlocked(t *testing.T) {
126207 })
127208}
128209
129- func getRedis8DatabaseConfig (t * testing.T , cloudAccountName , subscriptionName , password string ) string {
130- content := utils .GetTestConfig (t , "./pro/testdata/pro_database_redis_8 .tf" )
210+ func getRedis7DatabaseConfig (t * testing.T , cloudAccountName , subscriptionName , password string ) string {
211+ content := utils .GetTestConfig (t , "./pro/testdata/pro_database_redis_7 .tf" )
131212 return fmt .Sprintf (content , cloudAccountName , subscriptionName , password )
132213}
133214
134- func getRedis8DatabaseUpdateConfig (t * testing.T , cloudAccountName , subscriptionName , password string ) string {
135- content := utils .GetTestConfig (t , "./pro/testdata/pro_database_redis_8_update .tf" )
215+ func getRedis8DatabaseConfig (t * testing.T , cloudAccountName , subscriptionName , password string ) string {
216+ content := utils .GetTestConfig (t , "./pro/testdata/pro_database_redis_8 .tf" )
136217 return fmt .Sprintf (content , cloudAccountName , subscriptionName , password )
137218}
138219
0 commit comments