Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Reuses project in tests for advanced_cluster resource #2042

Merged
merged 11 commits into from
Mar 20, 2024
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",
EspenAlbert marked this conversation as resolved.
Show resolved Hide resolved
"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