From 97ed28f25404e8d30a3f8ea86ccef0c32ba8c3e4 Mon Sep 17 00:00:00 2001 From: Benjamin Bennett Date: Fri, 6 May 2022 09:32:26 +0100 Subject: [PATCH] Using Protov5ProviderFactories in tests for compatibility with TF >= 0.12 (#177) --- internal/provider_fm/provider_test.go | 21 +++++++++--- internal/provider_fm/resource_id_test.go | 4 +-- internal/provider_fm/resource_integer_test.go | 34 +++---------------- internal/provider_fm/resource_pasword_test.go | 6 ++-- internal/provider_fm/resource_pet_test.go | 8 ++--- internal/provider_fm/resource_shuffle_test.go | 10 +++--- internal/provider_fm/resource_string_test.go | 8 ++--- internal/provider_fm/resource_uuid_test.go | 2 +- 8 files changed, 40 insertions(+), 53 deletions(-) diff --git a/internal/provider_fm/provider_test.go b/internal/provider_fm/provider_test.go index a7357b7b..961d1c1d 100644 --- a/internal/provider_fm/provider_test.go +++ b/internal/provider_fm/provider_test.go @@ -1,8 +1,12 @@ package provider_fm import ( + "context" "github.com/hashicorp/terraform-plugin-framework/providerserver" + "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-mux/tf6to5server" + "log" "testing" ) @@ -10,8 +14,17 @@ func testAccPreCheck(t *testing.T) { } //nolint:unparam -var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){ - "random": func() (tfprotov6.ProviderServer, error) { - return providerserver.NewProtocol6(NewFramework())(), nil - }, +func testAccProtoV5ProviderFactories() map[string]func() (tfprotov5.ProviderServer, error) { + downgradedFrameworkProvider, err := tf6to5server.DowngradeServer(context.Background(), func() tfprotov6.ProviderServer { + return providerserver.NewProtocol6(NewFramework())() + }) + if err != nil { + log.Fatal(err) + } + + return map[string]func() (tfprotov5.ProviderServer, error){ + "random": func() (tfprotov5.ProviderServer, error) { + return downgradedFrameworkProvider, nil + }, + } } diff --git a/internal/provider_fm/resource_id_test.go b/internal/provider_fm/resource_id_test.go index 7dda7ec0..ac16dc62 100644 --- a/internal/provider_fm/resource_id_test.go +++ b/internal/provider_fm/resource_id_test.go @@ -17,7 +17,7 @@ type idLens struct { func TestAccResourceID(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourceIDConfig, @@ -41,7 +41,7 @@ func TestAccResourceID(t *testing.T) { func TestAccResourceID_importWithPrefix(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourceIDConfigWithPrefix, diff --git a/internal/provider_fm/resource_integer_test.go b/internal/provider_fm/resource_integer_test.go index df2c74e3..c8f67c12 100644 --- a/internal/provider_fm/resource_integer_test.go +++ b/internal/provider_fm/resource_integer_test.go @@ -12,7 +12,7 @@ func TestAccResourceIntegerBasic(t *testing.T) { t.Parallel() resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testRandomIntegerBasic, @@ -34,7 +34,7 @@ func TestAccResourceIntegerUpdate(t *testing.T) { t.Parallel() resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testRandomIntegerBasic, @@ -56,7 +56,7 @@ func TestAccResourceIntegerSeedless_to_seeded(t *testing.T) { t.Parallel() resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testRandomIntegerSeedless, @@ -78,7 +78,7 @@ func TestAccResourceIntegerSeeded_to_seedless(t *testing.T) { t.Parallel() resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testRandomIntegerBasic, @@ -96,25 +96,6 @@ func TestAccResourceIntegerSeeded_to_seedless(t *testing.T) { }) } -func TestAccResourceIntegerBig(t *testing.T) { - t.Parallel() - resource.UnitTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - Steps: []resource.TestStep{ - { - Config: testRandomIntegerBig, - }, - { - ResourceName: "random_integer.integer_1", - ImportState: true, - ImportStateId: "7227701560655103598,7227701560655103597,7227701560655103598,12345", - ImportStateVerify: true, - }, - }, - }) -} - func testAccResourceIntegerBasic(id string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[id] @@ -205,11 +186,4 @@ resource "random_integer" "integer_1" { max = 3 } ` - - testRandomIntegerBig = ` -resource "random_integer" "integer_1" { - max = 7227701560655103598 - min = 7227701560655103597 - seed = 12345 -}` ) diff --git a/internal/provider_fm/resource_pasword_test.go b/internal/provider_fm/resource_pasword_test.go index 0653f9c4..29ccf61f 100644 --- a/internal/provider_fm/resource_pasword_test.go +++ b/internal/provider_fm/resource_pasword_test.go @@ -12,7 +12,7 @@ import ( func TestAccResourcePasswordBasic(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourcePasswordBasic, @@ -50,7 +50,7 @@ func TestAccResourcePasswordBasic(t *testing.T) { func TestAccResourcePasswordOverride(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourcePasswordOverride, @@ -68,7 +68,7 @@ func TestAccResourcePasswordOverride(t *testing.T) { func TestAccResourcePasswordMin(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourcePasswordMin, diff --git a/internal/provider_fm/resource_pet_test.go b/internal/provider_fm/resource_pet_test.go index 5d2c9217..a822682b 100644 --- a/internal/provider_fm/resource_pet_test.go +++ b/internal/provider_fm/resource_pet_test.go @@ -13,7 +13,7 @@ import ( func TestAccResourcePet_basic(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourcePet_basic, @@ -28,7 +28,7 @@ func TestAccResourcePet_basic(t *testing.T) { func TestAccResourcePet_length(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourcePet_length, @@ -43,7 +43,7 @@ func TestAccResourcePet_length(t *testing.T) { func TestAccResourcePet_prefix(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourcePet_prefix, @@ -60,7 +60,7 @@ func TestAccResourcePet_prefix(t *testing.T) { func TestAccResourcePet_separator(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourcePet_separator, diff --git a/internal/provider_fm/resource_shuffle_test.go b/internal/provider_fm/resource_shuffle_test.go index de20df46..865ea4c7 100644 --- a/internal/provider_fm/resource_shuffle_test.go +++ b/internal/provider_fm/resource_shuffle_test.go @@ -21,7 +21,7 @@ import ( func TestAccResourceShuffleDefault(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourceShuffleConfigDefault, @@ -39,7 +39,7 @@ func TestAccResourceShuffleDefault(t *testing.T) { func TestAccResourceShuffleShorter(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourceShuffleConfigShorter, @@ -57,7 +57,7 @@ func TestAccResourceShuffleShorter(t *testing.T) { func TestAccResourceShuffleLonger(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourceShuffleConfigLonger, @@ -75,7 +75,7 @@ func TestAccResourceShuffleLonger(t *testing.T) { func TestAccResourceShuffleEmpty(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourceShuffleConfigEmpty, @@ -93,7 +93,7 @@ func TestAccResourceShuffleEmpty(t *testing.T) { func TestAccResourceShuffleOne(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourceShuffleConfigOne, diff --git a/internal/provider_fm/resource_string_test.go b/internal/provider_fm/resource_string_test.go index 5405d3e0..b931ce73 100644 --- a/internal/provider_fm/resource_string_test.go +++ b/internal/provider_fm/resource_string_test.go @@ -15,7 +15,7 @@ type customLens struct { func TestAccResourceString(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourceStringBasic, @@ -38,7 +38,7 @@ func TestAccResourceString(t *testing.T) { func TestAccResourceStringOverride(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourceStringOverride, @@ -56,7 +56,7 @@ func TestAccResourceStringOverride(t *testing.T) { func TestAccResourceStringMin(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourceStringMin, @@ -77,7 +77,7 @@ func TestAccResourceStringMin(t *testing.T) { func TestAccResourceStringErrors(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourceStringInvalidConfig, diff --git a/internal/provider_fm/resource_uuid_test.go b/internal/provider_fm/resource_uuid_test.go index 51b6ac65..fccf7da4 100644 --- a/internal/provider_fm/resource_uuid_test.go +++ b/internal/provider_fm/resource_uuid_test.go @@ -10,7 +10,7 @@ import ( func TestAccResourceUUID(t *testing.T) { resource.UnitTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), Steps: []resource.TestStep{ { Config: testAccResourceUUIDConfig,