Skip to content

Commit

Permalink
Randomize FQDN
Browse files Browse the repository at this point in the history
Signed-off-by: Kobi Samoray <[email protected]>
  • Loading branch information
ksamoray committed Feb 28, 2023
1 parent dcd4d14 commit 62b5daf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,15 @@ func testAccNsxtPolicyContextProfileCustomAttributeCheckDestroy(state *terraform
}

func testAccNsxtPolicyContextProfileCustomAttributeTemplate() string {
return testAccNsxtPolicyContextProfileCustomAttributeArgTemplate(
accTestPolicyContextProfileCustomAttributeAttributes["key"],
accTestPolicyContextProfileCustomAttributeAttributes["attribute"])
}

func testAccNsxtPolicyContextProfileCustomAttributeArgTemplate(key string, attribute string) string {
return fmt.Sprintf(`
resource "nsxt_policy_context_profile_custom_attribute" "test" {
key = "%s"
attribute = "%s"
}`, accTestPolicyContextProfileCustomAttributeAttributes["key"], accTestPolicyContextProfileCustomAttributeAttributes["attribute"])
}`, key, attribute)
}
7 changes: 4 additions & 3 deletions nsxt/resource_nsxt_policy_context_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func TestAccResourceNsxtPolicyContextProfile_basic(t *testing.T) {
func TestAccResourceNsxtPolicyContextProfile_CustomDomain(t *testing.T) {
name := getAccTestResourceName()
testResourceName := "nsxt_policy_context_profile.test"
attributes := testAccNsxtPolicyContextProfileAttributeDomainNameTemplate(accTestPolicyContextProfileCustomAttributeAttributes["attribute"])
fqdn := getAccTestFQDN()
attributes := testAccNsxtPolicyContextProfileAttributeDomainNameTemplate(fqdn)
dependsOn := testAccNsxtPolicyContextProfileDependsOnTemplate("nsxt_policy_context_profile_custom_attribute.test")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccNSXVersion(t, "3.0.0") },
Expand All @@ -82,7 +83,7 @@ func TestAccResourceNsxtPolicyContextProfile_CustomDomain(t *testing.T) {
},
Steps: []resource.TestStep{
{
Config: testAccNsxtPolicyContextProfileCustomAttributeTemplate() + testAccNsxtPolicyContextProfileTemplate(name, attributes+dependsOn),
Config: testAccNsxtPolicyContextProfileCustomAttributeArgTemplate(accTestPolicyContextProfileCustomAttributeAttributes["key"], fqdn) + testAccNsxtPolicyContextProfileTemplate(name, attributes+dependsOn),
Check: resource.ComposeTestCheckFunc(
testAccNsxtPolicyContextProfileExists(testResourceName),
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
Expand All @@ -95,7 +96,7 @@ func TestAccResourceNsxtPolicyContextProfile_CustomDomain(t *testing.T) {
resource.TestCheckResourceAttr(testResourceName, "domain_name.#", "1"),
resource.TestCheckResourceAttr(testResourceName, "url_category.#", "0"),
resource.TestCheckResourceAttr(testResourceName, "domain_name.0.value.#", "1"),
resource.TestCheckResourceAttr(testResourceName, "domain_name.0.value.0", accTestPolicyContextProfileCustomAttributeAttributes["attribute"]),
resource.TestCheckResourceAttr(testResourceName, "domain_name.0.value.0", fqdn),
),
},
},
Expand Down
10 changes: 10 additions & 0 deletions nsxt/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const doubleTags string = `
}`

var randomized = false
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz")

func initRand() {
if randomized {
Expand All @@ -71,6 +72,15 @@ func getAccTestResourceName() string {
return fmt.Sprintf("%s-%d", testAccResourceName, rand.Intn(100000))
}

func getAccTestFQDN() string {
initRand()
b := make([]rune, 10)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return fmt.Sprintf("test.%s.org", string(b))
}

func getTier0RouterName() string {
name := os.Getenv("NSXT_TEST_TIER0_ROUTER")
if name == "" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/policy_context_profile.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ resource "nsxt_policy_context_profile" "test2" {
custom_url {
value = ["test.some.org"]
}
depends_on = ["nsxt_policy_context_profile_custom_attribute.test1"]
depends_on = [nsxt_policy_context_profile_custom_attribute.test1]
}
```
Expand Down

0 comments on commit 62b5daf

Please sign in to comment.