Skip to content

Commit

Permalink
chore: Creates test group mongodbatlas_global_cluster_config and up…
Browse files Browse the repository at this point in the history
…dates tests (#2636)

* test group for global_cluster_config

* unify ds tests with resource

* update test checks

* add data source in tests

* join similar tests
  • Loading branch information
lantoli authored Sep 25, 2024
1 parent ecb0a1c commit ee78a92
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 156 deletions.
33 changes: 27 additions & 6 deletions .github/workflows/acceptance-tests-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ jobs:
event_trigger: ${{ steps.filter.outputs.event_trigger == 'true' || env.mustTrigger == 'true' }}
federated: ${{ steps.filter.outputs.federated == 'true' || env.mustTrigger == 'true' }}
generic: ${{ steps.filter.outputs.generic == 'true' || env.mustTrigger == 'true' }}
global_cluster_config: ${{ steps.filter.outputs.global_cluster_config == 'true' || env.mustTrigger == 'true' }}
ldap: ${{ steps.filter.outputs.ldap == 'true' || env.mustTrigger == 'true' }}
mongodb_employee_access_grant: ${{ steps.filter.outputs.mongodb_employee_access_grant == 'true' || env.mustTrigger == 'true' }}
network: ${{ steps.filter.outputs.network == 'true' || env.mustTrigger == 'true' }}
Expand Down Expand Up @@ -240,7 +241,6 @@ jobs:
- 'internal/service/controlplaneipaddresses/*.go'
cluster:
- 'internal/service/cluster/*.go'
- 'internal/service/globalclusterconfig/*.go'
cluster_outage_simulation:
- 'internal/service/clusteroutagesimulation/*.go'
config:
Expand Down Expand Up @@ -273,6 +273,8 @@ jobs:
- 'internal/service/auditing/*.go'
- 'internal/service/backupcompliancepolicy/*.go'
- 'internal/service/x509authenticationdatabaseuser/*.go'
global_cluster_config:
- 'internal/service/globalclusterconfig/*.go'
ldap:
- 'internal/service/ldapconfiguration/*.go'
- 'internal/service/ldapverify/*.go'
Expand Down Expand Up @@ -425,8 +427,7 @@ jobs:
- name: Acceptance Tests
env:
MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }}
ACCTEST_PACKAGES: |
./internal/service/controlplaneipaddresses
ACCTEST_PACKAGES: ./internal/service/controlplaneipaddresses
run: make testacc

cluster:
Expand All @@ -448,9 +449,7 @@ jobs:
- name: Acceptance Tests
env:
MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }}
ACCTEST_PACKAGES: |
./internal/service/cluster
./internal/service/globalclusterconfig
ACCTEST_PACKAGES: ./internal/service/cluster
run: make testacc

cluster_outage_simulation:
Expand Down Expand Up @@ -643,6 +642,28 @@ jobs:
./internal/service/x509authenticationdatabaseuser
run: make testacc

global_cluster_config:
needs: [ change-detection, get-provider-version ]
if: ${{ needs.change-detection.outputs.global_cluster_config == 'true' || inputs.test_group == 'global_cluster_config' }}
runs-on: ubuntu-latest
permissions: {}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
ref: ${{ inputs.ref || github.ref }}
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
with:
terraform_version: ${{ inputs.terraform_version }}
terraform_wrapper: false
- name: Acceptance Tests
env:
MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }}
ACCTEST_PACKAGES: ./internal/service/globalclusterconfig
run: make testacc

ldap:
needs: [ change-detection, get-provider-version ]
if: ${{ needs.change-detection.outputs.ldap == 'true' || inputs.test_group == 'ldap' }}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,9 @@ package globalclusterconfig_test
import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
)

func TestMigClusterRSGlobalCluster_basic(t *testing.T) {
var (
clusterInfo = acc.GetClusterInfo(t, &acc.ClusterRequest{Geosharded: true})
config = configBasic(&clusterInfo, false, false)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: config,
Check: resource.ComposeAggregateTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mappings.#"),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mapping.%"),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mapping.CA"),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "cluster_name", clusterInfo.Name),
resource.TestCheckResourceAttr(resourceName, "managed_namespaces.#", "1"),
resource.TestCheckResourceAttr(resourceName, "managed_namespaces.0.is_custom_shard_key_hashed", "false"),
resource.TestCheckResourceAttr(resourceName, "managed_namespaces.0.is_shard_key_unique", "false"),
),
},
mig.TestStepCheckEmptyPlan(config),
},
})
func TestMigGlobalClusterConfig_basic(t *testing.T) {
mig.CreateAndRunTest(t, basicTestCase(t, false))
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,58 +13,40 @@ import (
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
)

func TestAccClusterRSGlobalCluster_basic(t *testing.T) {
var (
clusterInfo = acc.GetClusterInfo(t, &acc.ClusterRequest{Geosharded: true})
)
const (
resourceName = "mongodbatlas_global_cluster_config.config"
dataSourceName = "data.mongodbatlas_global_cluster_config.config"
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
Config: configBasic(&clusterInfo, false, false),
Check: resource.ComposeAggregateTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mappings.#"),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mapping.%"),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mapping.CA"),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "cluster_name", clusterInfo.Name),
resource.TestCheckResourceAttr(resourceName, "managed_namespaces.#", "1"),
resource.TestCheckResourceAttr(resourceName, "managed_namespaces.0.is_custom_shard_key_hashed", "false"),
resource.TestCheckResourceAttr(resourceName, "managed_namespaces.0.is_shard_key_unique", "false"),
),
},
{
Config: configBasic(&clusterInfo, true, false),
ExpectError: regexp.MustCompile("Updating a global cluster configuration resource is not allowed"),
},
},
})
func TestAccGlobalClusterConfig_basic(t *testing.T) {
resource.ParallelTest(t, *basicTestCase(t, false))
}

