From 4a213ca1c03f599967261d18ff2cd68a62925b62 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Mon, 2 Oct 2023 15:58:11 +0000 Subject: [PATCH] Update acctest to reflect provider config validation added in 5.0.0 (#9120) Signed-off-by: Modular Magician --- .changelog/9120.txt | 3 +++ google-beta/provider/provider_test.go | 30 +++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .changelog/9120.txt diff --git a/.changelog/9120.txt b/.changelog/9120.txt new file mode 100644 index 0000000000..8ec013c069 --- /dev/null +++ b/.changelog/9120.txt @@ -0,0 +1,3 @@ +```release-note:none + +``` diff --git a/google-beta/provider/provider_test.go b/google-beta/provider/provider_test.go index e6215aefc8..92d8b4f0ce 100644 --- a/google-beta/provider/provider_test.go +++ b/google-beta/provider/provider_test.go @@ -199,14 +199,18 @@ func TestAccProviderCredentialsEmptyString(t *testing.T) { // No TestDestroy since that's not really the point of this test Steps: []resource.TestStep{ { + // This is a control for the other test steps; the provider block doesn't contain `credentials = ""` Config: testAccProviderCredentials_actWithCredsFromEnv(pid), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + PlanOnly: true, + ExpectNonEmptyPlan: true, }, { // Assert that errors are expected with credentials when // - GOOGLE_CREDENTIALS is set // - provider block has credentials = "" // - TPG v4.60.2 is used + // Context: this was an addidental breaking change introduced with muxing Config: testAccProviderCredentials_actWithCredsFromEnv_emptyString(pid), ExternalProviders: map[string]resource.ExternalProvider{ "google": { @@ -214,12 +218,34 @@ func TestAccProviderCredentialsEmptyString(t *testing.T) { Source: "hashicorp/google", }, }, - ExpectError: regexp.MustCompile(`unexpected end of JSON input`), + PlanOnly: true, + ExpectNonEmptyPlan: true, + ExpectError: regexp.MustCompile(`unexpected end of JSON input`), + }, + { + // Assert that errors are NOT expected with credentials when + // - GOOGLE_CREDENTIALS is set + // - provider block has credentials = "" + // - TPG v4.84.0 is used + // Context: this was the fix for the unintended breaking change in 4.60.2 + Config: testAccProviderCredentials_actWithCredsFromEnv_emptyString(pid), + ExternalProviders: map[string]resource.ExternalProvider{ + "google": { + VersionConstraint: "4.84.0", + Source: "hashicorp/google", + }, + }, + PlanOnly: true, + ExpectNonEmptyPlan: true, }, { - // Errors are not expected when using the latest 4.x.x version of the provider + // Validation errors are expected in 5.0.0+ + // Context: we intentionally introduced the breaking change again in 5.0.0+ Config: testAccProviderCredentials_actWithCredsFromEnv_emptyString(pid), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + PlanOnly: true, + ExpectNonEmptyPlan: true, + ExpectError: regexp.MustCompile(`expected a non-empty string`), }, }, })