From ea18b285d653ef0b531c0f89b781235d8ad9a683 Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Fri, 12 Jul 2024 07:09:52 +0100 Subject: [PATCH 1/3] test: Refactors resource tests to use GetClusterInfo ldap_configuration --- .../resource_ldap_configuration_test.go | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/service/ldapconfiguration/resource_ldap_configuration_test.go b/internal/service/ldapconfiguration/resource_ldap_configuration_test.go index 7db034a5dd..ab8910e665 100644 --- a/internal/service/ldapconfiguration/resource_ldap_configuration_test.go +++ b/internal/service/ldapconfiguration/resource_ldap_configuration_test.go @@ -30,8 +30,15 @@ func TestAccLDAPConfiguration_withVerify_CACertificateComplete(t *testing.T) { password = os.Getenv("MONGODB_ATLAS_LDAP_PASSWORD") port = os.Getenv("MONGODB_ATLAS_LDAP_PORT") caCertificate = os.Getenv("MONGODB_ATLAS_LDAP_CA_CERTIFICATE") - projectID = acc.ProjectIDExecution(t) - clusterName = acc.RandomClusterName() + clusterInfo = acc.GetClusterInfo(t, &acc.ClusterRequest{ + CloudBackup: true, + ReplicationSpecs: []acc.ReplicationSpecRequest{ + {Region: "US_EAST_2"}, + }, + }) + projectID = clusterInfo.ProjectID + clusterName = clusterInfo.ClusterName + clusterTerraformStr = clusterInfo.ClusterTerraformStr ) resource.Test(t, resource.TestCase{ @@ -39,7 +46,7 @@ func TestAccLDAPConfiguration_withVerify_CACertificateComplete(t *testing.T) { ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, Steps: []resource.TestStep{ { - Config: configWithVerify(projectID, clusterName, hostname, username, password, caCertificate, cast.ToInt(port), true), + Config: configWithVerify(clusterTerraformStr, projectID, clusterName, hostname, username, password, caCertificate, cast.ToInt(port), true), Check: resource.ComposeAggregateTestCheckFunc( checkExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -155,16 +162,9 @@ func configBasic(projectID, hostname, username, password string, authEnabled boo `, projectID, hostname, username, password, authEnabled, port) } -func configWithVerify(projectID, clusterName, hostname, username, password, caCertificate string, port int, authEnabled bool) string { +func configWithVerify(clusterTerraformStr, projectID, clusterName, hostname, username, password, caCertificate string, port int, authEnabled bool) string { return fmt.Sprintf(` - resource "mongodbatlas_cluster" "test" { - project_id = %[1]q - name = %[2]q - provider_name = "AWS" - provider_region_name = "US_EAST_2" - provider_instance_size_name = "M10" - cloud_backup = true //enable cloud provider snapshots - } +%[9]s resource "mongodbatlas_ldap_verify" "test" { project_id = %[1]q @@ -196,5 +196,5 @@ func configWithVerify(projectID, clusterName, hostname, username, password, caCe ldap_query = "DC=example,DC=com??sub?(userPrincipalName={0})" } depends_on = [mongodbatlas_ldap_verify.test] - }`, projectID, clusterName, hostname, username, password, port, authEnabled, caCertificate) + }`, projectID, clusterName, hostname, username, password, port, authEnabled, caCertificate, clusterTerraformStr) } From d0ef2ad2ea4efb0d2ef6e7b233f087278edc3497 Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Fri, 12 Jul 2024 08:12:33 +0100 Subject: [PATCH 2/3] test: Fix depends_on clause --- .../ldapconfiguration/resource_ldap_configuration_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/service/ldapconfiguration/resource_ldap_configuration_test.go b/internal/service/ldapconfiguration/resource_ldap_configuration_test.go index ab8910e665..506764e83b 100644 --- a/internal/service/ldapconfiguration/resource_ldap_configuration_test.go +++ b/internal/service/ldapconfiguration/resource_ldap_configuration_test.go @@ -46,7 +46,7 @@ func TestAccLDAPConfiguration_withVerify_CACertificateComplete(t *testing.T) { ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, Steps: []resource.TestStep{ { - Config: configWithVerify(clusterTerraformStr, projectID, clusterName, hostname, username, password, caCertificate, cast.ToInt(port), true), + Config: configWithVerify(clusterTerraformStr, clusterInfo.ClusterResourceName, projectID, clusterName, hostname, username, password, caCertificate, cast.ToInt(port), true), Check: resource.ComposeAggregateTestCheckFunc( checkExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -162,7 +162,7 @@ func configBasic(projectID, hostname, username, password string, authEnabled boo `, projectID, hostname, username, password, authEnabled, port) } -func configWithVerify(clusterTerraformStr, projectID, clusterName, hostname, username, password, caCertificate string, port int, authEnabled bool) string { +func configWithVerify(clusterTerraformStr, clusterResourceName, projectID, clusterName, hostname, username, password, caCertificate string, port int, authEnabled bool) string { return fmt.Sprintf(` %[9]s @@ -176,7 +176,7 @@ func configWithVerify(clusterTerraformStr, projectID, clusterName, hostname, use %[8]s EOF authz_query_template = "{USER}?memberOf?base" - depends_on = [mongodbatlas_cluster.test] + depends_on = [%[10]s] } resource "mongodbatlas_ldap_configuration" "test" { @@ -196,5 +196,5 @@ func configWithVerify(clusterTerraformStr, projectID, clusterName, hostname, use ldap_query = "DC=example,DC=com??sub?(userPrincipalName={0})" } depends_on = [mongodbatlas_ldap_verify.test] - }`, projectID, clusterName, hostname, username, password, port, authEnabled, caCertificate, clusterTerraformStr) + }`, projectID, clusterName, hostname, username, password, port, authEnabled, caCertificate, clusterTerraformStr, clusterResourceName) } From 2f2ef651e254f076299e228523cfd3ad91967b8b Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Mon, 15 Jul 2024 07:45:05 +0100 Subject: [PATCH 3/3] test: remove unused clusterName and align fields --- .../resource_ldap_configuration_test.go | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/internal/service/ldapconfiguration/resource_ldap_configuration_test.go b/internal/service/ldapconfiguration/resource_ldap_configuration_test.go index 506764e83b..f9eeba0eac 100644 --- a/internal/service/ldapconfiguration/resource_ldap_configuration_test.go +++ b/internal/service/ldapconfiguration/resource_ldap_configuration_test.go @@ -37,7 +37,6 @@ func TestAccLDAPConfiguration_withVerify_CACertificateComplete(t *testing.T) { }, }) projectID = clusterInfo.ProjectID - clusterName = clusterInfo.ClusterName clusterTerraformStr = clusterInfo.ClusterTerraformStr ) @@ -46,7 +45,7 @@ func TestAccLDAPConfiguration_withVerify_CACertificateComplete(t *testing.T) { ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, Steps: []resource.TestStep{ { - Config: configWithVerify(clusterTerraformStr, clusterInfo.ClusterResourceName, projectID, clusterName, hostname, username, password, caCertificate, cast.ToInt(port), true), + Config: configWithVerify(clusterTerraformStr, clusterInfo.ClusterResourceName, projectID, hostname, username, password, caCertificate, cast.ToInt(port), true), Check: resource.ComposeAggregateTestCheckFunc( checkExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -162,33 +161,33 @@ func configBasic(projectID, hostname, username, password string, authEnabled boo `, projectID, hostname, username, password, authEnabled, port) } -func configWithVerify(clusterTerraformStr, clusterResourceName, projectID, clusterName, hostname, username, password, caCertificate string, port int, authEnabled bool) string { +func configWithVerify(clusterTerraformStr, clusterResourceName, projectID, hostname, username, password, caCertificate string, port int, authEnabled bool) string { return fmt.Sprintf(` -%[9]s +%[8]s resource "mongodbatlas_ldap_verify" "test" { - project_id = %[1]q - hostname = %[3]q - bind_username = %[4]q - bind_password = %[5]q - port = %[6]d + project_id = %[1]q + hostname = %[2]q + bind_username = %[3]q + bind_password = %[4]q + port = %[5]d ca_certificate = <<-EOF -%[8]s +%[7]s EOF authz_query_template = "{USER}?memberOf?base" - depends_on = [%[10]s] + depends_on = [%[9]s] } resource "mongodbatlas_ldap_configuration" "test" { - project_id = %[1]q - authorization_enabled = false - hostname = %[3]q - bind_username = %[4]q - bind_password = %[5]q - port = %[6]d - authentication_enabled = %[7]t + project_id = %[1]q + authorization_enabled = false + hostname = %[2]q + bind_username = %[3]q + bind_password = %[4]q + port = %[5]d + authentication_enabled = %[6]t ca_certificate = <<-EOF -%[8]s +%[7]s EOF authz_query_template = "{USER}?memberOf?base" user_to_dn_mapping{ @@ -196,5 +195,5 @@ func configWithVerify(clusterTerraformStr, clusterResourceName, projectID, clust ldap_query = "DC=example,DC=com??sub?(userPrincipalName={0})" } depends_on = [mongodbatlas_ldap_verify.test] - }`, projectID, clusterName, hostname, username, password, port, authEnabled, caCertificate, clusterTerraformStr, clusterResourceName) + }`, projectID, hostname, username, password, port, authEnabled, caCertificate, clusterTerraformStr, clusterResourceName) }