Skip to content

Commit 131fb99

Browse files
committed
Multitenancy provider tests
Signed-off-by: Kobi Samoray <[email protected]>
1 parent 1a0b9e0 commit 131fb99

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

nsxt/data_source_nsxt_policy_context_profile_test.go

+29-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,30 @@ func TestAccDataSourceNsxtPolicyContextProfile_multitenancy(t *testing.T) {
6565
Providers: testAccProviders,
6666
Steps: []resource.TestStep{
6767
{
68-
Config: testAccNsxtPolicyContextProfileMultitenancyTemplate(name),
68+
Config: testAccNsxtPolicyContextProfileMultitenancyTemplate(name, true),
69+
Check: resource.ComposeTestCheckFunc(
70+
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
71+
resource.TestCheckResourceAttrSet(testResourceName, "description"),
72+
resource.TestCheckResourceAttrSet(testResourceName, "path"),
73+
),
74+
},
75+
},
76+
})
77+
}
78+
79+
func TestAccDataSourceNsxtPolicyContextProfile_multitenancyProvider(t *testing.T) {
80+
name := getAccTestResourceName()
81+
testResourceName := "data.nsxt_policy_context_profile.test"
82+
83+
resource.ParallelTest(t, resource.TestCase{
84+
PreCheck: func() {
85+
testAccPreCheck(t)
86+
testAccOnlyMultitenancy(t)
87+
},
88+
Providers: testAccProviders,
89+
Steps: []resource.TestStep{
90+
{
91+
Config: testAccNsxtPolicyContextProfileMultitenancyTemplate(name, false),
6992
Check: resource.ComposeTestCheckFunc(
7093
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
7194
resource.TestCheckResourceAttrSet(testResourceName, "description"),
@@ -83,8 +106,11 @@ data "nsxt_policy_context_profile" "test" {
83106
}`, name)
84107
}
85108

86-
func testAccNsxtPolicyContextProfileMultitenancyTemplate(name string) string {
87-
context := testAccNsxtPolicyMultitenancyContext()
109+
func testAccNsxtPolicyContextProfileMultitenancyTemplate(name string, withContext bool) string {
110+
context := ""
111+
if withContext {
112+
context = testAccNsxtPolicyMultitenancyContext()
113+
}
88114
return fmt.Sprintf(`
89115
resource "nsxt_policy_context_profile" "test" {
90116
%s

nsxt/utils.go

+8
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,10 @@ func handlePagination(lister func(*paginationInfo) error) (int64, error) {
681681
}
682682

683683
func getContextSchema(isRequired, isComputed, isVPC bool) *schema.Schema {
684+
return getContextExtendedSchema(isRequired, isComputed, isVPC, false)
685+
}
686+
687+
func getContextExtendedSchema(isRequired, isComputed, isVPC, isProvider bool) *schema.Schema {
684688
elemSchema := map[string]*schema.Schema{
685689
"project_id": {
686690
Type: schema.TypeString,
@@ -699,6 +703,10 @@ func getContextSchema(isRequired, isComputed, isVPC bool) *schema.Schema {
699703
ValidateFunc: validation.StringIsNotWhiteSpace,
700704
}
701705
}
706+
if isProvider {
707+
elemSchema["project_id"].DefaultFunc = schema.EnvDefaultFunc("NSXT_PROVIDER_PROJECT_ID", false)
708+
elemSchema["vpc_id"].DefaultFunc = schema.EnvDefaultFunc("NSXT_PROVIDER_VPC_ID", false)
709+
}
702710
return &schema.Schema{
703711
Type: schema.TypeList,
704712
Description: "Resource context",

nsxt/utils_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ func testAccIsMultitenancy() bool {
243243
return os.Getenv("NSXT_PROJECT_ID") != ""
244244
}
245245

246+
func testAccIsMultitenancyProvider() bool {
247+
return os.Getenv("NSXT_PROVIDER_PROJECT_ID") != ""
248+
}
249+
246250
func testAccIsVPC() bool {
247251
return os.Getenv("NSXT_VPC_PROJECT_ID") != "" && os.Getenv("NSXT_VPC_ID") != ""
248252
}
@@ -322,6 +326,13 @@ func testAccOnlyMultitenancy(t *testing.T) {
322326
}
323327
}
324328

329+
func testAccOnlyMultitenancyProvider(t *testing.T) {
330+
testAccNSXVersion(t, "4.1.0")
331+
if !testAccIsMultitenancyProvider() {
332+
t.Skipf("This test requires a multitenancy environment with provider configuration")
333+
}
334+
}
335+
325336
func testAccNSXGlobalManagerSitePrecheck(t *testing.T) {
326337
if testAccIsGlobalManager() && getTestSiteName() == "" {
327338
str := fmt.Sprintf("%s must be set for this acceptance test", "NSXT_TEST_SITE_NAME")

0 commit comments

Comments
 (0)