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: Fixes cluster tests #2195

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
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
104 changes: 4 additions & 100 deletions internal/service/cluster/resource_cluster_migration_test.go
Original file line number Diff line number Diff line change
@@ -1,111 +1,15 @@
package cluster_test

import (
"fmt"
"testing"

matlas "go.mongodb.org/atlas/mongodbatlas"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"

"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
)

func TestMigClusterRSCluster_withDefaultBiConnectorAndAdvancedConfiguration_backwardCompatibility(t *testing.T) {
var (
projectID = acc.ProjectIDExecution(t)
clusterName = acc.RandomClusterName()
cfg = configAWS(projectID, clusterName, true, true)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: cfg,
Check: resource.ComposeTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "name", clusterName),
),
},
mig.TestStepCheckEmptyPlan(cfg),
},
})
}

func TestMigClusterRSCluster_basic_PartialAdvancedConf_backwardCompatibility(t *testing.T) {
var (
projectID = acc.ProjectIDExecution(t)
clusterName = acc.RandomClusterName()
cfgPartial = configAdvancedConfPartial(projectID, clusterName, "false", &matlas.ProcessArgs{
MinimumEnabledTLSProtocol: "TLS1_2",
})
cfgPartialUpdated = configAdvancedConfPartialUpdated(projectID, clusterName, "false", &matlas.ProcessArgs{
MinimumEnabledTLSProtocol: "TLS1_2",
SampleSizeBIConnector: conversion.Pointer[int64](110),
})
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: cfgPartial,
Check: resource.ComposeTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.minimum_enabled_tls_protocol", "TLS1_2"),
),
},
mig.TestStepCheckEmptyPlan(cfgPartial),
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: cfgPartialUpdated,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.minimum_enabled_tls_protocol", "TLS1_2"),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.sample_size_bi_connector", "110"),
),
},
},
})
func TestMigCluster_basicAWS_simple(t *testing.T) {
mig.CreateAndRunTest(t, basicTestCase(t))
}

func configAdvancedConfPartialUpdated(projectID, name, autoscalingEnabled string, p *matlas.ProcessArgs) string {
return fmt.Sprintf(`
resource "mongodbatlas_cluster" "test" {
project_id = %[1]q
name = %[2]q
disk_size_gb = 10

cluster_type = "REPLICASET"
replication_specs {
num_shards = 1
regions_config {
region_name = "US_WEST_2"
electable_nodes = 3
priority = 7
read_only_nodes = 0
}
}

backup_enabled = false
auto_scaling_disk_gb_enabled = %[3]s

// Provider Settings "block"
provider_name = "AWS"
provider_instance_size_name = "M10"
provider_region_name = "US_WEST_2"

advanced_configuration {
minimum_enabled_tls_protocol = %[4]q
sample_size_bi_connector = %[5]d
}
}
`, projectID, name, autoscalingEnabled, p.MinimumEnabledTLSProtocol, *p.SampleSizeBIConnector)
func TestMigCluster_partial_advancedConf(t *testing.T) {
mig.CreateAndRunTest(t, partialAdvancedConfTestCase(t))
}
Loading
Loading