Skip to content

Commit

Permalink
Multitenancy provider tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ksamoray committed Jun 10, 2024
1 parent 1a0b9e0 commit 060577c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
24 changes: 24 additions & 0 deletions nsxt/data_source_nsxt_policy_context_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ func TestAccDataSourceNsxtPolicyContextProfile_multitenancy(t *testing.T) {
})
}

func TestAccDataSourceNsxtPolicyContextProfile_multitenancyProvider(t *testing.T) {
// Use existing system defined profile
name := "AMQP"
testResourceName := "data.nsxt_policy_context_profile.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccOnlyMultitenancyProvider(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccNsxtPolicyContextProfileReadTemplate(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
resource.TestCheckResourceAttrSet(testResourceName, "description"),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
),
},
},
})
}

func testAccNsxtPolicyContextProfileReadTemplate(name string) string {
return fmt.Sprintf(`
data "nsxt_policy_context_profile" "test" {
Expand Down
8 changes: 8 additions & 0 deletions nsxt/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ func handlePagination(lister func(*paginationInfo) error) (int64, error) {
}

func getContextSchema(isRequired, isComputed, isVPC bool) *schema.Schema {
return getContextExtendedSchema(isRequired, isComputed, isVPC, false)
}

func getContextExtendedSchema(isRequired, isComputed, isVPC, isProvider bool) *schema.Schema {
elemSchema := map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Expand All @@ -699,6 +703,10 @@ func getContextSchema(isRequired, isComputed, isVPC bool) *schema.Schema {
ValidateFunc: validation.StringIsNotWhiteSpace,
}
}
if isProvider {
elemSchema["project_id"].DefaultFunc = schema.EnvDefaultFunc("NSXT_PROVIDER_PROJECT_ID", false)
elemSchema["vpc_id"].DefaultFunc = schema.EnvDefaultFunc("NSXT_PROVIDER_VPC_ID", false)
}
return &schema.Schema{
Type: schema.TypeList,
Description: "Resource context",
Expand Down
11 changes: 11 additions & 0 deletions nsxt/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ func testAccIsMultitenancy() bool {
return os.Getenv("NSXT_PROJECT_ID") != ""
}

func testAccIsMultitenancyProvider() bool {
return os.Getenv("NSXT_PROVIDER_PROJECT_ID") != ""
}

func testAccIsVPC() bool {
return os.Getenv("NSXT_VPC_PROJECT_ID") != "" && os.Getenv("NSXT_VPC_ID") != ""
}
Expand Down Expand Up @@ -322,6 +326,13 @@ func testAccOnlyMultitenancy(t *testing.T) {
}
}

func testAccOnlyMultitenancyProvider(t *testing.T) {
testAccNSXVersion(t, "4.1.0")
if !testAccIsMultitenancyProvider() {
t.Skipf("This test requires a multitenancy environment with provider configuration")
}
}

func testAccNSXGlobalManagerSitePrecheck(t *testing.T) {
if testAccIsGlobalManager() && getTestSiteName() == "" {
str := fmt.Sprintf("%s must be set for this acceptance test", "NSXT_TEST_SITE_NAME")
Expand Down

0 comments on commit 060577c

Please sign in to comment.