Skip to content

Commit

Permalink
checkDestroy
Browse files Browse the repository at this point in the history
  • Loading branch information
lantoli committed Mar 26, 2024
1 parent 448f5be commit 4de6c61
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 16 deletions.
11 changes: 5 additions & 6 deletions internal/service/auditing/resource_auditing_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import (

func TestMigGenericAuditing_basic(t *testing.T) {
var (
resourceName = "mongodbatlas_auditing.test"
projectID = mig.ProjectIDGlobal(t)
auditAuth = true
auditFilter = "{ 'atype': 'authenticate', 'param': { 'user': 'auditAdmin', 'db': 'admin', 'mechanism': 'SCRAM-SHA-1' }}"
enabled = true
config = configBasic(projectID, auditFilter, auditAuth, enabled)
projectID = mig.ProjectIDGlobal(t)
auditAuth = true
auditFilter = "{ 'atype': 'authenticate', 'param': { 'user': 'auditAdmin', 'db': 'admin', 'mechanism': 'SCRAM-SHA-1' }}"
enabled = true
config = configBasic(projectID, auditFilter, auditAuth, enabled)
)

resource.ParallelTest(t, resource.TestCase{
Expand Down
5 changes: 1 addition & 4 deletions internal/service/auditing/resource_auditing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,12 @@ func checkExists(resourceName string) resource.TestCheckFunc {
}

func checkDestroy(s *terraform.State) error {
if acc.UsingLocalResources() {
return nil
}
for _, rs := range s.RootModule().Resources {
if rs.Type != "mongodbatlas_auditing" {
continue
}
auditingRes, _, _ := acc.ConnV2().AuditingApi.GetAuditingConfiguration(context.Background(), rs.Primary.ID).Execute()
if auditingRes != nil {
if auditingRes.GetEnabled() {
return fmt.Errorf("auditing (%s) exists", rs.Primary.ID)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func checkExists(resourceName string) resource.TestCheckFunc {
}

func checkDestroy(s *terraform.State) error {
if acc.UsingLocalResources() {
if acc.ExistingClusterUsed() {
return nil
}
for _, rs := range s.RootModule().Resources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func checkExists(resourceName string) resource.TestCheckFunc {
}

func checkDestroy(s *terraform.State) error {
if acc.UsingLocalResources() {
if acc.ExistingClusterUsed() {
return nil
}
for _, rs := range s.RootModule().Resources {
Expand Down
5 changes: 2 additions & 3 deletions internal/testutil/acc/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ func GetClusterInfo(tb testing.TB, req *ClusterRequest) ClusterInfo {
}
}

// UsingLocalResources is normally used in CheckDestroy when an existing project or cluster is used in local.
func UsingLocalResources() bool {
func ExistingClusterUsed() bool {
clusterName := os.Getenv("MONGODB_ATLAS_CLUSTER_NAME")
projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID")
return clusterName != "" || projectID != ""
return clusterName != "" && projectID != ""
}
2 changes: 1 addition & 1 deletion internal/testutil/acc/search_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func CheckDestroySearchIndex(state *terraform.State) error {
if UsingLocalResources() {
if ExistingClusterUsed() {
return nil
}
for _, rs := range state.RootModule().Resources {
Expand Down

0 comments on commit 4de6c61

Please sign in to comment.