From a08e576cb4647654a79a6623cb9e1f78eedd607e Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Tue, 28 Feb 2023 10:24:46 +0200 Subject: [PATCH] Randomize FQDN Signed-off-by: Kobi Samoray --- ...sxt_policy_context_profile_custom_attribute_test.go | 8 +++++++- nsxt/resource_nsxt_policy_context_profile_test.go | 7 ++++--- nsxt/utils_test.go | 10 ++++++++++ website/docs/r/policy_context_profile.html.markdown | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/nsxt/resource_nsxt_policy_context_profile_custom_attribute_test.go b/nsxt/resource_nsxt_policy_context_profile_custom_attribute_test.go index ad8d9ebf5..f5763f63b 100644 --- a/nsxt/resource_nsxt_policy_context_profile_custom_attribute_test.go +++ b/nsxt/resource_nsxt_policy_context_profile_custom_attribute_test.go @@ -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) } diff --git a/nsxt/resource_nsxt_policy_context_profile_test.go b/nsxt/resource_nsxt_policy_context_profile_test.go index 59df396c3..183c51b02 100644 --- a/nsxt/resource_nsxt_policy_context_profile_test.go +++ b/nsxt/resource_nsxt_policy_context_profile_test.go @@ -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") }, @@ -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), @@ -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), ), }, }, diff --git a/nsxt/utils_test.go b/nsxt/utils_test.go index 869832813..c36f5371e 100644 --- a/nsxt/utils_test.go +++ b/nsxt/utils_test.go @@ -52,6 +52,7 @@ const doubleTags string = ` }` var randomized = false +var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz") func initRand() { if randomized { @@ -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 == "" { diff --git a/website/docs/r/policy_context_profile.html.markdown b/website/docs/r/policy_context_profile.html.markdown index 77d419a9e..5168305de 100644 --- a/website/docs/r/policy_context_profile.html.markdown +++ b/website/docs/r/policy_context_profile.html.markdown @@ -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] } ```