Skip to content

Commit

Permalink
fix TestAccV2NutanixUsersResource_LDAPUser, delete user using V3 api …
Browse files Browse the repository at this point in the history
…to automate the test
  • Loading branch information
Haroon-Dweikat-Ntx committed Dec 10, 2024
1 parent 241feec commit 6d0a9c6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 27 additions & 2 deletions nutanix/services/iamv2/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package iamv2_test

import (
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
conns "github.com/terraform-providers/terraform-provider-nutanix/nutanix"
acc "github.com/terraform-providers/terraform-provider-nutanix/nutanix/acctest"
"strconv"
"strings"
)

func checkAttributeLength(resourceName, attribute string, minLength int) resource.TestCheckFunc {
Expand Down Expand Up @@ -33,3 +35,26 @@ func checkAttributeLength(resourceName, attribute string, minLength int) resourc
return nil
}
}

func testAccCheckNutanixUserDestroy(s *terraform.State) error {
fmt.Println("Checking user destroy")
conn := acc.TestAccProvider.Meta().(*conns.Client)

for _, rs := range s.RootModule().Resources {
if rs.Type != "nutanix_users_v2" {
continue
}
if _, err := conn.API.V3.GetUser(rs.Primary.ID); err != nil {
if strings.Contains(fmt.Sprint(err), "ENTITY_NOT_FOUND") {
return nil
}
return err
}
_, err := conn.API.V3.DeleteUser("4f1d9cf6-83dc-5fe2-8dd1-a84e062aaeee")
if err != nil {
return err
}
fmt.Println("Deleted user")
}
return nil
}
2 changes: 2 additions & 0 deletions nutanix/services/iamv2/resource_nutanix_users_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ func TestAccV2NutanixUsersResource_LDAPUser(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccFoundationPreCheck(t) },
Providers: acc.TestAccProviders,
// using V3 API to delete user
CheckDestroy: testAccCheckNutanixUserDestroy,
Steps: []resource.TestStep{
{
Config: testLDAPUserWithMinimalConfigResourceConfig(filepath),
Expand Down

0 comments on commit 6d0a9c6

Please sign in to comment.