func TestAccClusterRSGlobalCluster_withAWSAndBackup(t *testing.T) {
var (
clusterInfo = acc.GetClusterInfo(t, &acc.ClusterRequest{Geosharded: true, CloudBackup: true})
)
func TestAccGlobalClusterConfig_withBackup(t *testing.T) {
resource.ParallelTest(t, *basicTestCase(t, true))
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
func basicTestCase(tb testing.TB, withBackup bool) *resource.TestCase {
tb.Helper()
clusterInfo := acc.GetClusterInfo(tb, &acc.ClusterRequest{Geosharded: true, CloudBackup: withBackup})

return &resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(tb) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
Config: configBasic(&clusterInfo, false, false),
Check: resource.ComposeAggregateTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "managed_namespaces.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mappings.#"),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mapping.%"),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mapping.CA"),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "cluster_name", clusterInfo.Name),
acc.CheckRSAndDS(resourceName, nil, nil,
[]string{"custom_zone_mappings.#", "custom_zone_mapping.%", "custom_zone_mapping.CA", "project_id"},
map[string]string{
"cluster_name": clusterInfo.Name,
"managed_namespaces.#": "1",
"managed_namespaces.0.is_custom_shard_key_hashed": "false",
"managed_namespaces.0.is_shard_key_unique": "false",
}),
),
},
{
Expand All @@ -74,11 +56,51 @@ func TestAccClusterRSGlobalCluster_withAWSAndBackup(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"custom_zone_mappings"},
},
{
Config: configBasic(&clusterInfo, true, false),
ExpectError: regexp.MustCompile("Updating a global cluster configuration resource is not allowed"),
},
},
})
}
}

func TestAccClusterRSGlobalCluster_database(t *testing.T) {
func TestAccGlobalClusterConfig_database(t *testing.T) {
const (
customZone = `
custom_zone_mappings {
location = "US"
zone = "US"
}
custom_zone_mappings {
location = "IE"
zone = "EU"
}
custom_zone_mappings {
location = "DE"
zone = "DE"
}
`

customZoneUpdated = `
custom_zone_mappings {
location = "US"
zone = "US"
}
custom_zone_mappings {
location = "IE"
zone = "EU"
}
custom_zone_mappings {
location = "DE"
zone = "DE"
}
custom_zone_mappings {
location = "JP"
zone = "JP"
}
`
)

var (
specUS = acc.ReplicationSpecRequest{ZoneName: "US", Region: "US_EAST_1"}
specEU = acc.ReplicationSpecRequest{ZoneName: "EU", Region: "EU_WEST_1"}
Expand All @@ -96,14 +118,12 @@ func TestAccClusterRSGlobalCluster_database(t *testing.T) {
Config: configWithDBConfig(&clusterInfo, customZone),
Check: resource.ComposeAggregateTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "managed_namespaces.#", "5"),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mappings.#"),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mapping.%"),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mapping.US"),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mapping.IE"),
resource.TestCheckResourceAttrSet(resourceName, "custom_zone_mapping.DE"),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "cluster_name", clusterInfo.Name),
acc.CheckRSAndDS(resourceName, nil, nil,
[]string{"custom_zone_mappings.#", "custom_zone_mapping.%", "custom_zone_mapping.US", "custom_zone_mapping.IE", "custom_zone_mapping.DE", "project_id"},
map[string]string{
"cluster_name": clusterInfo.Name,
"managed_namespaces.#": "5",
}),
),
},
{
Expand Down Expand Up @@ -194,8 +214,9 @@ func configBasic(info *acc.ClusterInfo, isCustomShard, isShardKeyUnique bool) st
}
data "mongodbatlas_global_cluster_config" "config" {
cluster_name = %[1]s
project_id = %[2]q
project_id = mongodbatlas_global_cluster_config.config.project_id
cluster_name = mongodbatlas_global_cluster_config.config.cluster_name
depends_on = [mongodbatlas_global_cluster_config.config]
}
`, info.TerraformNameRef, info.ProjectID, isCustomShard, isShardKeyUnique)
}
Expand Down Expand Up @@ -233,43 +254,11 @@ func configWithDBConfig(info *acc.ClusterInfo, zones string) string {
}
%[3]s
}
data "mongodbatlas_global_cluster_config" "config" {
project_id = mongodbatlas_global_cluster_config.config.project_id
cluster_name = mongodbatlas_global_cluster_config.config.cluster_name
depends_on = [mongodbatlas_global_cluster_config.config]
}
`, info.TerraformNameRef, info.ProjectID, zones)
}

const (
resourceName = "mongodbatlas_global_cluster_config.config"
dataSourceName = "data.mongodbatlas_global_cluster_config.config"

customZone = `
custom_zone_mappings {
location = "US"
zone = "US"
}
custom_zone_mappings {
location = "IE"
zone = "EU"
}
custom_zone_mappings {
location = "DE"
zone = "DE"
}
`
customZoneUpdated = `
custom_zone_mappings {
location = "US"
zone = "US"
}
custom_zone_mappings {
location = "IE"
zone = "EU"
}
custom_zone_mappings {
location = "DE"
zone = "DE"
}
custom_zone_mappings {
location = "JP"
zone = "JP"
}
`
)

0 comments on commit ee78a92

Please sign in to comment.