Skip to content

Commit

Permalink
Add an acceptance test for subnet datasource filters
Browse files Browse the repository at this point in the history
  • Loading branch information
shreevari committed Feb 10, 2022
1 parent 4fac6d9 commit 9654fa4
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions nutanix/data_source_nutanix_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ func TestAccNutanixSubnetDataSource_conflicts(t *testing.T) {
})
}

func TestAccNutanixSubnetDataSource_nameWithFilters(t *testing.T) {
r := randIntBetween(11, 20)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccSubnetDataSourceConfigNameWithFilters(r, r),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.nutanix_subnet.test", "subnet_type", "VLAN"),
),
},
{
Config: testAccSubnetDataSourceConfigNameWithFilters(r, 30),
ExpectError: regexp.MustCompile("subnet with the given name, not found"),
},
},
})
}

func testAccSubnetDataSourceConfig(r int) string {
return fmt.Sprintf(`
data "nutanix_clusters" "clusters" {}
Expand Down Expand Up @@ -135,6 +156,34 @@ data "nutanix_subnet" "test" {
`, r, r)
}

func testAccSubnetDataSourceConfigNameWithFilters(r int, f int) string {
return fmt.Sprintf(`
data "nutanix_clusters" "clusters" {}
locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}
resource "nutanix_subnet" "test" {
name = "dnd_acc_test_vlan0_test_%d"
cluster_uuid = local.cluster1
vlan_id = %d
subnet_type = "VLAN"
}
data "nutanix_subnet" "test" {
subnet_name = nutanix_subnet.test.name
additional_filter {
name = "vlan_id"
values = ["%d"]
}
}
`, r, r, f)
}

func testAccSubnetDataSourceBadConfig() string {
return `
data "nutanix_subnet" "test" {
Expand Down

0 comments on commit 9654fa4

Please sign in to comment.