Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sinbai committed Jan 14, 2025
1 parent bd08c7c commit 74f64b1
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions internal/services/mongocluster/mongo_cluster_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,7 @@ func TestAccMongoCluster_previewFeature(t *testing.T) {
},
data.ImportStep("administrator_password", "create_mode"),
{
Config: r.geoReplica(data, r.previewFeature(data)),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_password", "create_mode", "source_location"),
})
}

func TestAccMongoCluster_geoReplica(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mongo_cluster", "test")
r := MongoClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.update(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_password", "create_mode"),
{
Config: r.geoReplica(data, r.update(data)),
Config: r.geoReplica(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand Down Expand Up @@ -191,7 +169,7 @@ resource "azurerm_mongo_cluster" "test" {
shard_count = "1"
compute_tier = "M30"
high_availability_mode = "ZoneRedundantPreferred"
public_network_access = "Enabled"
public_network_access = "Disabled"
storage_size_in_gb = "64"
version = "7.0"
Expand All @@ -202,6 +180,25 @@ resource "azurerm_mongo_cluster" "test" {
`, r.template(data, data.Locations.Ternary), data.RandomInteger)
}

func (r MongoClusterResource) source(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_mongo_cluster" "test" {
name = "acctest-mc%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
administrator_username = "adminTerraform"
administrator_password = "QAZwsx123update"
high_availability_mode = "ZoneRedundantPreferred"
shard_count = "1"
compute_tier = "M30"
storage_size_in_gb = "64"
version = "7.0"
}
`, r.template(data, data.Locations.Ternary), data.RandomInteger)
}

func (r MongoClusterResource) requiresImport(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down Expand Up @@ -241,7 +238,7 @@ resource "azurerm_mongo_cluster" "test" {
`, r.template(data, data.Locations.Primary), data.RandomInteger)
}

func (r MongoClusterResource) geoReplica(data acceptance.TestData, source string) string {
func (r MongoClusterResource) geoReplica(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand All @@ -257,7 +254,7 @@ resource "azurerm_mongo_cluster" "geo_replica" {
ignore_changes = ["administrator_username", "high_availability_mode", "preview_features", "shard_count", "storage_size_in_gb", "compute_tier", "version"]
}
}
`, source, data.RandomInteger, data.Locations.Secondary)
`, r.source(data), data.RandomInteger, data.Locations.Secondary)
}

func (r MongoClusterResource) template(data acceptance.TestData, location string) string {
Expand Down

0 comments on commit 74f64b1

Please sign in to comment.