Skip to content

Commit

Permalink
chore: Reuses project in tests for project_api_key resource (#2037)
Browse files Browse the repository at this point in the history
* testAccMongoDBAtlasProjectAPIKeyConfigBasic

* more ProjectIDExecution

* refactor

* use global project in mig tests

* mig.ProjectIDGlobal

* use mig project
  • Loading branch information
lantoli committed Mar 18, 2024
1 parent 8321bfc commit 9040304
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 154 deletions.
@@ -1,29 +1,26 @@
package projectapikey_test

import (
"os"
"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 TestMigConfigRSProjectAPIKey_RemovingOptionalRootProjectID(t *testing.T) {
var (
resourceName = "mongodbatlas_project_api_key.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
description = acc.RandomName()
roleName = "GROUP_OWNER"
projectID = mig.ProjectIDGlobal(t)
description = acc.RandomName()
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
CheckDestroy: testAccCheckMongoDBAtlasProjectAPIKeyDestroy,
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: acc.ExternalProviders("1.13.1"), // fixed version as this is the last version where root project id was required.
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, true),
Config: configBasic(projectID, description, roleName, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "description", description),
Expand All @@ -33,7 +30,7 @@ func TestMigConfigRSProjectAPIKey_RemovingOptionalRootProjectID(t *testing.T) {
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, true),
Config: configBasic(projectID, description, roleName, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "description", description),
Expand All @@ -43,7 +40,7 @@ func TestMigConfigRSProjectAPIKey_RemovingOptionalRootProjectID(t *testing.T) {
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, false),
Config: configBasic(projectID, description, roleName, false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "description", description),
resource.TestCheckResourceAttrSet(resourceName, "public_key"),
Expand Down

0 comments on commit 9040304

Please sign in to comment.