Revert "make sure all tests are using v2"

This reverts commit 4fdf73549a.
This commit is contained in:
Sarah Sicard 2026-01-05 10:56:41 -06:00
parent 4fdf73549a
commit 07ab4fba00
2 changed files with 9 additions and 156 deletions

View file

@ -58,7 +58,7 @@ resource "cloudflare_managed_headers" "%[1]s" {
Config: v4Config,
},
// Step 2: Run migration and verify state
acctest.MigrationV2TestStep(t, v4Config, tmpDir, "4.52.1", "v4", "v5", []statecheck.StateCheck{
acctest.MigrationTestStep(t, v4Config, tmpDir, "4.52.1", []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("zone_id"), knownvalue.StringExact(zoneID)),
// Verify request headers migrated correctly
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("managed_request_headers"), knownvalue.SetExact([]knownvalue.Check{
@ -118,7 +118,7 @@ resource "cloudflare_managed_headers" "%[1]s" {
Config: v4Config,
},
// Step 2: Run migration and verify state
acctest.MigrationV2TestStep(t, v4Config, tmpDir, "4.52.1", "v4", "v5", []statecheck.StateCheck{
acctest.MigrationTestStep(t, v4Config, tmpDir, "4.52.1", []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("zone_id"), knownvalue.StringExact(zoneID)),
// Verify request headers migrated correctly
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("managed_request_headers"), knownvalue.SetExact([]knownvalue.Check{
@ -169,7 +169,7 @@ resource "cloudflare_managed_headers" "%[1]s" {
Config: v4Config,
},
// Step 2: Run migration and verify state
acctest.MigrationV2TestStep(t, v4Config, tmpDir, "4.52.1", "v4", "v5", []statecheck.StateCheck{
acctest.MigrationTestStep(t, v4Config, tmpDir, "4.52.1", []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("zone_id"), knownvalue.StringExact(zoneID)),
// Verify request headers exists as empty set (required in v5)
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("managed_request_headers"), knownvalue.SetExact([]knownvalue.Check{})),
@ -215,7 +215,7 @@ resource "cloudflare_managed_headers" "%[1]s" {
Config: v4Config,
},
// Step 2: Run migration and verify state
acctest.MigrationV2TestStep(t, v4Config, tmpDir, "4.52.1", "v4", "v5", []statecheck.StateCheck{
acctest.MigrationTestStep(t, v4Config, tmpDir, "4.52.1", []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("zone_id"), knownvalue.StringExact(zoneID)),
// Verify both headers exist as empty sets (required in v5)
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("managed_request_headers"), knownvalue.SetExact([]knownvalue.Check{})),
@ -271,7 +271,7 @@ resource "cloudflare_managed_headers" "%[1]s" {
Config: v4Config,
},
// Step 2: Run migration and verify state
acctest.MigrationV2TestStep(t, v4Config, tmpDir, "4.52.1", "v4", "v5", []statecheck.StateCheck{
acctest.MigrationTestStep(t, v4Config, tmpDir, "4.52.1", []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("zone_id"), knownvalue.StringExact(zoneID)),
// Verify all request headers migrated correctly
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("managed_request_headers"), knownvalue.SetExact([]knownvalue.Check{
@ -353,9 +353,9 @@ func TestMigrateManagedTransformsMultiVersion(t *testing.T) {
steps = append(steps, step1)
// Step 2: Run migration (for v4) or just upgrade provider (for v5)
// MigrationV2TestStep automatically detects v4 vs v5 and only runs migration for v4
// MigrationTestStep automatically detects v4 vs v5 and only runs migration for v4
steps = append(steps,
acctest.MigrationV2TestStep(t, config, tmpDir, tc.version, "v4", "v5", []statecheck.StateCheck{
acctest.MigrationTestStep(t, config, tmpDir, tc.version, []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("zone_id"), knownvalue.StringExact(zoneID)),
// Verify request headers migrated correctly
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("managed_request_headers"), knownvalue.SetExact([]knownvalue.Check{
@ -526,9 +526,9 @@ func TestMigrateManagedTransformsEdgeCases(t *testing.T) {
steps = append(steps, step1)
// Step 2: Run migration (for v4) or just upgrade provider (for v5)
// MigrationV2TestStep automatically detects v4 vs v5 and only runs migration for v4
// MigrationTestStep automatically detects v4 vs v5 and only runs migration for v4
steps = append(steps,
acctest.MigrationV2TestStep(t, config, tmpDir, tc.version, "v4", "v5", expectedChecks),
acctest.MigrationTestStep(t, config, tmpDir, tc.version, expectedChecks),
)
resource.Test(t, resource.TestCase{

View file

@ -1,147 +0,0 @@
package url_normalization_settings_test
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
"github.com/cloudflare/terraform-provider-cloudflare/internal/acctest"
"github.com/cloudflare/terraform-provider-cloudflare/internal/utils"
)
// TestMigrateURLNormalizationSettingsFromV4Basic tests basic migration from v4 to v5
// This is a trivial migration - only schema_version changes from 1 to 0
func TestMigrateURLNormalizationSettingsFromV4Basic(t *testing.T) {
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := utils.GenerateRandomResourceName()
resourceName := "cloudflare_url_normalization_settings." + rnd
tmpDir := t.TempDir()
// V4 config - fields are identical in v4 and v5
v4Config := fmt.Sprintf(`
resource "cloudflare_url_normalization_settings" "%[1]s" {
zone_id = "%[2]s"
type = "cloudflare"
scope = "incoming"
}`, rnd, zoneID)
resource.Test(t, resource.TestCase{
PreCheck: func() {
acctest.TestAccPreCheck(t)
acctest.TestAccPreCheck_ZoneID(t)
},
WorkingDir: tmpDir,
Steps: []resource.TestStep{
{
// Step 1: Create with v4 provider
ExternalProviders: map[string]resource.ExternalProvider{
"cloudflare": {
Source: "cloudflare/cloudflare",
VersionConstraint: "4.52.1",
},
},
Config: v4Config,
},
// Step 2: Run migration and verify state
acctest.MigrationV2TestStep(t, v4Config, tmpDir, "4.52.1", "v4", "v5", []statecheck.StateCheck{
// Verify all fields are preserved correctly
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("zone_id"), knownvalue.StringExact(zoneID)),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("type"), knownvalue.StringExact("cloudflare")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("scope"), knownvalue.StringExact("incoming")),
// Verify computed id field is present
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("id"), knownvalue.NotNull()),
}),
},
})
}
// TestMigrateURLNormalizationSettingsFromV4AllTypeValues tests all type values
func TestMigrateURLNormalizationSettingsFromV4AllTypeValues(t *testing.T) {
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := utils.GenerateRandomResourceName()
resourceName := "cloudflare_url_normalization_settings." + rnd
tmpDir := t.TempDir()
// Test with rfc3986 type
v4Config := fmt.Sprintf(`
resource "cloudflare_url_normalization_settings" "%[1]s" {
zone_id = "%[2]s"
type = "rfc3986"
scope = "both"
}`, rnd, zoneID)
resource.Test(t, resource.TestCase{
PreCheck: func() {
acctest.TestAccPreCheck(t)
acctest.TestAccPreCheck_ZoneID(t)
},
WorkingDir: tmpDir,
Steps: []resource.TestStep{
{
// Step 1: Create with v4 provider
ExternalProviders: map[string]resource.ExternalProvider{
"cloudflare": {
Source: "cloudflare/cloudflare",
VersionConstraint: "4.52.1",
},
},
Config: v4Config,
},
// Step 2: Run migration and verify state
acctest.MigrationV2TestStep(t, v4Config, tmpDir, "4.52.1", "v4", "v5", []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("zone_id"), knownvalue.StringExact(zoneID)),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("type"), knownvalue.StringExact("rfc3986")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("scope"), knownvalue.StringExact("both")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("id"), knownvalue.NotNull()),
}),
},
})
}
// TestMigrateURLNormalizationSettingsFromV4AllScopeValues tests all scope values
func TestMigrateURLNormalizationSettingsFromV4AllScopeValues(t *testing.T) {
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := utils.GenerateRandomResourceName()
resourceName := "cloudflare_url_normalization_settings." + rnd
tmpDir := t.TempDir()
// Test with scope = "none"
v4Config := fmt.Sprintf(`
resource "cloudflare_url_normalization_settings" "%[1]s" {
zone_id = "%[2]s"
type = "cloudflare"
scope = "none"
}`, rnd, zoneID)
resource.Test(t, resource.TestCase{
PreCheck: func() {
acctest.TestAccPreCheck(t)
acctest.TestAccPreCheck_ZoneID(t)
},
WorkingDir: tmpDir,
Steps: []resource.TestStep{
{
// Step 1: Create with v4 provider
ExternalProviders: map[string]resource.ExternalProvider{
"cloudflare": {
Source: "cloudflare/cloudflare",
VersionConstraint: "4.52.1",
},
},
Config: v4Config,
},
// Step 2: Run migration and verify state
acctest.MigrationV2TestStep(t, v4Config, tmpDir, "4.52.1", "v4", "v5", []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("zone_id"), knownvalue.StringExact(zoneID)),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("type"), knownvalue.StringExact("cloudflare")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("scope"), knownvalue.StringExact("none")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("id"), knownvalue.NotNull()),
}),
},
})
}