Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kobi Samoray <[email protected]>
  • Loading branch information
ksamoray committed Jun 10, 2024
1 parent 15985a9 commit ddfeb34
Show file tree
Hide file tree
Showing 48 changed files with 942 additions and 7 deletions.
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_dhcp_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func TestAccDataSourceNsxtPolicyDhcpServer_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicyDhcpServer_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyDhcpServerBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicyDhcpServerBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_dhcp_server.test"
Expand Down
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_gateway_locale_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ func TestAccDataSourceNsxtPolicyGatewayLocaleService_multitenancy(t *testing.T)
})
}

func TestAccDataSourceNsxtPolicyGatewayLocaleService_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyGatewayLocaleServiceDefault(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccNsxtPolicyGatewayLocaleServiceTemplate(name string, withContext bool) string {
context := ""
if withContext {
Expand Down
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_gateway_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ func TestAccDataSourceNsxtPolicyGatewayPolicy_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicyGatewayPolicy_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyGatewayPolicyBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicyGatewayPolicyBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
category := "LocalGatewayRules"
Expand Down
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_gateway_qos_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func TestAccDataSourceNsxtPolicyGatewayQosProfile_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicyGatewayQosProfile_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyGatewayQosProfileBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicyGatewayQosProfileBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_gateway_qos_profile.test"
Expand Down
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func TestAccDataSourceNsxtPolicyGroup_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicyGroup_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyGroupBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicyGroupBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
domain := "default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func TestAccDataSourceNsxtPolicyIntrusionServiceProfile_multitenancy(t *testing.
})
}

func TestAccDataSourceNsxtPolicyIntrusionServiceProfile_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyIntrusionServiceProfileBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicyIntrusionServiceProfileBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestResourceName()
testResourceName := "data.nsxt_policy_intrusion_service_profile.test"
Expand Down
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_ip_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ func TestAccDataSourceNsxtPolicyIpBlock_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicyIpBlock_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyIPBlockBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicyIPBlockBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_ip_block.test"
Expand Down
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_ip_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ func TestAccDataSourceNsxtPolicyIpPool_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicyIpPool_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyIPPoolBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicyIPPoolBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_ip_pool.test"
Expand Down
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_ipv6_dad_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func TestAccDataSourceNsxtPolicyIpv6DadProfile_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicyIpv6DadProfile_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyIpv6DadProfileBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicyIpv6DadProfileBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_ipv6_dad_profile.test"
Expand Down
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_ipv6_ndra_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func TestAccDataSourceNsxtPolicyIpv6NdraProfile_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicyIpv6NdraProfile_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyIpv6NdraProfileBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicyIpv6NdraProfileBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_ipv6_ndra_profile.test"
Expand Down
31 changes: 28 additions & 3 deletions nsxt/data_source_nsxt_policy_mac_discovery_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,29 @@ func TestAccDataSourceNsxtPolicyMacDiscoveryProfile_multitenancy(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccNsxtPolicyMacDiscoveryProfileMultitenancyTemplate(name),
Config: testAccNsxtPolicyMacDiscoveryProfileMultitenancyTemplate(name, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
),
},
},
})
}

func TestAccDataSourceNsxtPolicyMacDiscoveryProfile_multitenancyProvider(t *testing.T) {
name := getAccTestResourceName()
testResourceName := "data.nsxt_policy_mac_discovery_profile.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccNsxtPolicyMacDiscoveryProfileMultitenancyTemplate(name, false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
Expand All @@ -81,8 +103,11 @@ data "nsxt_policy_mac_discovery_profile" "test" {
}`, name)
}

func testAccNsxtPolicyMacDiscoveryProfileMultitenancyTemplate(name string) string {
context := testAccNsxtPolicyMultitenancyContext()
func testAccNsxtPolicyMacDiscoveryProfileMultitenancyTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
}
return fmt.Sprintf(`
resource "nsxt_policy_mac_discovery_profile" "test" {
%s
Expand Down
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_qos_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func TestAccDataSourceNsxtPolicyQosProfile_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicyQosProfile_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyQosProfileBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicyQosProfileBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_qos_profile.test"
Expand Down
15 changes: 15 additions & 0 deletions nsxt/data_source_nsxt_policy_realization_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ func TestAccDataSourceNsxtPolicyRealizationInfo_tier1DataSource_multitenancy(t *
})
}

func TestAccDataSourceNsxtPolicyRealizationInfo_tier1DataSource_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyRealizationInfoTier1DataSource(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicyRealizationInfoTier1DataSource(t *testing.T, withContext bool, preCheck func()) {
resourceDataType := "nsxt_policy_tier1_gateway"
resourceName := getAccTestDataSourceName()
Expand Down Expand Up @@ -117,6 +124,14 @@ func TestAccDataSourceNsxtPolicyRealizationInfo_tier1Resource_multitenancy(t *te
})
}

