Skip to content

Commit

Permalink
use new projects in tests (#2643)
Browse files Browse the repository at this point in the history
  • Loading branch information
lantoli authored Sep 27, 2024
1 parent 7373f62 commit 988a1d7
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions internal/service/advancedcluster/resource_advanced_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,8 @@ func TestAccAdvancedCluster_replicaSetScalingStrategyOldSchema(t *testing.T) {
// TestAccClusterAdvancedCluster_priorityOldSchema will be able to be simplied or deleted in CLOUDP-275825
func TestAccClusterAdvancedCluster_priorityOldSchema(t *testing.T) {
var (
projectID = acc.ProjectIDExecution(t)
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName() // No ProjectIDExecution to avoid cross-region limits because multi-region
clusterName = acc.RandomClusterName()
)

Expand All @@ -817,15 +818,15 @@ func TestAccClusterAdvancedCluster_priorityOldSchema(t *testing.T) {
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Config: configPriority(projectID, clusterName, true, true),
Config: configPriority(orgID, projectName, clusterName, true, true),
ExpectError: regexp.MustCompile("priority values in region_configs must be in descending order"),
},
{
Config: configPriority(projectID, clusterName, true, false),
Config: configPriority(orgID, projectName, clusterName, true, false),
Check: resource.TestCheckResourceAttr(resourceName, "replication_specs.0.region_configs.#", "2"),
},
{
Config: configPriority(projectID, clusterName, true, true),
Config: configPriority(orgID, projectName, clusterName, true, true),
ExpectError: regexp.MustCompile("priority values in region_configs must be in descending order"),
},
},
Expand All @@ -835,7 +836,8 @@ func TestAccClusterAdvancedCluster_priorityOldSchema(t *testing.T) {
// TestAccClusterAdvancedCluster_priorityNewSchema will be able to be simplied or deleted in CLOUDP-275825
func TestAccClusterAdvancedCluster_priorityNewSchema(t *testing.T) {
var (
projectID = acc.ProjectIDExecution(t)
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName() // No ProjectIDExecution to avoid cross-region limits because multi-region
clusterName = acc.RandomClusterName()
)

Expand All @@ -845,15 +847,15 @@ func TestAccClusterAdvancedCluster_priorityNewSchema(t *testing.T) {
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Config: configPriority(projectID, clusterName, false, true),
Config: configPriority(orgID, projectName, clusterName, false, true),
ExpectError: regexp.MustCompile("priority values in region_configs must be in descending order"),
},
{
Config: configPriority(projectID, clusterName, false, false),
Config: configPriority(orgID, projectName, clusterName, false, false),
Check: resource.TestCheckResourceAttr(resourceName, "replication_specs.0.region_configs.#", "2"),
},
{
Config: configPriority(projectID, clusterName, false, true),
Config: configPriority(orgID, projectName, clusterName, false, true),
ExpectError: regexp.MustCompile("priority values in region_configs must be in descending order"),
},
},
Expand Down Expand Up @@ -2181,7 +2183,7 @@ func checkReplicaSetScalingStrategy(replicaSetScalingStrategy string) resource.T
)
}

func configPriority(projectID, name string, oldSchema, swapPriorities bool) string {
func configPriority(orgID, projectName, clusterName string, oldSchema, swapPriorities bool) string {
const (
config7 = `
region_configs {
Expand Down Expand Up @@ -2216,16 +2218,21 @@ func configPriority(projectID, name string, oldSchema, swapPriorities bool) stri
}

return fmt.Sprintf(`
resource "mongodbatlas_project" "test" {
org_id = %[1]q
name = %[2]q
}
resource "mongodbatlas_advanced_cluster" "test" {
project_id = %[1]q
name = %[2]q
cluster_type = %[3]q
project_id = mongodbatlas_project.test.id
name = %[3]q
cluster_type = %[4]q
backup_enabled = false
replication_specs {
%[4]s
%[5]s
%[6]s
}
}
`, projectID, name, strType, strNumShards, strConfigs)
`, orgID, projectName, clusterName, strType, strNumShards, strConfigs)
}

0 comments on commit 988a1d7

Please sign in to comment.