Skip to content

Commit

Permalink
test Unregister remote cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroon-Dweikat-Ntx committed Jan 21, 2025
1 parent e65ecc5 commit 2c138e3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func ResourceNutanixUnregisterClusterV2Create(ctx context.Context, d *schema.Res
ExtId: utils.StringPtr(extID.(string)),
}

aJSON, _ := json.MarshalIndent(body, "", " ")
log.Printf("[DEBUG] Unregister Cluster Request Body: %s", string(aJSON))

resp, err := conn.DomainManagerAPIInstance.Unregister(utils.StringPtr(pcExtID.(string)), &body, args)

if err != nil {
Expand Down Expand Up @@ -80,7 +83,7 @@ func ResourceNutanixUnregisterClusterV2Create(ctx context.Context, d *schema.Res
}

rUUID := resourceUUID.Data.GetValue().(config.Task)
aJSON, _ := json.MarshalIndent(rUUID, "", " ")
aJSON, _ = json.MarshalIndent(rUUID, "", " ")
log.Printf("[DEBUG] Unregister Cluster Task Details: %s", string(aJSON))

uuid := rUUID.EntitiesAffected[0].ExtId
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package prismv2_test

import (
"encoding/json"
"fmt"
"testing"

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

const resourceNameUnregisterCluster = "nutanix_unregister_cluster_v2.test"

func TestAccV2NutanixUnregisterClusterResource_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccUnregisterClusterResourceConfig(),
Check: resource.ComposeTestCheckFunc(
func(s *terraform.State) error {
aJson, _ := json.MarshalIndent(s.RootModule().Resources[resourceNameUnregisterCluster].Primary.Attributes, "", " ")

Check failure on line 24 in nutanix/services/prismv2/resource_nutanix_unregister_cluster_v2_test.go

View workflow job for this annotation

GitHub Actions / tests

var `aJson` should be `aJSON` (golint)
fmt.Println("############################################")
fmt.Println(fmt.Sprintf("Resource Attributes: \n%v", string(aJson)))

Check failure on line 26 in nutanix/services/prismv2/resource_nutanix_unregister_cluster_v2_test.go

View workflow job for this annotation

GitHub Actions / tests

S1038: should use fmt.Printf instead of fmt.Println(fmt.Sprintf(...)) (but don't forget the newline) (gosimple)
fmt.Println("############################################")

return nil
},
resource.TestCheckResourceAttrSet(resourceNameUnregisterCluster, "pc_ext_id"),
resource.TestCheckResourceAttrSet(resourceNameUnregisterCluster, "ext_id"),
),
},
},
})
}

func testAccUnregisterClusterResourceConfig() string {
return fmt.Sprintf(`
data "nutanix_clusters_v2" "clusters" {}
locals {
pcExtID = [
for cluster in data.nutanix_clusters_v2.clusters.cluster_entities :
cluster.ext_id if cluster.config[0].cluster_function[0] == "PRISM_CENTRAL"
][0]
config = (jsondecode(file("%[1]s")))
prism = local.config.prism
}
resource "nutanix_unregister_cluster_v2" "test"{
pc_ext_id = local.pcExtID
ext_id = local.prism.cluster_ext_id
}
`, filepath)
}
1 change: 1 addition & 0 deletions test_config_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
"domain_manager_ext_id": ""
},
"prism": {
"cluster_ext_id": "",
"bucket": {
"name": "",
"region": "",
Expand Down

0 comments on commit 2c138e3

Please sign in to comment.