Skip to content

Commit

Permalink
test: added test for search by name using datasource of acp
Browse files Browse the repository at this point in the history
  • Loading branch information
Edgar López committed Jan 20, 2021
1 parent 004c7d3 commit bf9be64
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions nutanix/data_source_nutanix_access_control_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccNutanixAccessControlPolicyDataSource_basic(t *testing.T) {
func TestAccNutanixAccessControlPolicyDataSourceByID_basic(t *testing.T) {
name := acctest.RandomWithPrefix("accest-access-policy")
description := "Description of my access control policy"

Expand All @@ -18,7 +18,7 @@ func TestAccNutanixAccessControlPolicyDataSource_basic(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAccessControlPolicyDataSourceConfig(name, description),
Config: testAccAccessControlPolicyDataSourceByIDConfig(name, description),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.nutanix_access_control_policy.test", "name", name),
Expand All @@ -31,7 +31,29 @@ func TestAccNutanixAccessControlPolicyDataSource_basic(t *testing.T) {
})
}

func testAccAccessControlPolicyDataSourceConfig(name, description string) string {
func TestAccNutanixAccessControlPolicyDataSourceByName_basic(t *testing.T) {
name := acctest.RandomWithPrefix("accest-access-policy")
description := "Description of my access control policy"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAccessControlPolicyDataSourceByNameConfig(name, description),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.nutanix_access_control_policy.test", "name", name),
resource.TestCheckResourceAttr(
"data.nutanix_access_control_policy.test", "description", description),
resource.TestCheckResourceAttrSet("data.nutanix_access_control_policy.test", "name"),
),
},
},
})
}

func testAccAccessControlPolicyDataSourceByIDConfig(name, description string) string {
return fmt.Sprintf(`
resource "nutanix_role" "test" {
name = "test role"
Expand All @@ -55,3 +77,28 @@ data "nutanix_access_control_policy" "test" {
}
`, name, description)
}

func testAccAccessControlPolicyDataSourceByNameConfig(name, description string) string {
return fmt.Sprintf(`
resource "nutanix_role" "test" {
name = "test role 2"
description = "description role"
permission_reference_list {
kind = "permission"
uuid = "2e9988df-47ae-44ae-9114-ada346657b90"
}
}
resource "nutanix_access_control_policy" "test" {
name = "%[1]s"
description = "%[2]s"
role_reference{
kind = "role"
uuid = nutanix_role.test.id
}
}
data "nutanix_access_control_policy" "test" {
access_control_policy_name = nutanix_access_control_policy.test.name
}
`, name, description)
}

0 comments on commit bf9be64

Please sign in to comment.