From d49c584ce371f8052d923fdd4799d78dfe461a6a Mon Sep 17 00:00:00 2001 From: Heather Lanigan Date: Tue, 24 Oct 2023 15:30:48 -0400 Subject: [PATCH] Update ACC tests, framework migration complete. Convert one Stable test per entity to an UpgradeProvider test. No longer need other Stable tests. This will improve our testing and reduce test time. Change the released version of tf for testing to most recent, 0.9.1. --- internal/provider/data_source_offer_test.go | 22 ++- internal/provider/provider_test.go | 2 +- .../provider/resource_access_model_test.go | 40 ++-- .../provider/resource_application_test.go | 185 ++---------------- internal/provider/resource_credential_test.go | 49 ++--- .../provider/resource_integration_test.go | 68 ++----- internal/provider/resource_machine_test.go | 23 +-- internal/provider/resource_model_test.go | 93 ++------- internal/provider/resource_offer_test.go | 23 +-- internal/provider/resource_ssh_key_test.go | 53 ++--- internal/provider/resource_user_test.go | 24 ++- 11 files changed, 131 insertions(+), 451 deletions(-) diff --git a/internal/provider/data_source_offer_test.go b/internal/provider/data_source_offer_test.go index 5bac9598..700713e9 100644 --- a/internal/provider/data_source_offer_test.go +++ b/internal/provider/data_source_offer_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) -func TestAcc_DataSourceOffer_Edge(t *testing.T) { +func TestAcc_DataSourceOffer(t *testing.T) { modelName := acctest.RandomWithPrefix("tf-datasource-offer-test-model") // ...-test-[0-9]+ is not a valid offer name, need to remove the dash before numbers offerName := fmt.Sprintf("tf-datasource-offer-test%d", acctest.RandInt()) @@ -31,27 +31,33 @@ func TestAcc_DataSourceOffer_Edge(t *testing.T) { }) } -func TestAcc_DataSourceOffer_Stable(t *testing.T) { +func TestAcc_DataSourceOffer_UpgradeProvider(t *testing.T) { modelName := acctest.RandomWithPrefix("tf-datasource-offer-test-model") // ...-test-[0-9]+ is not a valid offer name, need to remove the dash before numbers offerName := fmt.Sprintf("tf-datasource-offer-test%d", acctest.RandInt()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, + Steps: []resource.TestStep{ { + ExternalProviders: map[string]resource.ExternalProvider{ + "juju": { + VersionConstraint: TestProviderStableVersion, + Source: "juju/juju", + }, + }, Config: testAccDataSourceOffer(modelName, "series = \"jammy\"", offerName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.juju_offer.this", "model", modelName), resource.TestCheckResourceAttr("data.juju_offer.this", "name", offerName), ), }, + { + ProtoV6ProviderFactories: frameworkProviderFactories, + Config: testAccDataSourceOffer(modelName, "series = \"jammy\"", offerName), + PlanOnly: true, + }, }, }) } diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index bbed83e1..b59e3bbc 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -21,7 +21,7 @@ import ( "github.com/juju/terraform-provider-juju/internal/juju" ) -const TestProviderStableVersion = "0.8.0" +const TestProviderStableVersion = "0.9.1" // providerFactories are used to instantiate the Framework provider during // acceptance testing. diff --git a/internal/provider/resource_access_model_test.go b/internal/provider/resource_access_model_test.go index a2f07d89..57e9fc07 100644 --- a/internal/provider/resource_access_model_test.go +++ b/internal/provider/resource_access_model_test.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) -func TestAcc_ResourceAccessModel_Edge(t *testing.T) { +func TestAcc_ResourceAccessModel(t *testing.T) { userName := acctest.RandomWithPrefix("tfuser") userPassword := acctest.RandomWithPrefix("tf-test-user") userName2 := acctest.RandomWithPrefix("tfuser") @@ -66,33 +66,27 @@ func TestAcc_ResourceAccessModel_Edge(t *testing.T) { }) } -func TestAcc_ResourceAccessModel_Stable(t *testing.T) { +func TestAcc_ResourceAccessModel_UpgradeProvider(t *testing.T) { + if testingCloud != LXDCloudTesting { + t.Skip(t.Name() + " only runs with LXD") + } + userName := acctest.RandomWithPrefix("tfuser") userPassword := acctest.RandomWithPrefix("tf-test-user") modelName := "testing" access := "write" - accessFail := "bogus" resourceName := "juju_access_model.test" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, + Steps: []resource.TestStep{ { - Config: testAccResourceAccessModel(userName, userPassword, modelName, accessFail), - ExpectError: regexp.MustCompile("Error running pre-apply refresh.*"), - }, - { - // (juanmanuel-tirado) For some reason beyond my understanding, - // this test fails no microk8s on GitHub. If passes in local - // environments with no additional configurations... - SkipFunc: func() (bool, error) { - return testingCloud != LXDCloudTesting, nil + ExternalProviders: map[string]resource.ExternalProvider{ + "juju": { + VersionConstraint: TestProviderStableVersion, + Source: "juju/juju", + }, }, Config: testAccResourceAccessModel(userName, userPassword, modelName, access), Check: resource.ComposeTestCheckFunc( @@ -102,13 +96,9 @@ func TestAcc_ResourceAccessModel_Stable(t *testing.T) { ), }, { - SkipFunc: func() (bool, error) { - return testingCloud != LXDCloudTesting, nil - }, - ImportStateVerify: true, - ImportState: true, - ImportStateId: fmt.Sprintf("%s:%s:%s", modelName, access, userName), - ResourceName: resourceName, + ProtoV6ProviderFactories: frameworkProviderFactories, + Config: testAccResourceAccessModel(userName, userPassword, modelName, access), + PlanOnly: true, }, }, }) diff --git a/internal/provider/resource_application_test.go b/internal/provider/resource_application_test.go index 0e388a77..1f18e897 100644 --- a/internal/provider/resource_application_test.go +++ b/internal/provider/resource_application_test.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) -func TestAcc_ResourceApplication_Edge(t *testing.T) { +func TestAcc_ResourceApplication(t *testing.T) { modelName := acctest.RandomWithPrefix("tf-test-application") appName := "test-app" appInvalidName := "test_app" @@ -110,7 +110,7 @@ func TestAcc_ResourceApplication_Edge(t *testing.T) { }) } -func TestAcc_ResourceApplication_Updates_Edge(t *testing.T) { +func TestAcc_ResourceApplication_Updates(t *testing.T) { modelName := acctest.RandomWithPrefix("tf-test-application") appName := "jameinel-ubuntu-lite" if testingCloud != LXDCloudTesting { @@ -171,7 +171,7 @@ func TestAcc_ResourceApplication_Updates_Edge(t *testing.T) { }) } -func TestAcc_CharmUpdates_Edge(t *testing.T) { +func TestAcc_CharmUpdates(t *testing.T) { modelName := acctest.RandomWithPrefix("tf-test-charmupdates") resource.Test(t, resource.TestCase{ @@ -233,28 +233,21 @@ func TestAcc_ResourceApplication_Minimal(t *testing.T) { }) } -func TestAcc_ResourceApplication_Stable(t *testing.T) { +func TestAcc_ResourceApplication_UpgradeProvider(t *testing.T) { modelName := acctest.RandomWithPrefix("tf-test-application") appName := "test-app" - appInvalidName := "test_app" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, + Steps: []resource.TestStep{ { - // Mind that ExpectError should be the first step - // "When tests have an ExpectError[...]; this results in any previous state being cleared. " - // https://github.com/hashicorp/terraform-plugin-sdk/issues/118 - Config: testAccResourceApplicationBasic(modelName, appInvalidName), - ExpectError: regexp.MustCompile(fmt.Sprintf("Error: invalid application name \"%s\", unexpected character _", appInvalidName)), - }, - { + ExternalProviders: map[string]resource.ExternalProvider{ + "juju": { + VersionConstraint: TestProviderStableVersion, + Source: "juju/juju", + }, + }, Config: testAccResourceApplicationBasic(modelName, appName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("juju_application.this", "model", modelName), @@ -266,159 +259,9 @@ func TestAcc_ResourceApplication_Stable(t *testing.T) { ), }, { - SkipFunc: func() (bool, error) { - // cores constraint is not valid in K8s - return testingCloud != LXDCloudTesting, nil - }, - Config: testAccResourceApplicationConstraints(modelName, "arch=amd64 cores=1 mem=4096M"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("juju_application.this", "model", modelName), - resource.TestCheckResourceAttr("juju_application.this", "constraints", "arch=amd64 cores=1 mem=4096M"), - ), - }, - { - // specific constraints for k8s - SkipFunc: func() (bool, error) { - return testingCloud != MicroK8sTesting, nil - }, - Config: testAccResourceApplicationConstraints(modelName, "arch=amd64 mem=4096M"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("juju_application.this", "model", modelName), - resource.TestCheckResourceAttr("juju_application.this", "constraints", "arch=amd64 mem=4096M"), - ), - }, - { - SkipFunc: func() (bool, error) { - // skip if we are not in lxd environment - return testingCloud != LXDCloudTesting, nil - }, - Config: testAccResourceApplicationConstraintsSubordinate(modelName, "arch=amd64 cores=1 mem=4096M"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("juju_application.this", "model", modelName), - resource.TestCheckResourceAttr("juju_application.this", "constraints", "arch=amd64 cores=1 mem=4096M"), - ), - }, - { - ImportStateVerify: true, - ImportState: true, - ResourceName: "juju_application.this", - }, - }, - }) -} - -func TestAcc_ResourceApplication_Updates_Stable(t *testing.T) { - modelName := acctest.RandomWithPrefix("tf-test-application") - appName := "jameinel-ubuntu-lite" - if testingCloud != LXDCloudTesting { - appName = "hello-kubecon" - } - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, - Steps: []resource.TestStep{ - { - Config: testAccResourceApplicationUpdates(modelName, 1, true, "machinename"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("juju_application.this", "model", modelName), - resource.TestCheckResourceAttr("juju_application.this", "charm.#", "1"), - resource.TestCheckResourceAttr("juju_application.this", "charm.0.name", appName), - resource.TestCheckResourceAttr("juju_application.this", "units", "1"), - resource.TestCheckResourceAttr("juju_application.this", "expose.#", "1"), - // (juanmanuel-tirado) Uncomment and test when running - // a different charm with other config - //resource.TestCheckResourceAttr("juju_application.this", "config.hostname", "machinename"), - ), - }, - { - SkipFunc: func() (bool, error) { - return testingCloud != LXDCloudTesting, nil - }, - Config: testAccResourceApplicationUpdates(modelName, 2, true, "machinename"), - Check: resource.TestCheckResourceAttr("juju_application.this", "units", "2"), - }, - { - SkipFunc: func() (bool, error) { - return testingCloud != LXDCloudTesting, nil - }, - Config: testAccResourceApplicationUpdates(modelName, 2, true, "machinename"), - Check: resource.TestCheckResourceAttr("juju_application.this", "charm.0.revision", "10"), - }, - { - SkipFunc: func() (bool, error) { - return testingCloud != MicroK8sTesting, nil - }, - Config: testAccResourceApplicationUpdates(modelName, 2, true, "machinename"), - Check: resource.TestCheckResourceAttr("juju_application.this", "charm.0.revision", "19"), - }, - { - Config: testAccResourceApplicationUpdates(modelName, 2, false, "machinename"), - Check: resource.TestCheckResourceAttr("juju_application.this", "expose.#", "0"), - }, - { - Config: testAccResourceApplicationUpdates(modelName, 2, true, "machinename"), - Check: resource.TestCheckResourceAttr("juju_application.this", "expose.#", "1"), - }, - { - SkipFunc: func() (bool, error) { - // This test is broken in a released version of the juju - // provider, 0.8.0, but not in the version under development - // === RUN TestAcc_ResourceApplication_Updates_Stable - // resource_application_test.go:485: Skipping step 2/7 due to SkipFunc - // resource_application_test.go:485: Skipping step 3/7 due to SkipFunc - // resource_application_test.go:485: Step 7/7 error running import: ImportStateVerify attributes not equivalent. Difference is shown below. The - symbol indicates attributes missing after import. - // - // map[string]string{ - // "placement": "", - // "placement": ",", - // } - //--- FAIL: TestAcc_ResourceApplication_Updates_Stable (25.87s) - return testingCloud != MicroK8sTesting && TestProviderStableVersion == "0.8.0", nil - }, - ImportStateVerify: true, - ImportState: true, - ResourceName: "juju_application.this", - }, - }, - }) -} - -func TestAcc_CharmUpdates_Stable(t *testing.T) { - modelName := acctest.RandomWithPrefix("tf-test-charmupdates") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, - Steps: []resource.TestStep{ - { - Config: testAccResourceApplicationUpdatesCharm(modelName, "latest/stable"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("juju_application.this", "charm.0.channel", "latest/stable"), - ), - }, - { - // move to latest/edge - Config: testAccResourceApplicationUpdatesCharm(modelName, "latest/edge"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("juju_application.this", "charm.0.channel", "latest/edge"), - ), - }, - { - // move back to latest/stable - Config: testAccResourceApplicationUpdatesCharm(modelName, "latest/stable"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("juju_application.this", "charm.0.channel", "latest/stable"), - ), + ProtoV6ProviderFactories: frameworkProviderFactories, + Config: testAccResourceApplicationBasic(modelName, appName), + PlanOnly: true, }, }, }) diff --git a/internal/provider/resource_credential_test.go b/internal/provider/resource_credential_test.go index a978e42c..3cbd34cc 100644 --- a/internal/provider/resource_credential_test.go +++ b/internal/provider/resource_credential_test.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) -func TestAcc_ResourceCredential_Edge(t *testing.T) { +func TestAcc_ResourceCredential(t *testing.T) { if testingCloud != LXDCloudTesting { t.Skip(t.Name() + " only runs with LXD") } @@ -69,38 +69,25 @@ func TestAcc_ResourceCredential_Edge(t *testing.T) { }) } -func TestAcc_ResourceCredential_Stable(t *testing.T) { +func TestAcc_ResourceCredential_UpgradeProvider(t *testing.T) { if testingCloud != LXDCloudTesting { t.Skip(t.Name() + " only runs with LXD") } credentialName := acctest.RandomWithPrefix("tf-test-credential") - credentialInvalidName := "tf%test_credential" authType := "certificate" - authTypeInvalid := "invalid" - token := "123abc" resourceName := "juju_credential.test-credential" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, + Steps: []resource.TestStep{ { - // Mind that ExpectError should be the first step - // "When tests have an ExpectError[...]; this results in any previous state being cleared. " - // https://github.com/hashicorp/terraform-plugin-sdk/issues/118 - Config: testAccResourceCredential(credentialName, authTypeInvalid), - ExpectError: regexp.MustCompile(fmt.Sprintf("Error: supported auth-types (.*), \"%s\" not supported", authTypeInvalid)), - }, - { - Config: testAccResourceCredential(credentialInvalidName, authType), - ExpectError: regexp.MustCompile(fmt.Sprintf("Error: \"%s\" is not a valid credential name", credentialInvalidName)), - }, - { + ExternalProviders: map[string]resource.ExternalProvider{ + "juju": { + VersionConstraint: TestProviderStableVersion, + Source: "juju/juju", + }, + }, Config: testAccResourceCredential(credentialName, authType), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "name", credentialName), @@ -108,21 +95,9 @@ func TestAcc_ResourceCredential_Stable(t *testing.T) { ), }, { - Config: testAccResourceCredentialToken(credentialName, authType, token), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", credentialName), - resource.TestCheckResourceAttr(resourceName, "auth_type", authType), - resource.TestCheckResourceAttr(resourceName, "attributes.token", token), - ), - }, - { - ImportStateVerify: true, - ImportState: true, - ImportStateVerifyIgnore: []string{ - "attributes.%", - "attributes.token"}, - ImportStateId: fmt.Sprintf("%s:localhost:false:true", credentialName), - ResourceName: resourceName, + ProtoV6ProviderFactories: frameworkProviderFactories, + Config: testAccResourceCredential(credentialName, authType), + PlanOnly: true, }, }, }) diff --git a/internal/provider/resource_integration_test.go b/internal/provider/resource_integration_test.go index 7247611a..935f021b 100644 --- a/internal/provider/resource_integration_test.go +++ b/internal/provider/resource_integration_test.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" ) -func TestAcc_ResourceIntegration_Edge(t *testing.T) { +func TestAcc_ResourceIntegration(t *testing.T) { if testingCloud != LXDCloudTesting { t.Skip(t.Name() + " only runs with LXD") } @@ -50,7 +50,7 @@ func TestAcc_ResourceIntegration_Edge(t *testing.T) { }) } -func TestAcc_ResourceIntegrationWithViaCIDRs_Edge(t *testing.T) { +func TestAcc_ResourceIntegrationWithViaCIDRs(t *testing.T) { if testingCloud != LXDCloudTesting { t.Skip(t.Name() + " only runs with LXD") } @@ -77,23 +77,23 @@ func TestAcc_ResourceIntegrationWithViaCIDRs_Edge(t *testing.T) { }) } -func TestAcc_ResourceIntegration_Stable(t *testing.T) { +func TestAcc_ResourceIntegration_UpgradeProvider(t *testing.T) { if testingCloud != LXDCloudTesting { t.Skip(t.Name() + " only runs with LXD") } modelName := acctest.RandomWithPrefix("tf-test-integration") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, + PreCheck: func() { testAccPreCheck(t) }, CheckDestroy: testAccCheckIntegrationDestroy, Steps: []resource.TestStep{ { + ExternalProviders: map[string]resource.ExternalProvider{ + "juju": { + VersionConstraint: TestProviderStableVersion, + Source: "juju/juju", + }, + }, Config: testAccResourceIntegration(modelName, "series = \"jammy\"", "series = \"jammy\""), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("juju_integration.this", "model", modelName), @@ -103,17 +103,9 @@ func TestAcc_ResourceIntegration_Stable(t *testing.T) { ), }, { - ImportStateVerify: true, - ImportState: true, - ResourceName: "juju_integration.this", - }, - { - Config: testAccResourceIntegration(modelName, "series = \"jammy\"", "series = \"jammy\""), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("juju_integration.this", "model", modelName), - resource.TestCheckResourceAttr("juju_integration.this", "id", fmt.Sprintf("%v:%v:%v", modelName, "one:source", "two:sink")), - resource.TestCheckResourceAttr("juju_integration.this", "application.#", "2"), - ), + ProtoV6ProviderFactories: frameworkProviderFactories, + Config: testAccResourceIntegration(modelName, "series = \"jammy\"", "series = \"jammy\""), + PlanOnly: true, }, }, }) @@ -165,38 +157,6 @@ resource "juju_integration" "this" { `, modelName, osOne, osTwo) } -func TestAcc_ResourceIntegrationWithViaCIDRs_Stable(t *testing.T) { - if testingCloud != LXDCloudTesting { - t.Skip(t.Name() + " only runs with LXD") - } - srcModelName := acctest.RandomWithPrefix("tf-test-integration") - dstModelName := acctest.RandomWithPrefix("tf-test-integration-dst") - via := "127.0.0.1/32,127.0.0.3/32" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, - CheckDestroy: testAccCheckIntegrationDestroy, - Steps: []resource.TestStep{ - { - Config: testAccResourceIntegrationWithVia(srcModelName, "series = \"jammy\"", dstModelName, "series = \"jammy\"", via), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("juju_integration.a", "model", srcModelName), - resource.TestCheckResourceAttr("juju_integration.a", "id", fmt.Sprintf("%v:%v:%v", srcModelName, "a:source", "b:sink")), - resource.TestCheckResourceAttr("juju_integration.a", "application.#", "2"), - resource.TestCheckTypeSetElemNestedAttrs("juju_integration.a", "application.*", map[string]string{"name": "a", "endpoint": "source"}), - resource.TestCheckResourceAttr("juju_integration.a", "via", via), - ), - }, - }, - }) -} - // testAccResourceIntegrationWithVia generates a plan where a // postgresql:source relates to a pgbouncer:backend-source using // and offer of pgbouncer. @@ -252,7 +212,7 @@ resource "juju_integration" "a" { `, srcModelName, aOS, dstModelName, bOS, viaCIDRs) } -func TestAcc_ResourceIntegrationWithMultipleConsumers_Edge(t *testing.T) { +func TestAcc_ResourceIntegrationWithMultipleConsumers(t *testing.T) { if testingCloud != LXDCloudTesting { t.Skip(t.Name() + " only runs with LXD") } diff --git a/internal/provider/resource_machine_test.go b/internal/provider/resource_machine_test.go index e0ea8c9a..4f980f41 100644 --- a/internal/provider/resource_machine_test.go +++ b/internal/provider/resource_machine_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) -func TestAcc_ResourceMachine_Edge(t *testing.T) { +func TestAcc_ResourceMachine(t *testing.T) { if testingCloud != LXDCloudTesting { t.Skip(t.Name() + " only runs with LXD") } @@ -75,21 +75,22 @@ resource "juju_machine" "testmachine" { `, modelName) } -func TestAcc_ResourceMachine_Stable(t *testing.T) { +func TestAcc_ResourceMachine_UpgradeProvider(t *testing.T) { if testingCloud != LXDCloudTesting { t.Skip(t.Name() + " only runs with LXD") } modelName := acctest.RandomWithPrefix("tf-test-machine") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, + Steps: []resource.TestStep{ { + ExternalProviders: map[string]resource.ExternalProvider{ + "juju": { + VersionConstraint: TestProviderStableVersion, + Source: "juju/juju", + }, + }, Config: testAccResourceMachine(modelName, "series = \"focal\""), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("juju_machine.this", "model", modelName), @@ -98,9 +99,9 @@ func TestAcc_ResourceMachine_Stable(t *testing.T) { ), }, { - ImportStateVerify: true, - ImportState: true, - ResourceName: "juju_machine.this", + ProtoV6ProviderFactories: frameworkProviderFactories, + Config: testAccResourceMachine(modelName, "series = \"focal\""), + PlanOnly: true, }, }, }) diff --git a/internal/provider/resource_model_test.go b/internal/provider/resource_model_test.go index 6a35b7df..1dcaf8ad 100644 --- a/internal/provider/resource_model_test.go +++ b/internal/provider/resource_model_test.go @@ -15,7 +15,7 @@ import ( "github.com/juju/juju/rpc/params" ) -func TestAcc_ResourceModel_Edge(t *testing.T) { +func TestAcc_ResourceModel(t *testing.T) { modelName := acctest.RandomWithPrefix("tf-test-model") modelInvalidName := acctest.RandomWithPrefix("tf_test_model") logLevelInfo := "INFO" @@ -67,7 +67,7 @@ func TestAcc_ResourceModel_Edge(t *testing.T) { }) } -func TestAcc_ResourceModel_UnsetConfig_Edge(t *testing.T) { +func TestAcc_ResourceModel_UnsetConfig(t *testing.T) { modelName := acctest.RandomWithPrefix("tf-test-model") resourceName := "juju_model.this" @@ -123,98 +123,31 @@ resource "juju_model" "testmodel" { }) } -func TestAcc_ResourceModel_Stable(t *testing.T) { +func TestAcc_ResourceModel_UpgradeProvider(t *testing.T) { modelName := acctest.RandomWithPrefix("tf-test-model") - modelInvalidName := acctest.RandomWithPrefix("tf_test_model") - logLevelInfo := "INFO" logLevelDebug := "DEBUG" resourceName := "juju_model.model" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, Steps: []resource.TestStep{ { - // Mind that ExpectError should be the first step - // "When tests have an ExpectError[...]; this results in any previous state being cleared. " - // https://github.com/hashicorp/terraform-plugin-sdk/issues/118 - Config: testAccResourceModel(modelInvalidName, testingCloud.CloudName(), logLevelInfo), - ExpectError: regexp.MustCompile(fmt.Sprintf("Error: \"%s\" is not a valid name: model names may only contain lowercase letters, digits and hyphens", modelInvalidName)), - }, - { - Config: testAccResourceModel(modelName, testingCloud.CloudName(), logLevelInfo), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", modelName), - resource.TestCheckResourceAttr(resourceName, "config.logging-config", fmt.Sprintf("=%s", logLevelInfo)), - ), - }, - { + ExternalProviders: map[string]resource.ExternalProvider{ + "juju": { + VersionConstraint: TestProviderStableVersion, + Source: "juju/juju", + }, + }, Config: testAccResourceModel(modelName, testingCloud.CloudName(), logLevelDebug), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "config.logging-config", fmt.Sprintf("=%s", logLevelDebug)), - ), - }, - { - Config: testAccConstraintsModel(modelName, testingCloud.CloudName(), "cores=1 mem=1024M"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "constraints", "cores=1 mem=1024M"), - ), - }, - { - ImportStateVerify: true, - ImportState: true, - ImportStateVerifyIgnore: []string{ - "config.%", - "config.logging-config"}, - ImportStateId: modelName, - ResourceName: resourceName, - }, - }, - }) -} - -func TestAcc_ResourceModel_UnsetConfigStable(t *testing.T) { - modelName := acctest.RandomWithPrefix("tf-test-model") - - resourceName := "juju_model.this" - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, - Steps: []resource.TestStep{ - { - Config: fmt.Sprintf(` -resource "juju_model" "this" { - name = %q - - config = { - development = true - } -}`, modelName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "name", modelName), - resource.TestCheckResourceAttr(resourceName, "config.development", "true"), + resource.TestCheckResourceAttr(resourceName, "config.logging-config", fmt.Sprintf("=%s", logLevelDebug)), ), }, { - Config: fmt.Sprintf(` -resource "juju_model" "this" { - name = %q -}`, modelName), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", modelName), - resource.TestCheckNoResourceAttr(resourceName, "config.development"), - testAccCheckDevelopmentConfigIsUnset(modelName), - ), + ProtoV6ProviderFactories: frameworkProviderFactories, + Config: testAccResourceModel(modelName, testingCloud.CloudName(), logLevelDebug), + PlanOnly: true, }, }, }) diff --git a/internal/provider/resource_offer_test.go b/internal/provider/resource_offer_test.go index 2b0e9b5c..a496b902 100644 --- a/internal/provider/resource_offer_test.go +++ b/internal/provider/resource_offer_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) -func TestAcc_ResourceOffer_Edge(t *testing.T) { +func TestAcc_ResourceOffer(t *testing.T) { if testingCloud != LXDCloudTesting { t.Skip(t.Name() + " only runs with LXD") } @@ -104,7 +104,7 @@ resource "juju_integration" "int" { `, srcModelName, destModelName) } -func TestAcc_ResourceOffer_Stable(t *testing.T) { +func TestAcc_ResourceOffer_UpgradeProvider(t *testing.T) { if testingCloud != LXDCloudTesting { t.Skip(t.Name() + " only runs with LXD") } @@ -112,14 +112,15 @@ func TestAcc_ResourceOffer_Stable(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, + Steps: []resource.TestStep{ { + ExternalProviders: map[string]resource.ExternalProvider{ + "juju": { + VersionConstraint: TestProviderStableVersion, + Source: "juju/juju", + }, + }, Config: testAccResourceOffer(modelName, "series = \"focal\""), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("juju_offer.this", "model", modelName), @@ -128,9 +129,9 @@ func TestAcc_ResourceOffer_Stable(t *testing.T) { ), }, { - ImportStateVerify: true, - ImportState: true, - ResourceName: "juju_offer.this", + ProtoV6ProviderFactories: frameworkProviderFactories, + Config: testAccResourceOffer(modelName, "series = \"focal\""), + PlanOnly: true, }, }, }) diff --git a/internal/provider/resource_ssh_key_test.go b/internal/provider/resource_ssh_key_test.go index 3e3c3502..29512c84 100644 --- a/internal/provider/resource_ssh_key_test.go +++ b/internal/provider/resource_ssh_key_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) -func TestAcc_ResourceSSHKey_Edge(t *testing.T) { +func TestAcc_ResourceSSHKey(t *testing.T) { if testingCloud != LXDCloudTesting { t.Skip(t.Name() + " only runs with LXD") } @@ -41,7 +41,7 @@ func TestAcc_ResourceSSHKey_Edge(t *testing.T) { }) } -func TestAcc_ResourceSSHKey_ED25519_Edge(t *testing.T) { +func TestAcc_ResourceSSHKey_ED25519(t *testing.T) { if testingCloud != LXDCloudTesting { t.Skip(t.Name() + " only runs with LXD") } @@ -62,7 +62,7 @@ func TestAcc_ResourceSSHKey_ED25519_Edge(t *testing.T) { }) } -func TestAcc_ResourceSSHKey_Stable(t *testing.T) { +func TestAcc_ResourceSSHKey_UpgradeProvider(t *testing.T) { if testingCloud != LXDCloudTesting { t.Skip(t.Name() + " only runs with LXD") } @@ -73,51 +73,24 @@ func TestAcc_ResourceSSHKey_Stable(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, + Steps: []resource.TestStep{ { + ExternalProviders: map[string]resource.ExternalProvider{ + "juju": { + VersionConstraint: TestProviderStableVersion, + Source: "juju/juju", + }, + }, Config: testAccResourceSSHKey(modelName, sshKey1), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("juju_ssh_key.this", "model", modelName), resource.TestCheckResourceAttr("juju_ssh_key.this", "payload", sshKey1)), }, - // we update the key { - Config: testAccResourceSSHKey(modelName, sshKey2), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("juju_ssh_key.this", "model", modelName), - resource.TestCheckResourceAttr("juju_ssh_key.this", "payload", sshKey2)), - }, - }, - }) -} - -func TestAcc_ResourceSSHKey_ED25519_Stable(t *testing.T) { - if testingCloud != LXDCloudTesting { - t.Skip(t.Name() + " only runs with LXD") - } - modelName := acctest.RandomWithPrefix("tf-test-sshkey") - sshKey1 := `ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID3gjJTJtYZU55HTUr+hu0JF9p152yiC9czJi9nKojuW jimmy@somewhere` - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, - Steps: []resource.TestStep{ - { - Config: testAccResourceSSHKey(modelName, sshKey1), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("juju_ssh_key.this", "model", modelName), - resource.TestCheckResourceAttr("juju_ssh_key.this", "payload", sshKey1)), + ProtoV6ProviderFactories: frameworkProviderFactories, + Config: testAccResourceSSHKey(modelName, sshKey2), + PlanOnly: true, }, }, }) diff --git a/internal/provider/resource_user_test.go b/internal/provider/resource_user_test.go index 151dddc5..ea36029f 100644 --- a/internal/provider/resource_user_test.go +++ b/internal/provider/resource_user_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) -func TestAcc_ResourceUser_Edge(t *testing.T) { +func TestAcc_ResourceUser(t *testing.T) { userName := acctest.RandomWithPrefix("tfuser") userPassword := acctest.RandomWithPrefix("tf-test-user") @@ -48,32 +48,30 @@ resource "juju_user" "user" { }`, userName, userPassword) } -func TestAcc_ResourceUser_Stable(t *testing.T) { +func TestAcc_ResourceUser_UpgradeProvider(t *testing.T) { userName := acctest.RandomWithPrefix("tfuser") userPassword := acctest.RandomWithPrefix("tf-test-user") resourceName := "juju_user.user" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ExternalProviders: map[string]resource.ExternalProvider{ - "juju": { - VersionConstraint: TestProviderStableVersion, - Source: "juju/juju", - }, - }, Steps: []resource.TestStep{ { + ExternalProviders: map[string]resource.ExternalProvider{ + "juju": { + VersionConstraint: TestProviderStableVersion, + Source: "juju/juju", + }, + }, Config: testAccResourceUser(userName, userPassword), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "name", userName), ), }, { - ImportStateVerify: true, - ImportState: true, - ImportStateVerifyIgnore: []string{"password"}, - ImportStateId: fmt.Sprintf("user:%s", userName), - ResourceName: resourceName, + ProtoV6ProviderFactories: frameworkProviderFactories, + Config: testAccResourceUser(userName, userPassword), + PlanOnly: true, }, }, })