Skip to content

Commit

Permalink
Update acctest to reflect provider config validation added in 5.0.0 (…
Browse files Browse the repository at this point in the history
…#9120) (#6419)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Oct 2, 2023
1 parent b8053d2 commit 30b38fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/9120.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
30 changes: 28 additions & 2 deletions google-beta/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,27 +199,53 @@ 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": {
VersionConstraint: "4.60.2",
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`),
},
},
})
Expand Down

0 comments on commit 30b38fa

Please sign in to comment.