Skip to content

Commit

Permalink
Aggregate test checks and other test refactoring (#543)
Browse files Browse the repository at this point in the history
* chore: refactoring tests to have aggregate checks

* chore: extracting out resource strings, setting them as consts

* More consts and aggs

---------

Co-authored-by: JohnSharpe <[email protected]>
  • Loading branch information
burythehammer and JohnSharpe authored Aug 6, 2024
1 parent 91b5a9c commit ae9215b
Show file tree
Hide file tree
Showing 24 changed files with 285 additions and 269 deletions.
13 changes: 7 additions & 6 deletions provider/datasource_rediscloud_cloud_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ import (
func TestAccDataSourceRedisCloudCloudAccount_basic(t *testing.T) {
name := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")

const testCloudAccount = "data.rediscloud_cloud_account.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccAwsPreExistingCloudAccountPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: nil, // test doesn't create a resource at the moment, so don't need to check anything
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccDatasourceRedisCloudCloudAccountDataSource, name),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"data.rediscloud_cloud_account.test", "id", regexp.MustCompile("^\\d*$")),
resource.TestCheckResourceAttr("data.rediscloud_cloud_account.test", "provider_type", "AWS"),
resource.TestCheckResourceAttr("data.rediscloud_cloud_account.test", "name", name),
resource.TestCheckResourceAttrSet("data.rediscloud_cloud_account.test", "access_key_id"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr(testCloudAccount, "id", regexp.MustCompile("^\\d*$")),
resource.TestCheckResourceAttr(testCloudAccount, "provider_type", "AWS"),
resource.TestCheckResourceAttr(testCloudAccount, "name", name),
resource.TestCheckResourceAttrSet(testCloudAccount, "access_key_id"),
),
},
},
Expand Down
9 changes: 5 additions & 4 deletions provider/datasource_rediscloud_data_persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ import (
)

