Skip to content

Commit

Permalink
Fix situation with switching SF_TF_ACC_TEST_CONFIGURE_CLIENT_ONCE on/off
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-asawicki committed Mar 7, 2024
1 parent 991fbf7 commit f4037d6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,20 @@ func ConfigureProvider(s *schema.ResourceData) (interface{}, error) {
}
}

configuredClient, configureClientError = sdk.NewClient(config)
cl, clErr := sdk.NewClient(config)

if configureClientError != nil {
return nil, configureClientError
// needed for tests verifying different provider setups
if os.Getenv("TF_ACC") != "" && os.Getenv("SF_TF_ACC_TEST_CONFIGURE_CLIENT_ONCE") == "true" {
configuredClient = cl
configureClientError = clErr
} else {
configuredClient = nil
configureClientError = nil
}

if clErr != nil {
return nil, clErr
}

return &provider.Context{Client: configuredClient}, nil
return &provider.Context{Client: cl}, nil
}
31 changes: 31 additions & 0 deletions pkg/provider/provider_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,37 @@ func TestAcc_Provider_configHierarchy(t *testing.T) {
})
}

func TestAcc_Provider_(t *testing.T) {
t.Setenv(string(testenvs.ConfigureClientOnce), "")

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() {
acc.TestAccPreCheck(t)
testenvs.AssertEnvNotSet(t, snowflakeenvs.User)
testenvs.AssertEnvNotSet(t, snowflakeenvs.Password)
},
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
Steps: []resource.TestStep{
{
Config: providerConfig(testprofiles.IncorrectUserAndPassword),
ExpectError: regexp.MustCompile("Incorrect username or password was specified"),
},
{
PreConfig: func() {
t.Setenv(string(testenvs.ConfigureClientOnce), "true")
},
Config: emptyProviderConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.snowflake_database.t", "name", acc.TestDatabaseName),
),
},
},
})
}

func emptyProviderConfig() string {
return `
provider "snowflake" {
Expand Down

0 comments on commit f4037d6

Please sign in to comment.