Skip to content

Commit

Permalink
Fix preview features tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jmichalak committed Nov 29, 2024
1 parent 3bb2964 commit 6172fd2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ func (m *SnowflakeModel) WithClientStoreTemporaryCredentialBool(clientStoreTempo
return m
}

func (m *SnowflakeModel) WithPreviewFeaturesEnabled(previewFeaturesEnabled ...string) *SnowflakeModel {
previewFeaturesEnabledStringVariables := make([]tfconfig.Variable, len(previewFeaturesEnabled))
for i, v := range previewFeaturesEnabled {
previewFeaturesEnabledStringVariables[i] = tfconfig.StringVariable(v)
}
m.PreviewFeaturesEnabled = tfconfig.SetVariable(previewFeaturesEnabledStringVariables...)
return m
}

func (m *SnowflakeModel) AllFields(tmpConfig *helpers.TmpTomlConfig, tmpUser *helpers.TmpServiceUser) *SnowflakeModel {
return SnowflakeProvider().
WithProfile(tmpConfig.Profile).
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions pkg/provider/provider_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"
internalprovider "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/provider"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/previewfeatures"
tfconfig "github.com/hashicorp/terraform-plugin-testing/config"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config"
Expand Down Expand Up @@ -808,22 +809,24 @@ func TestAcc_Provider_invalidConfigurations(t *testing.T) {
func TestAcc_Provider_PreviewFeaturesEnabled(t *testing.T) {
t.Setenv(string(testenvs.ConfigureClientOnce), "")
t.Setenv(string(testenvs.EnableAllPreviewFeatures), "")
acc.TestAccPreCheck(t)

tmpServiceUser := acc.TestClient().SetUpTemporaryServiceUser(t)
tmpServiceUserConfig := acc.TestClient().TempTomlConfigForServiceUser(t, tmpServiceUser)

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
Steps: []resource.TestStep{
{
// Config: providerConfigWithDatasourcePreviewFeatureEnabled(testprofiles.Default, "snowflake_current_account"),
Config: config.FromModels(t, providermodel.SnowflakeProvider().WithProfile(tmpServiceUserConfig.Profile), datasourceModel()),
PreConfig: func() {
t.Setenv(snowflakeenvs.ConfigPath, tmpServiceUserConfig.Path)
},
Config: config.FromModels(t, providermodel.SnowflakeProvider().WithProfile(tmpServiceUserConfig.Profile).WithPreviewFeaturesEnabled(string(previewfeatures.DatabaseDatasource)), datasourceModel()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.snowflake_current_account.t", "account"),
resource.TestCheckResourceAttrSet(datasourceModel().DatasourceReference(), "name"),
),
},
},
Expand All @@ -833,6 +836,10 @@ func TestAcc_Provider_PreviewFeaturesEnabled(t *testing.T) {
func TestAcc_Provider_PreviewFeaturesDisabled(t *testing.T) {
t.Setenv(string(testenvs.ConfigureClientOnce), "")
t.Setenv(string(testenvs.EnableAllPreviewFeatures), "")
acc.TestAccPreCheck(t)

tmpServiceUser := acc.TestClient().SetUpTemporaryServiceUser(t)
tmpServiceUserConfig := acc.TestClient().TempTomlConfigForServiceUser(t, tmpServiceUser)

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Expand All @@ -842,8 +849,11 @@ func TestAcc_Provider_PreviewFeaturesDisabled(t *testing.T) {
},
Steps: []resource.TestStep{
{
Config: providerConfigWithDatasourcePreviewFeature(testprofiles.Default, "snowflake_current_account"),
ExpectError: regexp.MustCompile("snowflake_current_account_datasource is currently a preview feature, and must be enabled by adding snowflake_current_account_datasource to `preview_features_enabled` in Terraform configuration"),
PreConfig: func() {
t.Setenv(snowflakeenvs.ConfigPath, tmpServiceUserConfig.Path)
},
Config: config.FromModels(t, providermodel.SnowflakeProvider().WithProfile(tmpServiceUserConfig.Profile), datasourceModel()),
ExpectError: regexp.MustCompile("snowflake_database_datasource is currently a preview feature, and must be enabled by adding snowflake_database_datasource to `preview_features_enabled` in Terraform configuration"),
},
},
})
Expand Down

0 comments on commit 6172fd2

Please sign in to comment.