func TestAccDataSourceRedisCloudDataPersistence_basic(t *testing.T) {
const dataPersistenceFoo = "data.rediscloud_data_persistence.foo"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: nil, // data persistence isn't a 'real' resource
Steps: []resource.TestStep{
{
Config: testAccDataSourceRedisCloudDataPersistence,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckTypeSetElemNestedAttrs("data.rediscloud_data_persistence.foo", "data_persistence.*", map[string]string{
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckTypeSetElemNestedAttrs(dataPersistenceFoo, "data_persistence.*", map[string]string{
"name": "snapshot-every-12-hours",
}),
resource.TestCheckTypeSetElemNestedAttrs("data.rediscloud_data_persistence.foo", "data_persistence.*", map[string]string{
resource.TestCheckTypeSetElemNestedAttrs(dataPersistenceFoo, "data_persistence.*", map[string]string{
"name": "snapshot-every-6-hours",
}),
resource.TestCheckTypeSetElemNestedAttrs("data.rediscloud_data_persistence.foo", "data_persistence.*", map[string]string{
resource.TestCheckTypeSetElemNestedAttrs(dataPersistenceFoo, "data_persistence.*", map[string]string{
"name": "snapshot-every-1-hour",
}),
),
Expand Down
2 changes: 1 addition & 1 deletion provider/datasource_rediscloud_database_modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestAccDataSourceRedisCloudDatabaseModules_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccDataSourceRedisCloudDatabaseModules,
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckTypeSetElemNestedAttrs("data.rediscloud_database_modules.foo", "modules.*", map[string]string{
"name": "RedisBloom",
}),
Expand Down
148 changes: 76 additions & 72 deletions provider/datasource_rediscloud_essentials_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,38 @@ import (

func TestAccDataSourceRedisCloudEssentialsPlan_basic(t *testing.T) {

const basicPlan = "data.rediscloud_essentials_plan.basic"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: nil, // Essentials Plans aren't managed by this provider
Steps: []resource.TestStep{
{
Config: testAccDataSourceRedisCloudEssentialsPlan,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "id", "34843"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "name", "30MB"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "size", "30"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "size_measurement_unit", "MB"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "cloud_provider", "AWS"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "region", "us-east-1"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "region_id", "1"),
resource.TestCheckResourceAttrSet("data.rediscloud_essentials_plan.basic", "price"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "price_currency", "USD"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "price_period", "Month"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "maximum_databases", "1"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "maximum_throughput", "100"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "maximum_bandwidth_in_gb", "5"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "availability", "No replication"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "connections", "30"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "cidr_allow_rules", "1"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "support_data_persistence", "false"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "support_instant_and_daily_backups", "false"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "support_replication", "false"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "support_clustering", "false"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "supported_alerts.#", "2"),
resource.TestCheckResourceAttr("data.rediscloud_essentials_plan.basic", "customer_support", "Basic"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(basicPlan, "id", "34843"),
resource.TestCheckResourceAttr(basicPlan, "name", "30MB"),
resource.TestCheckResourceAttr(basicPlan, "size", "30"),
resource.TestCheckResourceAttr(basicPlan, "size_measurement_unit", "MB"),
resource.TestCheckResourceAttr(basicPlan, "cloud_provider", "AWS"),
resource.TestCheckResourceAttr(basicPlan, "region", "us-east-1"),
resource.TestCheckResourceAttr(basicPlan, "region_id", "1"),
resource.TestCheckResourceAttrSet(basicPlan, "price"),
resource.TestCheckResourceAttr(basicPlan, "price_currency", "USD"),
resource.TestCheckResourceAttr(basicPlan, "price_period", "Month"),
resource.TestCheckResourceAttr(basicPlan, "maximum_databases", "1"),
resource.TestCheckResourceAttr(basicPlan, "maximum_throughput", "100"),
resource.TestCheckResourceAttr(basicPlan, "maximum_bandwidth_in_gb", "5"),
resource.TestCheckResourceAttr(basicPlan, "availability", "No replication"),
resource.TestCheckResourceAttr(basicPlan, "connections", "30"),
resource.TestCheckResourceAttr(basicPlan, "cidr_allow_rules", "1"),
resource.TestCheckResourceAttr(basicPlan, "support_data_persistence", "false"),
resource.TestCheckResourceAttr(basicPlan, "support_instant_and_daily_backups", "false"),
resource.TestCheckResourceAttr(basicPlan, "support_replication", "false"),
resource.TestCheckResourceAttr(basicPlan, "support_clustering", "false"),
resource.TestCheckResourceAttr(basicPlan, "supported_alerts.#", "2"),
resource.TestCheckResourceAttr(basicPlan, "customer_support", "Basic"),
),
},
},
Expand All @@ -46,37 +48,38 @@ func TestAccDataSourceRedisCloudEssentialsPlan_basic(t *testing.T) {

func TestAccDataSourceRedisCloudEssentialsPlan_azure(t *testing.T) {

const azureResource = "data.rediscloud_essentials_plan.azure"
const azurePlan = "data.rediscloud_essentials_plan.azure"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: nil, // Essentials Plans aren't managed by this provider
Steps: []resource.TestStep{
{
Config: testAccDataSourceRedisCloudEssentialsPlanAzure,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(azureResource, "id", "35008"),
resource.TestCheckResourceAttr(azureResource, "name", "Single-Zone_Persistence_1GB"),
resource.TestCheckResourceAttr(azureResource, "size", "1"),
resource.TestCheckResourceAttr(azureResource, "size_measurement_unit", "GB"),
resource.TestCheckResourceAttr(azureResource, "cloud_provider", "Azure"),
resource.TestCheckResourceAttr(azureResource, "region", "west-us"),
resource.TestCheckResourceAttr(azureResource, "region_id", "17"),
resource.TestCheckResourceAttrSet(azureResource, "price"),
resource.TestCheckResourceAttr(azureResource, "price_currency", "USD"),
resource.TestCheckResourceAttr(azureResource, "price_period", "Month"),
resource.TestCheckResourceAttr(azureResource, "maximum_databases", "1"),
resource.TestCheckResourceAttr(azureResource, "maximum_throughput", "2000"),
resource.TestCheckResourceAttr(azureResource, "maximum_bandwidth_in_gb", "200"),
resource.TestCheckResourceAttr(azureResource, "availability", "Single-zone"),
resource.TestCheckResourceAttr(azureResource, "connections", "1024"),
resource.TestCheckResourceAttr(azureResource, "cidr_allow_rules", "8"),
resource.TestCheckResourceAttr(azureResource, "support_data_persistence", "true"),
resource.TestCheckResourceAttr(azureResource, "support_instant_and_daily_backups", "true"),
resource.TestCheckResourceAttr(azureResource, "support_replication", "true"),
resource.TestCheckResourceAttr(azureResource, "support_clustering", "false"),
resource.TestCheckResourceAttr(azureResource, "supported_alerts.#", "5"),
resource.TestCheckResourceAttr(azureResource, "customer_support", "Standard"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(azurePlan, "id", "35008"),
resource.TestCheckResourceAttr(azurePlan, "name", "Single-Zone_Persistence_1GB"),
resource.TestCheckResourceAttr(azurePlan, "size", "1"),
resource.TestCheckResourceAttr(azurePlan, "size_measurement_unit", "GB"),
resource.TestCheckResourceAttr(azurePlan, "cloud_provider", "Azure"),
resource.TestCheckResourceAttr(azurePlan, "region", "west-us"),
resource.TestCheckResourceAttr(azurePlan, "region_id", "17"),
resource.TestCheckResourceAttrSet(azurePlan, "price"),
resource.TestCheckResourceAttr(azurePlan, "price_currency", "USD"),
resource.TestCheckResourceAttr(azurePlan, "price_period", "Month"),
resource.TestCheckResourceAttr(azurePlan, "maximum_databases", "1"),
resource.TestCheckResourceAttr(azurePlan, "maximum_throughput", "2000"),
resource.TestCheckResourceAttr(azurePlan, "maximum_bandwidth_in_gb", "200"),
resource.TestCheckResourceAttr(azurePlan, "availability", "Single-zone"),
resource.TestCheckResourceAttr(azurePlan, "connections", "1024"),
resource.TestCheckResourceAttr(azurePlan, "cidr_allow_rules", "8"),
resource.TestCheckResourceAttr(azurePlan, "support_data_persistence", "true"),
resource.TestCheckResourceAttr(azurePlan, "support_instant_and_daily_backups", "true"),
resource.TestCheckResourceAttr(azurePlan, "support_replication", "true"),
resource.TestCheckResourceAttr(azurePlan, "support_clustering", "false"),
resource.TestCheckResourceAttr(azurePlan, "supported_alerts.#", "5"),
resource.TestCheckResourceAttr(azurePlan, "customer_support", "Standard"),
),
},
},
Expand All @@ -85,7 +88,8 @@ func TestAccDataSourceRedisCloudEssentialsPlan_azure(t *testing.T) {

func TestAccDataSourceRedisCloudEssentialsPlan_subscriptionId(t *testing.T) {

const exampleResource = "data.rediscloud_essentials_plan.example"
const examplePlan = "data.rediscloud_essentials_plan.example"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Expand All @@ -94,30 +98,30 @@ func TestAccDataSourceRedisCloudEssentialsPlan_subscriptionId(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccResourceRedisCloudPaidEssentialsSubscriptionDataSource,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(exampleResource, "id", "34858"),
resource.TestCheckResourceAttr(exampleResource, "name", "250MB"),
resource.TestCheckResourceAttrSet(exampleResource, "subscription_id"),
resource.TestCheckResourceAttr(exampleResource, "size", "250"),
resource.TestCheckResourceAttr(exampleResource, "size_measurement_unit", "MB"),
resource.TestCheckResourceAttr(exampleResource, "cloud_provider", "AWS"),
resource.TestCheckResourceAttr(exampleResource, "region", "us-east-1"),
resource.TestCheckResourceAttr(exampleResource, "region_id", "1"),
resource.TestCheckResourceAttrSet(exampleResource, "price"),
resource.TestCheckResourceAttr(exampleResource, "price_currency", "USD"),
resource.TestCheckResourceAttr(exampleResource, "price_period", "Month"),
resource.TestCheckResourceAttr(exampleResource, "maximum_databases", "1"),
resource.TestCheckResourceAttr(exampleResource, "maximum_throughput", "1000"),
resource.TestCheckResourceAttr(exampleResource, "maximum_bandwidth_in_gb", "100"),
resource.TestCheckResourceAttr(exampleResource, "availability", "No replication"),
resource.TestCheckResourceAttr(exampleResource, "connections", "256"),
resource.TestCheckResourceAttr(exampleResource, "cidr_allow_rules", "4"),
resource.TestCheckResourceAttr(exampleResource, "support_data_persistence", "false"),
resource.TestCheckResourceAttr(exampleResource, "support_instant_and_daily_backups", "true"),
resource.TestCheckResourceAttr(exampleResource, "support_replication", "false"),
resource.TestCheckResourceAttr(exampleResource, "support_clustering", "false"),
resource.TestCheckResourceAttr(exampleResource, "supported_alerts.#", "5"),
resource.TestCheckResourceAttr(exampleResource, "customer_support", "Standard"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(examplePlan, "id", "34858"),
resource.TestCheckResourceAttr(examplePlan, "name", "250MB"),
resource.TestCheckResourceAttrSet(examplePlan, "subscription_id"),
resource.TestCheckResourceAttr(examplePlan, "size", "250"),
resource.TestCheckResourceAttr(examplePlan, "size_measurement_unit", "MB"),
resource.TestCheckResourceAttr(examplePlan, "cloud_provider", "AWS"),
resource.TestCheckResourceAttr(examplePlan, "region", "us-east-1"),
resource.TestCheckResourceAttr(examplePlan, "region_id", "1"),
resource.TestCheckResourceAttrSet(examplePlan, "price"),
resource.TestCheckResourceAttr(examplePlan, "price_currency", "USD"),
resource.TestCheckResourceAttr(examplePlan, "price_period", "Month"),
resource.TestCheckResourceAttr(examplePlan, "maximum_databases", "1"),
resource.TestCheckResourceAttr(examplePlan, "maximum_throughput", "1000"),
resource.TestCheckResourceAttr(examplePlan, "maximum_bandwidth_in_gb", "100"),
resource.TestCheckResourceAttr(examplePlan, "availability", "No replication"),
resource.TestCheckResourceAttr(examplePlan, "connections", "256"),
resource.TestCheckResourceAttr(examplePlan, "cidr_allow_rules", "4"),
resource.TestCheckResourceAttr(examplePlan, "support_data_persistence", "false"),
resource.TestCheckResourceAttr(examplePlan, "support_instant_and_daily_backups", "true"),
resource.TestCheckResourceAttr(examplePlan, "support_replication", "false"),
resource.TestCheckResourceAttr(examplePlan, "support_clustering", "false"),
resource.TestCheckResourceAttr(examplePlan, "supported_alerts.#", "5"),
resource.TestCheckResourceAttr(examplePlan, "customer_support", "Standard"),
),
},
},
Expand Down
2 changes: 1 addition & 1 deletion provider/datasource_rediscloud_payment_method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAccDataSourceRedisCloudPaymentMethod_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccDataSourceRedisCloudPaymentMethod,
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr(
"data.rediscloud_payment_method.foo", "id", regexp.MustCompile("^\\d*$")),
resource.TestMatchResourceAttr(
Expand Down
6 changes: 3 additions & 3 deletions provider/datasource_rediscloud_pro_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func TestAccDataSourceRedisCloudProDatabase_basic(t *testing.T) {
password := acctest.RandString(20)
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")

dataSourceById := "data.rediscloud_database.example-by-id"
dataSourceByName := "data.rediscloud_database.example-by-name"
const dataSourceById = "data.rediscloud_database.example-by-id"
const dataSourceByName = "data.rediscloud_database.example-by-name"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccAwsPreExistingCloudAccountPreCheck(t) },
Expand All @@ -24,7 +24,7 @@ func TestAccDataSourceRedisCloudProDatabase_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccDatasourceRedisCloudProDatabase, testCloudAccountName, name, password),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceById, "name", "tf-database"),
resource.TestCheckResourceAttr(dataSourceById, "protocol", "redis"),
resource.TestCheckResourceAttr(dataSourceById, "region", "eu-west-1"),
Expand Down
8 changes: 4 additions & 4 deletions provider/datasource_rediscloud_pro_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
func TestAccDataSourceRedisCloudProSubscription_basic(t *testing.T) {
name := acctest.RandomWithPrefix("tf-test")

resourceName := "rediscloud_subscription.example"
dataSourceName := "data.rediscloud_subscription.example"
const resourceName = "rediscloud_subscription.example"
const dataSourceName = "data.rediscloud_subscription.example"
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -24,13 +24,13 @@ func TestAccDataSourceRedisCloudProSubscription_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccDatasourceRedisCloudProSubscription, testCloudAccountName, name),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr(resourceName, "name", regexp.MustCompile(name)),
),
},
{
Config: fmt.Sprintf(testAccDatasourceRedisCloudProSubscriptionDataSource, name) + fmt.Sprintf(testAccDatasourceRedisCloudProSubscription, testCloudAccountName, name),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr(dataSourceName, "name", regexp.MustCompile(name)),
resource.TestCheckResourceAttr(dataSourceName, "payment_method", "credit-card"),
resource.TestCheckResourceAttrSet(dataSourceName, "payment_method_id"),
Expand Down
Loading

0 comments on commit ae9215b

Please sign in to comment.