Skip to content

Commit

Permalink
Run multitenancy tests in LM setups
Browse files Browse the repository at this point in the history
DO not skip multitenancy tests in LM environments, given that project id is set

Signed-off-by: Kobi Samoray <[email protected]>
  • Loading branch information
ksamoray committed Sep 15, 2024
1 parent 32340df commit ee8d47f
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 175 deletions.
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_dhcp_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func testAccDataSourceNsxtPolicyDhcpServerBasic(t *testing.T, withContext bool,
func testAccNsxtPolicyDhcpServerReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtProjectContext()
}
return fmt.Sprintf(`
resource "nsxt_policy_dhcp_server" "test" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestAccDataSourceNsxtPolicyGatewayLocaleService_multitenancy(t *testing.T)
func testAccNsxtPolicyGatewayLocaleServiceTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtProjectContext()
}
return fmt.Sprintf(`
data "nsxt_policy_edge_cluster" "test" {
Expand Down
19 changes: 12 additions & 7 deletions nsxt/data_source_nsxt_policy_ip_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package nsxt

import (
"fmt"
tf_api "github.com/vmware/terraform-provider-nsxt/api/utl"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -31,17 +32,21 @@ func TestAccDataSourceNsxtPolicyIpPool_multitenancy(t *testing.T) {
func testAccDataSourceNsxtPolicyIPPoolBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_ip_pool.test"
var clientType tf_api.ClientType = tf_api.Local
if withContext {
clientType = tf_api.Multitenancy
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: preCheck,
Providers: testAccProviders,
CheckDestroy: func(state *terraform.State) error {
return testAccDataSourceNsxtPolicyIPPoolDeleteByName(name)
return testAccDataSourceNsxtPolicyIPPoolDeleteByName(name, clientType)
},
Steps: []resource.TestStep{
{
PreConfig: func() {
if err := testAccDataSourceNsxtPolicyIPPoolCreate(name); err != nil {
if err := testAccDataSourceNsxtPolicyIPPoolCreate(name, clientType); err != nil {
t.Error(err)
}
},
Expand All @@ -57,12 +62,12 @@ func testAccDataSourceNsxtPolicyIPPoolBasic(t *testing.T, withContext bool, preC
})
}

func testAccDataSourceNsxtPolicyIPPoolCreate(name string) error {
func testAccDataSourceNsxtPolicyIPPoolCreate(name string, clientType tf_api.ClientType) error {
connector, err := testAccGetPolicyConnector()
if err != nil {
return fmt.Errorf("Error during test client initialization: %v", err)
}
client := infra.NewIpPoolsClient(testAccGetSessionContext(), connector)
client := infra.NewIpPoolsClient(testAccGetContextByType(clientType), connector)
if client == nil {
return policyResourceNotSupportedError()
}
Expand All @@ -84,12 +89,12 @@ func testAccDataSourceNsxtPolicyIPPoolCreate(name string) error {
return nil
}

func testAccDataSourceNsxtPolicyIPPoolDeleteByName(name string) error {
func testAccDataSourceNsxtPolicyIPPoolDeleteByName(name string, clientType tf_api.ClientType) error {
connector, err := testAccGetPolicyConnector()
if err != nil {
return fmt.Errorf("Error during test client initialization: %v", err)
}
client := infra.NewIpPoolsClient(testAccGetSessionContext(), connector)
client := infra.NewIpPoolsClient(testAccGetContextByType(clientType), connector)
if client == nil {
return policyResourceNotSupportedError()
}
Expand All @@ -114,7 +119,7 @@ func testAccDataSourceNsxtPolicyIPPoolDeleteByName(name string) error {
func testAccNsxtPolicyIPPoolReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtProjectContext()
}
return fmt.Sprintf(`
data "nsxt_policy_ip_pool" "test" {
Expand Down
19 changes: 12 additions & 7 deletions nsxt/data_source_nsxt_policy_ipv6_dad_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package nsxt

import (
"fmt"
tf_api "github.com/vmware/terraform-provider-nsxt/api/utl"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -30,17 +31,21 @@ func TestAccDataSourceNsxtPolicyIpv6DadProfile_multitenancy(t *testing.T) {
func testAccDataSourceNsxtPolicyIpv6DadProfileBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_ipv6_dad_profile.test"
var clientType tf_api.ClientType = tf_api.Local
if withContext {
clientType = tf_api.Multitenancy
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: preCheck,
Providers: testAccProviders,
CheckDestroy: func(state *terraform.State) error {
return testAccDataSourceNsxtPolicyIpv6DadProfileDeleteByName(name)
return testAccDataSourceNsxtPolicyIpv6DadProfileDeleteByName(name, clientType)
},
Steps: []resource.TestStep{
{
PreConfig: func() {
if err := testAccDataSourceNsxtPolicyIpv6DadProfileCreate(name); err != nil {
if err := testAccDataSourceNsxtPolicyIpv6DadProfileCreate(name, clientType); err != nil {
t.Error(err)
}
},
Expand All @@ -55,7 +60,7 @@ func testAccDataSourceNsxtPolicyIpv6DadProfileBasic(t *testing.T, withContext bo
})
}

func testAccDataSourceNsxtPolicyIpv6DadProfileCreate(name string) error {
func testAccDataSourceNsxtPolicyIpv6DadProfileCreate(name string, clientType tf_api.ClientType) error {
connector, err := testAccGetPolicyConnector()
if err != nil {
return fmt.Errorf("Error during test client initialization: %v", err)
Expand All @@ -70,7 +75,7 @@ func testAccDataSourceNsxtPolicyIpv6DadProfileCreate(name string) error {

// Generate a random ID for the resource
id := newUUID()
client := infra.NewIpv6DadProfilesClient(testAccGetSessionContext(), connector)
client := infra.NewIpv6DadProfilesClient(testAccGetContextByType(clientType), connector)
if client == nil {
return policyResourceNotSupportedError()
}
Expand All @@ -82,13 +87,13 @@ func testAccDataSourceNsxtPolicyIpv6DadProfileCreate(name string) error {
return nil
}

func testAccDataSourceNsxtPolicyIpv6DadProfileDeleteByName(name string) error {
func testAccDataSourceNsxtPolicyIpv6DadProfileDeleteByName(name string, clientType tf_api.ClientType) error {
connector, err := testAccGetPolicyConnector()
if err != nil {
return fmt.Errorf("Error during test client initialization: %v", err)
}
// Find the object by name and delete it
client := infra.NewIpv6DadProfilesClient(testAccGetSessionContext(), connector)
client := infra.NewIpv6DadProfilesClient(testAccGetContextByType(clientType), connector)
if client == nil {
return policyResourceNotSupportedError()
}
Expand All @@ -113,7 +118,7 @@ func testAccDataSourceNsxtPolicyIpv6DadProfileDeleteByName(name string) error {
func testAccNsxtPolicyIpv6DadProfileReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtProjectContext()
}
return fmt.Sprintf(`
data "nsxt_policy_ipv6_dad_profile" "test" {
Expand Down
17 changes: 11 additions & 6 deletions nsxt/data_source_nsxt_policy_ipv6_ndra_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package nsxt

import (
"fmt"
tf_api "github.com/vmware/terraform-provider-nsxt/api/utl"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -30,17 +31,21 @@ func TestAccDataSourceNsxtPolicyIpv6NdraProfile_multitenancy(t *testing.T) {
func testAccDataSourceNsxtPolicyIpv6NdraProfileBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_ipv6_ndra_profile.test"
var clientType tf_api.ClientType = tf_api.Local
if withContext {
clientType = tf_api.Multitenancy
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: preCheck,
Providers: testAccProviders,
CheckDestroy: func(state *terraform.State) error {
return testAccDataSourceNsxtPolicyIpv6NdraProfileDeleteByName(name)
return testAccDataSourceNsxtPolicyIpv6NdraProfileDeleteByName(name, clientType)
},
Steps: []resource.TestStep{
{
PreConfig: func() {
if err := testAccDataSourceNsxtPolicyIpv6NdraProfileCreate(name); err != nil {
if err := testAccDataSourceNsxtPolicyIpv6NdraProfileCreate(name, clientType); err != nil {
t.Error(err)
}
},
Expand All @@ -55,7 +60,7 @@ func testAccDataSourceNsxtPolicyIpv6NdraProfileBasic(t *testing.T, withContext b
})
}

func testAccDataSourceNsxtPolicyIpv6NdraProfileCreate(name string) error {
func testAccDataSourceNsxtPolicyIpv6NdraProfileCreate(name string, clientType tf_api.ClientType) error {
connector, err := testAccGetPolicyConnector()
if err != nil {
return fmt.Errorf("Error during test client initialization: %v", err)
Expand All @@ -75,7 +80,7 @@ func testAccDataSourceNsxtPolicyIpv6NdraProfileCreate(name string) error {
// Generate a random ID for the resource
id := newUUID()

client := infra.NewIpv6NdraProfilesClient(testAccGetSessionContext(), connector)
client := infra.NewIpv6NdraProfilesClient(testAccGetContextByType(clientType), connector)
if client == nil {
return policyResourceNotSupportedError()
}
Expand All @@ -86,13 +91,13 @@ func testAccDataSourceNsxtPolicyIpv6NdraProfileCreate(name string) error {
return nil
}

func testAccDataSourceNsxtPolicyIpv6NdraProfileDeleteByName(name string) error {
func testAccDataSourceNsxtPolicyIpv6NdraProfileDeleteByName(name string, clientType tf_api.ClientType) error {
connector, err := testAccGetPolicyConnector()
if err != nil {
return fmt.Errorf("Error during test client initialization: %v", err)
}
// Find the object by name and delete it
client := infra.NewIpv6NdraProfilesClient(testAccGetSessionContext(), connector)
client := infra.NewIpv6NdraProfilesClient(testAccGetContextByType(clientType), connector)
if client == nil {
return policyResourceNotSupportedError()
}
Expand Down
19 changes: 12 additions & 7 deletions nsxt/data_source_nsxt_policy_qos_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package nsxt

import (
"fmt"
tf_api "github.com/vmware/terraform-provider-nsxt/api/utl"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -30,17 +31,21 @@ func TestAccDataSourceNsxtPolicyQosProfile_multitenancy(t *testing.T) {
func testAccDataSourceNsxtPolicyQosProfileBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_qos_profile.test"
var clientType tf_api.ClientType = tf_api.Local
if withContext {
clientType = tf_api.Multitenancy
}

resource.Test(t, resource.TestCase{
PreCheck: preCheck,
Providers: testAccProviders,
CheckDestroy: func(state *terraform.State) error {
return testAccDataSourceNsxtPolicyQosProfileDeleteByName(name)
return testAccDataSourceNsxtPolicyQosProfileDeleteByName(name, clientType)
},
Steps: []resource.TestStep{
{
PreConfig: func() {
if err := testAccDataSourceNsxtPolicyQosProfileCreate(name); err != nil {
if err := testAccDataSourceNsxtPolicyQosProfileCreate(name, clientType); err != nil {
t.Error(err)
}
},
Expand All @@ -55,7 +60,7 @@ func testAccDataSourceNsxtPolicyQosProfileBasic(t *testing.T, withContext bool,
})
}

func testAccDataSourceNsxtPolicyQosProfileCreate(name string) error {
func testAccDataSourceNsxtPolicyQosProfileCreate(name string, clientType tf_api.ClientType) error {
connector, err := testAccGetPolicyConnector()
if err != nil {
return fmt.Errorf("Error during test client initialization: %v", err)
Expand All @@ -71,7 +76,7 @@ func testAccDataSourceNsxtPolicyQosProfileCreate(name string) error {
// Generate a random ID for the resource
id := newUUID()

client := infra.NewQosProfilesClient(testAccGetSessionContext(), connector)
client := infra.NewQosProfilesClient(testAccGetContextByType(clientType), connector)
if client == nil {
return policyResourceNotSupportedError()
}
Expand All @@ -83,14 +88,14 @@ func testAccDataSourceNsxtPolicyQosProfileCreate(name string) error {
return nil
}

func testAccDataSourceNsxtPolicyQosProfileDeleteByName(name string) error {
func testAccDataSourceNsxtPolicyQosProfileDeleteByName(name string, clientType tf_api.ClientType) error {
connector, err := testAccGetPolicyConnector()
if err != nil {
return fmt.Errorf("Error during test client initialization: %v", err)
}

// Find the object by name and delete it
client := infra.NewQosProfilesClient(testAccGetSessionContext(), connector)
client := infra.NewQosProfilesClient(testAccGetContextByType(clientType), connector)
if client == nil {
return policyResourceNotSupportedError()
}
Expand All @@ -113,7 +118,7 @@ func testAccDataSourceNsxtPolicyQosProfileDeleteByName(name string) error {
func testAccNsxtPolicyQosProfileReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtProjectContext()
}
return fmt.Sprintf(`
data "nsxt_policy_qos_profile" "test" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ data "nsxt_policy_segment_security_profile" "test" {
}

func testAccNsxtPolicySegmentSecurityProfileMultitenancyTemplate(name string) string {
context := testAccNsxtPolicyMultitenancyContext()
context := testAccNsxtProjectContext()
return fmt.Sprintf(`
resource "nsxt_policy_segment_security_profile" "test" {
%s
Expand Down
Loading

0 comments on commit ee8d47f

Please sign in to comment.