Skip to content

Commit

Permalink
add assertion in data source for data process region
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinBettati committed Apr 30, 2024
1 parent 8dfd6f4 commit 7841c1d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,6 @@ import (
"go.mongodb.org/atlas-sdk/v20231115012/admin"
)

func TestAccFederatedDatabaseInstanceDS_basic(t *testing.T) {
var (
resourceName = "data.mongodbatlas_federated_database_instance.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
name = acc.RandomName()
federatedInstance = admin.DataLakeTenant{}
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance,
Steps: []resource.TestStep{
{
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: configFirstStepsDS(name, projectName, orgID),
Check: resource.ComposeTestCheckFunc(
checkExists(resourceName, &federatedInstance),
checkAttributes(&federatedInstance, name),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttrSet(resourceName, "storage_stores.0.read_preference.0.tag_sets.#"),
resource.TestCheckResourceAttr(resourceName, "storage_stores.0.read_preference.0.tag_sets.#", "2"),
resource.TestCheckResourceAttr(resourceName, "storage_stores.0.read_preference.0.tag_sets.0.tags.#", "2"),
),
},
},
})
}

func TestAccFederatedDatabaseInstanceDS_s3Bucket(t *testing.T) {
var (
resourceName = "data.mongodbatlas_federated_database_instance.test"
Expand Down Expand Up @@ -264,105 +233,3 @@ data "mongodbatlas_federated_database_instance" "test" {
}
`, name, testS3Bucket)
}

func configFirstStepsDS(federatedInstanceName, projectName, orgID string) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "test" {
name = %[2]q
org_id = %[3]q
}
resource "mongodbatlas_federated_database_instance" "test" {
project_id = mongodbatlas_project.test.id
name = %[1]q
storage_databases {
name = "VirtualDatabase0"
collections {
name = "VirtualCollection0"
data_sources {
collection = "listingsAndReviews"
database = "sample_airbnb"
store_name = "ClusterTest"
}
}
}
storage_stores {
name = "ClusterTest"
cluster_name = "ClusterTest"
project_id = mongodbatlas_project.test.id
provider = "atlas"
read_preference {
mode = "secondary"
tag_sets {
tags {
name = "environment0"
value = "development0"
}
tags {
name = "application0"
value = "app0"
}
}
tag_sets {
tags {
name = "environment1"
value = "development1"
}
tags {
name = "application1"
value = "app1"
}
}
}
}
storage_stores {
name = "dataStore0"
cluster_name = "ClusterTest"
project_id = mongodbatlas_project.test.id
provider = "atlas"
read_preference {
mode = "secondary"
tag_sets {
tags {
name = "environment0"
value = "development0"
}
tags {
name = "application0"
value = "app0"
}
}
tag_sets {
tags {
name = "environment1"
value = "development1"
}
tags {
name = "application1"
value = "app1"
}
}
tag_sets {
tags {
name = "environment0"
value = "development0"
}
tags {
name = "application0"
value = "app0"
}
}
}
}
}
data "mongodbatlas_federated_database_instance" "test" {
project_id = mongodbatlas_federated_database_instance.test.project_id
name = mongodbatlas_federated_database_instance.test.name
}
`, federatedInstanceName, projectName, orgID)
}
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ func flattenCloudProviderConfig(d *schema.ResourceData, cloudProviderConfig *adm
}

func flattenDataProcessRegion(processRegion *admin.DataLakeDataProcessRegion) []map[string]any {
if processRegion == nil || (processRegion.Region != "" && processRegion.CloudProvider != "") {
if processRegion == nil {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,35 @@ import (

func TestAccFederatedDatabaseInstance_basic(t *testing.T) {
var (
resourceName = "mongodbatlas_federated_database_instance.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
name = acc.RandomName()
resourceName = "mongodbatlas_federated_database_instance.test"
dataSourceName = "data.mongodbatlas_federated_database_instance.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
name = acc.RandomName()
)

valueChecks := map[string]string{
"name": name,
"data_process_region.0.cloud_provider": "AWS",
"data_process_region.0.region": "OREGON_USA",
"storage_stores.0.read_preference.0.tag_sets.#": "2",
"storage_stores.0.read_preference.0.tag_sets.0.tags.#": "2",
"storage_databases.0.collections.0.data_sources.0.database": "sample_airbnb",
}
setChecks := []string{"project_id", "storage_stores.0.read_preference.0.tag_sets.#"}
firstStepChecks := acc.AddAttrChecks(resourceName, nil, valueChecks)
firstStepChecks = acc.AddAttrSetChecks(resourceName, firstStepChecks, setChecks...)
firstStepChecks = acc.AddAttrChecks(dataSourceName, firstStepChecks, valueChecks)
firstStepChecks = acc.AddAttrSetChecks(dataSourceName, firstStepChecks, setChecks...)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance,
Steps: []resource.TestStep{
{
Config: configFirstSteps(name, projectName, orgID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttrSet(resourceName, "storage_stores.0.read_preference.0.tag_sets.#"),
resource.TestCheckResourceAttr(resourceName, "storage_stores.0.read_preference.0.tag_sets.#", "2"),
resource.TestCheckResourceAttr(resourceName, "storage_stores.0.read_preference.0.tag_sets.0.tags.#", "2"),
resource.TestCheckResourceAttr(resourceName, "storage_databases.0.collections.0.data_sources.0.database", "sample_airbnb"),
),
Check: resource.ComposeTestCheckFunc(firstStepChecks...),
},
{
Config: configFirstStepsUpdate(name, projectName, orgID),
Expand Down Expand Up @@ -489,6 +497,11 @@ resource "mongodbatlas_federated_database_instance" "test" {
}
}
}
data "mongodbatlas_federated_database_instance" "test" {
project_id = mongodbatlas_federated_database_instance.test.project_id
name = mongodbatlas_federated_database_instance.test.name
}
`, federatedInstanceName, projectName, orgID)
}

Expand Down

0 comments on commit 7841c1d

Please sign in to comment.