Skip to content

Commit

Permalink
chore: Uses TestStepCheckEmptyPlan in mig tests (#2597)
Browse files Browse the repository at this point in the history
* these are not mig tests

* access_list_api_key mig tests

* use TestStepCheckEmptyPlan
  • Loading branch information
lantoli authored Sep 13, 2024
1 parent 89802aa commit c20f162
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

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

"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
Expand Down Expand Up @@ -45,6 +44,7 @@ func TestMigProjectAccesslistAPIKey_SettingCIDRBlock(t *testing.T) {
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
cidrBlock = acc.RandomIP(179, 154, 226) + "/32"
description = acc.RandomName()
config = configWithCIDRBlock(orgID, description, cidrBlock)
)

resource.Test(t, resource.TestCase{
Expand All @@ -53,24 +53,14 @@ func TestMigProjectAccesslistAPIKey_SettingCIDRBlock(t *testing.T) {
Steps: []resource.TestStep{
{
ExternalProviders: acc.ExternalProviders("1.14.0"),
Config: configWithCIDRBlock(orgID, description, cidrBlock),
Config: config,
Check: resource.ComposeAggregateTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "org_id", orgID),
resource.TestCheckResourceAttr(resourceName, "cidr_block", cidrBlock),
),
},
{
ExternalProviders: mig.ExternalProviders(),
Config: configWithCIDRBlock(orgID, description, cidrBlock),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
},
},
},
mig.TestStepCheckEmptyPlan(configWithCIDRBlock(orgID, description, cidrBlock)),
mig.TestStepCheckEmptyPlan(config),
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
Expand Down Expand Up @@ -150,15 +149,6 @@ func TestAccBackupCompliancePolicy_UpdateSetsAllAttributes(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "copy_protection_enabled", "true"),
),
},
{
Config: configBasicWithOptionalAttributesWithNonDefaultValues(projectName, orgID, projectOwnerID, "8"),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
},
},
},
},
})
}
Expand Down
10 changes: 0 additions & 10 deletions internal/service/cluster/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
clustersvc "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cluster"
Expand Down Expand Up @@ -580,15 +579,6 @@ func TestAccCluster_ProviderRegionName(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "replication_specs.0.regions_config.#", "3"),
),
},
{
Config: configMultiRegion(orgID, projectName, clusterName, "false", updatedRegionsConfig),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
},
},
},
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestMigEncryptionAtRest_withRole_basicAWS(t *testing.T) {
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
plancheck.ExpectEmptyPlan(), // special case using AWS resources
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
)
Expand All @@ -16,6 +15,7 @@ func TestMigFederatedDatabaseInstance_basic(t *testing.T) {
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
name = acc.RandomName()
config = configFirstSteps(name, projectName, orgID)
)

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -24,7 +24,7 @@ func TestMigFederatedDatabaseInstance_basic(t *testing.T) {
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: configFirstSteps(name, projectName, orgID),
Config: config,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "name", name),
Expand All @@ -34,15 +34,7 @@ func TestMigFederatedDatabaseInstance_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "storage_databases.0.collections.0.data_sources.0.database", "sample_airbnb"),
),
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: configFirstSteps(name, projectName, orgID),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
},
},
mig.TestStepCheckEmptyPlan(config),
},
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
Expand Down Expand Up @@ -63,15 +62,6 @@ func TestAccFederatedDatabaseInstance_basic(t *testing.T) {
ImportStateVerifyIgnore: []string{"storage_stores.0.allow_insecure", "storage_stores.0.include_tags", "storage_stores.0.read_preference.0.max_staleness_seconds",
"storage_stores.1.allow_insecure", "storage_stores.1.include_tags", "storage_stores.1.read_preference.0.max_staleness_seconds"},
},
{
Config: configFirstStepsUpdate(name, projectName, orgID),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
},
},
},
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

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

"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
Expand All @@ -20,29 +19,21 @@ func TestMigConfigRSOrganization_Basic(t *testing.T) {
name = acc.RandomName()
description = "test Key for Acceptance tests"
roleName = "ORG_OWNER"
config = configBasic(orgOwnerID, name, description, roleName)
)

resource.Test(t, resource.TestCase{
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: configBasic(orgOwnerID, name, description, roleName),
Config: config,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "org_id"),
resource.TestCheckResourceAttrSet(resourceName, "description"),
resource.TestCheckResourceAttr(resourceName, "description", description),
),
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: configBasic(orgOwnerID, name, description, roleName),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
},
},
},
mig.TestStepCheckEmptyPlan(config),
},
})
}
10 changes: 0 additions & 10 deletions internal/service/project/resource_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/stretchr/testify/mock"

