From b6bdeb5382bf04674f3e2bd8a3f960bf3ed7040d Mon Sep 17 00:00:00 2001 From: Alex Luong Date: Tue, 3 Sep 2024 10:26:49 +0700 Subject: [PATCH] regression test --- .../resource_cloudflare_record_test.go | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/internal/sdkv2provider/resource_cloudflare_record_test.go b/internal/sdkv2provider/resource_cloudflare_record_test.go index 7297150291..4893723dea 100644 --- a/internal/sdkv2provider/resource_cloudflare_record_test.go +++ b/internal/sdkv2provider/resource_cloudflare_record_test.go @@ -13,6 +13,7 @@ import ( "github.com/cloudflare/terraform-provider-cloudflare/internal/consts" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/plancheck" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/pkg/errors" "github.com/stretchr/testify/assert" @@ -672,6 +673,35 @@ func TestAccCloudflareRecord_ClearTags(t *testing.T) { }) } +func TestAccCloudflareRecord_CompareIPv6(t *testing.T) { + t.Parallel() + zoneID := os.Getenv("CLOUDFLARE_ZONE_ID") + rnd := generateRandomResourceName() + name := fmt.Sprintf("cloudflare_record.%s", rnd) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: providerFactories, + CheckDestroy: testAccCheckCloudflareRecordDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckCloudflareRecordConfigIPv6(zoneID, rnd, rnd, "2001:4860:4860:0:0:0:0:8888"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(name, "name", rnd), + resource.TestCheckResourceAttr(name, "type", "AAAA"), + resource.TestCheckResourceAttr(name, "content", "2001:4860:4860:0:0:0:0:8888"), + ), + }, + { + Config: testAccCheckCloudflareRecordConfigIPv6(zoneID, rnd, rnd, "2001:4860:4860::8888"), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{plancheck.ExpectEmptyPlan()}, + }, + }, + }, + }) +} + func TestSuppressTrailingDots(t *testing.T) { t.Parallel() @@ -1076,3 +1106,14 @@ func testAccCheckCloudflareRecordDNSKEY(zoneID, name string) string { } `, zoneID, name) } + +func testAccCheckCloudflareRecordConfigIPv6(zoneID, name, rnd, content string) string { + return fmt.Sprintf(` +resource "cloudflare_record" "%[3]s" { + zone_id = "%[1]s" + name = "%[2]s" + content = "%[4]s" + type = "AAAA" + ttl = 3600 +}`, zoneID, name, rnd, content) +}