Skip to content

Commit

Permalink
chore: Reuses project in tests for advanced_cluster resource (#2042)
Browse files Browse the repository at this point in the history
* configSingleProvider and configMultiCloud

* TestMigAdvancedCluster_partialAdvancedConf

* TestAccClusterAdvancedCluster_basicTenant

* TestAccClusterAdvancedCluster_multicloudSharded

* TestAccClusterAdvancedCluster_withTags

* rest of tests with acc.ProjectIDExecution

* change regions

* multi-sharded in own project

* multi-region clusters in their own project

* configWithTags in its own project

* shared clusters in US_EAST_1
  • Loading branch information
lantoli authored Mar 20, 2024
1 parent 1b8dd6e commit febe2be
Show file tree
Hide file tree
Showing 3 changed files with 418 additions and 476 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import (

func TestMigAdvancedCluster_singleAWSProvider(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
projectID = mig.ProjectIDGlobal(t)
clusterName = acc.RandomClusterName()
config = configSingleProvider(orgID, projectName, clusterName)
config = configSingleProvider(projectID, clusterName)
)

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -43,7 +42,7 @@ func TestMigAdvancedCluster_singleAWSProvider(t *testing.T) {
func TestMigAdvancedCluster_multiCloud(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
projectName = acc.RandomProjectName() // No ProjectIDExecution to avoid cross-region limits because multi-region
clusterName = acc.RandomClusterName()
config = configMultiCloud(orgID, projectName, clusterName)
)
Expand Down Expand Up @@ -71,33 +70,37 @@ func TestMigAdvancedCluster_multiCloud(t *testing.T) {

func TestMigAdvancedCluster_partialAdvancedConf(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
rName = acc.RandomClusterName()
processArgs = `advanced_configuration {
fail_index_key_too_long = false
javascript_enabled = true
minimum_enabled_tls_protocol = "TLS1_1"
no_table_scan = false
}`
biConnector = `bi_connector_config {
enabled = true
}`
processArgsUpdated = `advanced_configuration {
fail_index_key_too_long = false
javascript_enabled = true
minimum_enabled_tls_protocol = "TLS1_1"
no_table_scan = false
default_read_concern = "available"
sample_size_bi_connector = 110
sample_refresh_interval_bi_connector = 310
}`
biConnectorUpdated = `bi_connector_config {
enabled = false
read_preference = "secondary"
}`
config = configPartialAdvancedConfig(orgID, projectName, rName, processArgs, biConnector)
configUpdated = configPartialAdvancedConfig(orgID, projectName, rName, processArgsUpdated, biConnectorUpdated)
projectID = mig.ProjectIDGlobal(t)
clusterName = acc.RandomClusterName()
extraArgs = `
advanced_configuration {
fail_index_key_too_long = false
javascript_enabled = true
minimum_enabled_tls_protocol = "TLS1_1"
no_table_scan = false
}
bi_connector_config {
enabled = true
}`

extraArgsUpdated = `
advanced_configuration {
fail_index_key_too_long = false
javascript_enabled = true
minimum_enabled_tls_protocol = "TLS1_1"
no_table_scan = false
default_read_concern = "available"
sample_size_bi_connector = 110
sample_refresh_interval_bi_connector = 310
}
bi_connector_config {
enabled = false
read_preference = "secondary"
}`
config = configPartialAdvancedConfig(projectID, clusterName, extraArgs)
configUpdated = configPartialAdvancedConfig(projectID, clusterName, extraArgsUpdated)
)

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -136,38 +139,29 @@ func TestMigAdvancedCluster_partialAdvancedConf(t *testing.T) {
})
}

func configPartialAdvancedConfig(orgID, projectName, name, processArgs, biConnector string) string {
func configPartialAdvancedConfig(projectID, clusterName, extraArgs string) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "cluster_project" {
name = %[2]q
org_id = %[1]q
}
resource "mongodbatlas_advanced_cluster" "test" {
project_id = mongodbatlas_project.cluster_project.id
name = %[3]q
cluster_type = "REPLICASET"
%[5]s
replication_specs {
region_configs {
electable_specs {
instance_size = "M10"
node_count = 3
}
analytics_specs {
instance_size = "M10"
node_count = 1
}
provider_name = "AWS"
priority = 7
region_name = "EU_WEST_1"
}
}
%[4]s
}
resource "mongodbatlas_advanced_cluster" "test" {
project_id = %[1]q
name = %[2]q
cluster_type = "REPLICASET"
`, orgID, projectName, name, processArgs, biConnector)
replication_specs {
region_configs {
electable_specs {
instance_size = "M10"
node_count = 3
}
analytics_specs {
instance_size = "M10"
node_count = 1
}
provider_name = "AWS"
priority = 7
region_name = "US_WEST_2"
}
}
%[3]s
}
`, projectID, clusterName, extraArgs)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestMigAdvancedCluster_empty_advancedConfig(t *testing.T) {
},
},
"provider_name": "AWS",
"region_name": "US_EAST_1",
"region_name": "US_WEST_2",
"priority": 7,
},
},
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestMigAdvancedCluster_v0StateUpgrade_ReplicationSpecs(t *testing.T) {
map[string]any{
"priority": 7,
"provider_name": "AWS",
"region_name": "US_EAST_1",
"region_name": "US_WEST_2",
"electable_specs": []any{
map[string]any{
"instance_size": "M30",
Expand Down
Loading

0 comments on commit febe2be

Please sign in to comment.