Expand Down Expand Up @@ -1045,15 +1044,6 @@ func TestAccProject_withTags(t *testing.T) {
Config: configWithTags(orgID, projectName, map[string]string{}, `tags["Name"]`),
Check: tagChecks(tagsOnlyIgnored, "Environment", "NewKey"),
},
{
Config: configWithTags(orgID, projectName, tagsOnlyIgnored),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
},
},
},
{
ResourceName: resourceName,
ImportStateIdFunc: acc.ImportStateProjectIDFunc(resourceName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
)
Expand All @@ -17,6 +16,7 @@ func TestMigProjectInvitation_basic(t *testing.T) {
projectName = acc.RandomProjectName()
name = acc.RandomEmail()
roles = []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_CLUSTER_MANAGER"}
config = configBasic(orgID, projectName, name, roles)
)

resource.Test(t, resource.TestCase{
Expand All @@ -25,7 +25,7 @@ func TestMigProjectInvitation_basic(t *testing.T) {
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: configBasic(orgID, projectName, name, roles),
Config: config,
Check: resource.ComposeAggregateTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
Expand All @@ -36,16 +36,7 @@ func TestMigProjectInvitation_basic(t *testing.T) {
resource.TestCheckTypeSetElemAttr(resourceName, "roles.*", roles[1]),
),
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: configBasic(orgID, projectName, name, roles),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
},
},
},
mig.TestStepCheckEmptyPlan(config),
},
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
)
Expand All @@ -15,6 +14,7 @@ func TestMigStreamRSStreamConnection_kafkaPlaintext(t *testing.T) {
resourceName = "mongodbatlas_stream_connection.test"
projectID = acc.ProjectIDExecution(t)
instanceName = acc.RandomName()
config = kafkaStreamConnectionConfig(projectID, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", false)
)
mig.SkipIfVersionBelow(t, "1.16.0") // when reached GA

Expand All @@ -24,19 +24,10 @@ func TestMigStreamRSStreamConnection_kafkaPlaintext(t *testing.T) {
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: kafkaStreamConnectionConfig(projectID, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", false),
Config: config,
Check: kafkaStreamConnectionAttributeChecks(resourceName, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", false, true),
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: kafkaStreamConnectionConfig(projectID, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", false),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
},
},
},
mig.TestStepCheckEmptyPlan(config),
},
})
}
Expand All @@ -46,6 +37,7 @@ func TestMigStreamRSStreamConnection_kafkaSSL(t *testing.T) {
resourceName = "mongodbatlas_stream_connection.test"
projectID = acc.ProjectIDExecution(t)
instanceName = acc.RandomName()
config = kafkaStreamConnectionConfig(projectID, instanceName, "user", "rawpassword", "localhost:9092", "earliest", true)
)
mig.SkipIfVersionBelow(t, "1.16.0") // when reached GA

Expand All @@ -55,19 +47,10 @@ func TestMigStreamRSStreamConnection_kafkaSSL(t *testing.T) {
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: kafkaStreamConnectionConfig(projectID, instanceName, "user", "rawpassword", "localhost:9092", "earliest", true),
Config: config,
Check: kafkaStreamConnectionAttributeChecks(resourceName, instanceName, "user", "rawpassword", "localhost:9092", "earliest", true, true),
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: kafkaStreamConnectionConfig(projectID, instanceName, "user", "rawpassword", "localhost:9092", "earliest", true),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
},
},
},
mig.TestStepCheckEmptyPlan(config),
},
})
}
Expand All @@ -77,6 +60,7 @@ func TestMigStreamRSStreamConnection_cluster(t *testing.T) {
resourceName = "mongodbatlas_stream_connection.test"
projectID, clusterName = acc.ClusterNameExecution(t)
instanceName = acc.RandomName()
config = clusterStreamConnectionConfig(projectID, instanceName, clusterName)
)
mig.SkipIfVersionBelow(t, "1.16.0") // when reached GA

Expand All @@ -86,19 +70,10 @@ func TestMigStreamRSStreamConnection_cluster(t *testing.T) {
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: clusterStreamConnectionConfig(projectID, instanceName, clusterName),
Config: config,
Check: clusterStreamConnectionAttributeChecks(resourceName, clusterName),
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: clusterStreamConnectionConfig(projectID, instanceName, clusterName),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
},
},
},
mig.TestStepCheckEmptyPlan(config),
},
})
}
Loading

0 comments on commit c20f162

Please sign in to comment.