From 9654fa4fc3f568a3968d43224f085ed79b9c47ed Mon Sep 17 00:00:00 2001 From: Shreevari SP Date: Thu, 10 Feb 2022 18:06:23 +0530 Subject: [PATCH] Add an acceptance test for subnet datasource filters --- nutanix/data_source_nutanix_subnet_test.go | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/nutanix/data_source_nutanix_subnet_test.go b/nutanix/data_source_nutanix_subnet_test.go index 1ea6a901c..0591fc9c4 100644 --- a/nutanix/data_source_nutanix_subnet_test.go +++ b/nutanix/data_source_nutanix_subnet_test.go @@ -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" {} @@ -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" {