Skip to content

Commit

Permalink
chore: Adds a TestAccMockableAdvancedCluster_tenantUpgradeExplicitZon…
Browse files Browse the repository at this point in the history
…eName to capture API behavior
  • Loading branch information
EspenAlbert committed Jan 10, 2025
1 parent 5d05ad3 commit 5902807
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions internal/service/advancedcluster/resource_advanced_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ func TestAccMockableAdvancedCluster_basicTenant(t *testing.T) {
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Config: configTenant(t, true, projectID, clusterName),
Config: configTenant(t, true, projectID, clusterName, ""),
Check: checkTenant(true, projectID, clusterName),
},
{
Config: configTenant(t, true, projectID, clusterNameUpdated),
Config: configTenant(t, true, projectID, clusterNameUpdated, ""),
Check: checkTenant(true, projectID, clusterNameUpdated),
},
acc.TestStepImportCluster(resourceName),
Expand All @@ -160,11 +160,32 @@ func TestAccMockableAdvancedCluster_tenantUpgrade(t *testing.T) {
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Config: acc.ConvertAdvancedClusterToSchemaV2(t, true, configTenant(t, true, projectID, clusterName)),
Config: acc.ConvertAdvancedClusterToSchemaV2(t, true, configTenant(t, true, projectID, clusterName, "")),
Check: checkTenant(true, projectID, clusterName),
},
{
Config: acc.ConvertAdvancedClusterToSchemaV2(t, true, configTenantUpgraded(projectID, clusterName)),
Config: acc.ConvertAdvancedClusterToSchemaV2(t, true, configTenantUpgraded(projectID, clusterName, "")),
Check: checksTenantUpgraded(projectID, clusterName),
},
},
})
}
func TestAccMockableAdvancedCluster_tenantUpgradeExplicitZoneName(t *testing.T) {
var (
projectID = acc.ProjectIDExecution(t)
clusterName = acc.RandomClusterName()
)
unit.CaptureOrMockTestCaseAndRun(t, mockConfig, &resource.TestCase{
PreCheck: acc.PreCheckBasicSleep(t, nil, projectID, clusterName),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Config: acc.ConvertAdvancedClusterToSchemaV2(t, true, configTenant(t, true, projectID, clusterName, "explicit-name")),
Check: checkTenant(true, projectID, clusterName),
},
{
Config: acc.ConvertAdvancedClusterToSchemaV2(t, true, configTenantUpgraded(projectID, clusterName, "explicit-name")),
Check: checksTenantUpgraded(projectID, clusterName),
},
},
Expand Down Expand Up @@ -1423,8 +1444,12 @@ func checkAggr(isAcc bool, attrsSet []string, attrsMap map[string]string, extra
return resource.ComposeAggregateTestCheckFunc(checks...)
}

func configTenant(t *testing.T, isAcc bool, projectID, name string) string {
func configTenant(t *testing.T, isAcc bool, projectID, name, zoneName string) string {
t.Helper()
zoneNameLine := ""
if zoneName != "" {
zoneNameLine = fmt.Sprintf("zone_name = %q", zoneName)
}
return acc.ConvertAdvancedClusterToSchemaV2(t, isAcc, fmt.Sprintf(`
resource "mongodbatlas_advanced_cluster" "test" {
project_id = %[1]q
Expand All @@ -1441,9 +1466,10 @@ func configTenant(t *testing.T, isAcc bool, projectID, name string) string {
region_name = "US_EAST_1"
priority = 7
}
%[3]s
}
}
`, projectID, name)) + dataSourcesTFNewSchema
`, projectID, name, zoneNameLine)) + dataSourcesTFNewSchema
}

func checkTenant(isAcc bool, projectID, name string) resource.TestCheckFunc {
Expand All @@ -1459,7 +1485,11 @@ func checkTenant(isAcc bool, projectID, name string) resource.TestCheckFunc {
pluralChecks...)
}

func configTenantUpgraded(projectID, name string) string {
func configTenantUpgraded(projectID, name, zoneName string) string {
zoneNameLine := ""
if zoneName != "" {
zoneNameLine = fmt.Sprintf("zone_name = %q", zoneName)
}
return fmt.Sprintf(`
resource "mongodbatlas_advanced_cluster" "test" {
project_id = %[1]q
Expand All @@ -1476,9 +1506,10 @@ func configTenantUpgraded(projectID, name string) string {
instance_size = "M10"
}
}
%[3]s
}
}
`, projectID, name) + dataSourcesTFNewSchema
`, projectID, name, zoneNameLine) + dataSourcesTFNewSchema
}

func checksTenantUpgraded(projectID, name string) resource.TestCheckFunc {
Expand Down

0 comments on commit 5902807

Please sign in to comment.