func TestAccDataSourceNsxtPolicyRealizationInfo_tier1Resource_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyRealizationInfoTier1Resource(t, false, func() {
testAccPreCheck(t)
testAccNSXVersion(t, "3.0.0")
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicyRealizationInfoTier1Resource(t *testing.T, withContext bool, preCheck func()) {
resourceType := "nsxt_policy_tier1_gateway"
resourceName := getAccTestDataSourceName()
Expand Down
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_security_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func TestAccDataSourceNsxtPolicySecurityPolicy_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicySecurityPolicy_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicySecurityPolicyBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicySecurityPolicyBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
category := "Application"
Expand Down
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_segment_realization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func TestAccDataSourceNsxtPolicySegmentRealization_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicySegmentRealization_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicySegmentRealization(t, false, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccNsxtPolicySegmentRealizationTemplate(vlan, withContext bool) string {
resource := "nsxt_policy_segment"
tz := getOverlayTransportZoneName()
Expand Down
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ func TestAccDataSourceNsxtPolicySegment_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicySegment_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicySegmentBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicySegmentBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_segment.test"
Expand Down
7 changes: 7 additions & 0 deletions nsxt/data_source_nsxt_policy_tier1_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func TestAccDataSourceNsxtPolicyTier1Gateway_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicyTier1Gateway_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyTier1GatewayBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccDataSourceNsxtPolicyTier1GatewayBasic(t *testing.T, withContext bool, preCheck func()) {
routerName := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_tier1_gateway.test"
Expand Down
8 changes: 8 additions & 0 deletions nsxt/data_source_nsxt_policy_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ func TestAccDataSourceNsxtPolicyVM_multitenancy(t *testing.T) {
testAccEnvDefined(t, "NSXT_TEST_VM_NAME")
})
}
func TestAccDataSourceNsxtPolicyVM_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyVMBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
testAccEnvDefined(t, "NSXT_TEST_VM_ID")
testAccEnvDefined(t, "NSXT_TEST_VM_NAME")
})
}
func testAccDataSourceNsxtPolicyVMBasic(t *testing.T, withContext bool, preCheck func()) {
testResourceName := "data.nsxt_policy_vm.test"

Expand Down
10 changes: 9 additions & 1 deletion nsxt/data_source_nsxt_policy_vms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ func TestAccDataSourceNsxtPolicyVMs_basic(t *testing.T) {
}

func TestAccDataSourceNsxtPolicyVMs_multitenancy(t *testing.T) {
testAccDataSourceNsxtPolicyVMsBasic(t, false, func() {
testAccDataSourceNsxtPolicyVMsBasic(t, true, func() {
testAccPreCheck(t)
testAccOnlyMultitenancy(t)
testAccEnvDefined(t, "NSXT_TEST_VM_NAME")
})
}

func TestAccDataSourceNsxtPolicyVMs_multitenancyProvider(t *testing.T) {
testAccDataSourceNsxtPolicyVMsBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
testAccEnvDefined(t, "NSXT_TEST_VM_NAME")
})
}

func testAccDataSourceNsxtPolicyVMsBasic(t *testing.T, withContext bool, preCheck func()) {
testResourceName := "data.nsxt_policy_vms.test"
checkDataSourceName := "data.nsxt_policy_vm.check"
Expand Down
42 changes: 39 additions & 3 deletions nsxt/data_source_policy_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,40 @@ func TestAccDataSourceNsxtPolicyVPC_basic_multitenancy(t *testing.T) {
t.Error(err)
}
},
Config: testAccNsxtPolicyVPCReadTemplate(name),
Config: testAccNsxtPolicyVPCReadTemplate(name, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
resource.TestCheckResourceAttr(testResourceName, "description", name),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
resource.TestCheckResourceAttrSet(testResourceName, "short_id"),
),
},
},
})
}

func TestAccDataSourceNsxtPolicyVPC_basic_multitenancyProvider(t *testing.T) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_vpc.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccOnlyMultitenancyProvider(t)
testAccPreCheck(t)
testAccNSXVersion(t, "4.1.2")
},
Providers: testAccProviders,
CheckDestroy: func(state *terraform.State) error {
return testAccDataSourceNsxtPolicyVPCDeleteByName(name)
},
Steps: []resource.TestStep{
{
PreConfig: func() {
if err := testAccDataSourceNsxtPolicyVPCCreate(name); err != nil {
t.Error(err)
}
},
Config: testAccNsxtPolicyVPCReadTemplate(name, false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
resource.TestCheckResourceAttr(testResourceName, "description", name),
Expand Down Expand Up @@ -113,8 +146,11 @@ func testAccDataSourceNsxtPolicyVPCDeleteByName(name string) error {
return fmt.Errorf("error while deleting VPC '%s': resource not found", name)
}

func testAccNsxtPolicyVPCReadTemplate(name string) string {
context := testAccNsxtPolicyMultitenancyContext()
func testAccNsxtPolicyVPCReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_ip_block" "test" {
%s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func TestAccResourceNsxtPolicyContextProfileCustomAttribute_multitenancy(t *test
})
}

func TestAccResourceNsxtPolicyContextProfileCustomAttribute_multitenancyProvider(t *testing.T) {
testAccResourceNsxtPolicyContextProfileCustomAttributeBasic(t, false, func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
})
}

func testAccResourceNsxtPolicyContextProfileCustomAttributeBasic(t *testing.T, withContext bool, preCheck func()) {
testResourceName := "nsxt_policy_context_profile_custom_attribute.test"

Expand Down
Loading

0 comments on commit ddfeb34

Please sign in to comment.