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

test: Refactors resource tests to use GetClusterInfo ldap_configuration #2411

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@ 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
EspenAlbert marked this conversation as resolved.
Show resolved Hide resolved
clusterName = clusterInfo.ClusterName
clusterTerraformStr = clusterInfo.ClusterTerraformStr
)

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.PreCheckLDAPCert(t) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Steps: []resource.TestStep{
{
Config: configWithVerify(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"),
Expand Down Expand Up @@ -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, clusterResourceName, 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
Expand All @@ -176,7 +176,7 @@ func configWithVerify(projectID, clusterName, hostname, username, password, caCe
%[8]s
EOF
authz_query_template = "{USER}?memberOf?base"
depends_on = [mongodbatlas_cluster.test]
depends_on = [%[10]s]
}

resource "mongodbatlas_ldap_configuration" "test" {
Expand All @@ -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, clusterResourceName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EspenAlbert I think we are not using clusterName here, because I don't see %[2]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice spot @marcosuma , changed in 2f2ef65

}