From 116735cb59583ee88a3ea8557e0ff82900ed8884 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Wed, 4 Dec 2024 01:59:57 +0000 Subject: [PATCH 1/2] fix rp registration resource test --- .../resource_provider_registration_resource_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/services/resource/resource_provider_registration_resource_test.go b/internal/services/resource/resource_provider_registration_resource_test.go index 5944d2aa0c9c..2ca8f858b8da 100644 --- a/internal/services/resource/resource_provider_registration_resource_test.go +++ b/internal/services/resource/resource_provider_registration_resource_test.go @@ -6,6 +6,7 @@ package resource_test import ( "context" "fmt" + "os" "strings" "testing" "time" @@ -46,6 +47,12 @@ func TestAccResourceProviderRegistration_requiresImport(t *testing.T) { r := ResourceProviderRegistrationResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { + PreConfig: func() { + // Last error may cause resource provider still in `Registered` status.Need to unregister it before a new test. + if err := r.unRegisterProviders("Microsoft.AgFoodPlatform"); err != nil { + t.Fatalf("Failed to reset feature registration with error: %+v", err) + } + }, Config: r.basic("Microsoft.AgFoodPlatform"), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), @@ -63,6 +70,8 @@ func TestAccResourceProviderRegistration_feature(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { PreConfig: func() { + _ = os.Setenv("ARM_PROVIDER_ENHANCED_VALIDATION", "false") + // Last error may cause resource provider still in `Registered` status.Need to unregister it before a new test. if err := r.unRegisterProviders("Microsoft.ApiSecurity"); err != nil { t.Fatalf("Failed to reset feature registration with error: %+v", err) From 05aac9b17a4a2c3fd42d8aac8ff0ccbc50bd148f Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Wed, 4 Dec 2024 06:03:23 +0000 Subject: [PATCH 2/2] fix feature registration --- ...rce_provider_registration_resource_test.go | 37 ++++--------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/internal/services/resource/resource_provider_registration_resource_test.go b/internal/services/resource/resource_provider_registration_resource_test.go index 2ca8f858b8da..cc58d386fb3b 100644 --- a/internal/services/resource/resource_provider_registration_resource_test.go +++ b/internal/services/resource/resource_provider_registration_resource_test.go @@ -6,7 +6,6 @@ package resource_test import ( "context" "fmt" - "os" "strings" "testing" "time" @@ -50,7 +49,7 @@ func TestAccResourceProviderRegistration_requiresImport(t *testing.T) { PreConfig: func() { // Last error may cause resource provider still in `Registered` status.Need to unregister it before a new test. if err := r.unRegisterProviders("Microsoft.AgFoodPlatform"); err != nil { - t.Fatalf("Failed to reset feature registration with error: %+v", err) + t.Fatalf("Failed to reset resource provider registration with error: %+v", err) } }, Config: r.basic("Microsoft.AgFoodPlatform"), @@ -70,35 +69,19 @@ func TestAccResourceProviderRegistration_feature(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { PreConfig: func() { - _ = os.Setenv("ARM_PROVIDER_ENHANCED_VALIDATION", "false") - // Last error may cause resource provider still in `Registered` status.Need to unregister it before a new test. - if err := r.unRegisterProviders("Microsoft.ApiSecurity"); err != nil { + if err := r.unRegisterProviders("Microsoft.ManufacturingPlatform"); err != nil { t.Fatalf("Failed to reset feature registration with error: %+v", err) } }, - Config: r.multiFeature(true, true), + Config: r.feature(true), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { - Config: r.multiFeature(true, false), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - data.ImportStep(), - { - Config: r.multiFeature(false, true), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - data.ImportStep(), - { - Config: r.multiFeature(false, false), + Config: r.feature(false), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -207,7 +190,7 @@ func (r ResourceProviderRegistrationResource) unRegisterProvider(client *clients return nil } -func (ResourceProviderRegistrationResource) multiFeature(registered1 bool, registered2 bool) string { +func (ResourceProviderRegistrationResource) feature(registered bool) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -215,15 +198,11 @@ provider "azurerm" { } resource "azurerm_resource_provider_registration" "test" { - name = "Microsoft.ApiSecurity" - feature { - name = "PP2CanaryAccessDEV" - registered = %t - } + name = "Microsoft.ManufacturingPlatform" feature { - name = "PP3CanaryAccessDEV" + name = "DefaultFeature" registered = %t } } -`, registered1, registered2) +`, registered) }