Skip to content

Commit

Permalink
update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sinbai committed Nov 7, 2024
1 parent b8ce5d1 commit 2ef6ef8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .teamcity/components/settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ var serviceTestConfigurationOverrides = mapOf(
// MobileNetwork is only available in certain locations
"mobilenetwork" to testConfiguration(locationOverride = LocationConfiguration("eastus", "westeurope", "centraluseuap", false)),

// Mongocluster free tier is currently only available in southindia
"mongocluster" to testConfiguration(locationOverride = LocationConfiguration("westeurope", "eastus2", "southindia", false)),

// MSSQl uses app service which is only available in certain locations
"mssql" to testConfiguration(locationOverride = LocationConfiguration("westeurope", "francecentral", "eastus2", false)),

Expand Down
56 changes: 32 additions & 24 deletions internal/services/mongocluster/mongo_cluster_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ import (

type MongoClusterResource struct{}

func TestAccMongoCluster_basic(t *testing.T) {
func TestAccMongoClusterFreeTier(t *testing.T) {
acceptance.RunTestsInSequence(t, map[string]map[string]func(t *testing.T){
"freeTier": { // Run tests inSequence since each subscription is limited to one free tier cluster per region and free tier is currently only available in South India.
"basic": testAccMongoCluster_basic,
"update": testAccMongoCluster_update,
"import": testAccMongoCluster_requiresImport,
},
})
}
func testAccMongoCluster_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mongo_cluster", "test")
r := MongoClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -33,11 +41,11 @@ func TestAccMongoCluster_basic(t *testing.T) {
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -55,40 +63,40 @@ func TestAccMongoCluster_update(t *testing.T) {
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.previewFeature(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_password", "create_mode"),
{
Config: r.geoReplica(data),
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_password", "create_mode", "source_location"),
data.RequiresImportErrorStep(r.requiresImport),
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Config: r.previewFeature(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.RequiresImportErrorStep(r.requiresImport),
data.ImportStep("administrator_password", "create_mode"),
{
Config: r.geoReplica(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_password", "create_mode", "source_location"),
})
}

Expand Down Expand Up @@ -122,7 +130,7 @@ resource "azurerm_mongo_cluster" "test" {
storage_size_in_gb = "32"
version = "6.0"
}
`, r.template(data), data.RandomInteger)
`, r.template(data, data.Locations.Ternary), data.RandomInteger)
}

func (r MongoClusterResource) update(data acceptance.TestData) string {
Expand All @@ -146,7 +154,7 @@ resource "azurerm_mongo_cluster" "test" {
environment = "test"
}
}
`, r.template(data), data.RandomInteger)
`, r.template(data, data.Locations.Ternary), data.RandomInteger)
}

func (r MongoClusterResource) requiresImport(data acceptance.TestData) string {
Expand Down Expand Up @@ -185,7 +193,7 @@ resource "azurerm_mongo_cluster" "test" {
preview_features = ["GeoReplicas"]
version = "7.0"
}
`, r.template(data), data.RandomInteger)
`, r.template(data, data.Locations.Primary), data.RandomInteger)
}

func (r MongoClusterResource) geoReplica(data acceptance.TestData) string {
Expand All @@ -207,7 +215,7 @@ resource "azurerm_mongo_cluster" "geo_replica" {
`, r.previewFeature(data), data.RandomInteger, data.Locations.Secondary)
}

func (r MongoClusterResource) template(data acceptance.TestData) string {
func (r MongoClusterResource) template(data acceptance.TestData, location string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand All @@ -217,5 +225,5 @@ resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
`, data.RandomInteger, data.Locations.Primary)
`, data.RandomInteger, location)
}

0 comments on commit 2ef6ef8

Please sign in to comment.