From 96430072b8b85a4b0a713c4def74c6fb1a38e951 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 26 Feb 2024 17:30:21 +0100 Subject: [PATCH 1/6] Use GetOrSkipTest method --- .../testenvs/testing_environment_variables.go | 2 ++ .../failover_group_acceptance_test.go | 22 +++++-------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/pkg/acceptance/testenvs/testing_environment_variables.go b/pkg/acceptance/testenvs/testing_environment_variables.go index 11882e8715..370bcd30a0 100644 --- a/pkg/acceptance/testenvs/testing_environment_variables.go +++ b/pkg/acceptance/testenvs/testing_environment_variables.go @@ -14,6 +14,8 @@ const ( Account env = "TEST_SF_TF_ACCOUNT" Role env = "TEST_SF_TF_ROLE" Host env = "TEST_SF_TF_HOST" + + BusinessCriticalAccount env = "SNOWFLAKE_BUSINESS_CRITICAL_ACCOUNT" ) func GetOrSkipTest(t *testing.T, envName Env) string { diff --git a/pkg/resources/failover_group_acceptance_test.go b/pkg/resources/failover_group_acceptance_test.go index df6903024c..e1ae0b89d1 100644 --- a/pkg/resources/failover_group_acceptance_test.go +++ b/pkg/resources/failover_group_acceptance_test.go @@ -2,12 +2,12 @@ package resources_test import ( "fmt" - "os" "strings" "testing" acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testenvs" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/tfversion" @@ -16,10 +16,7 @@ import ( func TestAcc_FailoverGroupBasic(t *testing.T) { randomCharacters := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) - if _, ok := os.LookupEnv("SNOWFLAKE_BUSINESS_CRITICAL_ACCOUNT"); !ok { - t.Skip("Skipping TestAcc_FailoverGroup since not a business critical account") - } - accountName := os.Getenv("SNOWFLAKE_BUSINESS_CRITICAL_ACCOUNT") + accountName := testenvs.GetOrSkipTest(t, testenvs.BusinessCriticalAccount) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -54,10 +51,7 @@ func TestAcc_FailoverGroupBasic(t *testing.T) { func TestAcc_FailoverGroupRemoveObjectTypes(t *testing.T) { randomCharacters := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) - if _, ok := os.LookupEnv("SNOWFLAKE_BUSINESS_CRITICAL_ACCOUNT"); !ok { - t.Skip("Skipping TestAcc_FailoverGroup since not a business critical account") - } - accountName := os.Getenv("SNOWFLAKE_BUSINESS_CRITICAL_ACCOUNT") + accountName := testenvs.GetOrSkipTest(t, testenvs.BusinessCriticalAccount) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -95,10 +89,7 @@ func TestAcc_FailoverGroupRemoveObjectTypes(t *testing.T) { func TestAcc_FailoverGroupInterval(t *testing.T) { randomCharacters := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) - if _, ok := os.LookupEnv("SNOWFLAKE_BUSINESS_CRITICAL_ACCOUNT"); !ok { - t.Skip("Skipping TestAcc_FailoverGroup since not a business critical account") - } - accountName := os.Getenv("SNOWFLAKE_BUSINESS_CRITICAL_ACCOUNT") + accountName := testenvs.GetOrSkipTest(t, testenvs.BusinessCriticalAccount) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -194,10 +185,7 @@ func TestAcc_FailoverGroupInterval(t *testing.T) { func TestAcc_FailoverGroup_issue2517(t *testing.T) { randomCharacters := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) - if _, ok := os.LookupEnv("SNOWFLAKE_BUSINESS_CRITICAL_ACCOUNT"); !ok { - t.Skip("Skipping TestAcc_FailoverGroup since not a business critical account") - } - accountName := os.Getenv("SNOWFLAKE_BUSINESS_CRITICAL_ACCOUNT") + accountName := testenvs.GetOrSkipTest(t, testenvs.BusinessCriticalAccount) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, From 559c82121dbb6f5e122ba9f1bf7a21833def772d Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 26 Feb 2024 18:02:40 +0100 Subject: [PATCH 2/6] Run first part of failover group integration tests --- pkg/sdk/failover_groups.go | 8 +++-- .../failover_groups_integration_test.go | 36 +++++++++++++++++-- pkg/sdk/testint/helpers_test.go | 6 ++-- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/pkg/sdk/failover_groups.go b/pkg/sdk/failover_groups.go index 1e71f35036..bb42f24db5 100644 --- a/pkg/sdk/failover_groups.go +++ b/pkg/sdk/failover_groups.go @@ -574,15 +574,17 @@ func (v *failoverGroups) ShowShares(ctx context.Context, id AccountObjectIdentif return nil, err } dest := []struct { - Name string `db:"name"` + Name string `db:"name"` + OwnerAccount string `db:"owner_account"` }{} err = v.client.query(ctx, &dest, sql) if err != nil { return nil, err } resultList := make([]AccountObjectIdentifier, len(dest)) - for i, row := range dest { - resultList[i] = NewExternalObjectIdentifierFromFullyQualifiedName(row.Name).objectIdentifier.(AccountObjectIdentifier) + for i, r := range dest { + // TODO [SNOW-999049]: this was not working correctly with identifiers containing `.` character + resultList[i] = NewExternalObjectIdentifier(NewAccountIdentifierFromFullyQualifiedName(r.OwnerAccount), NewAccountObjectIdentifier(r.Name)).objectIdentifier.(AccountObjectIdentifier) } return resultList, nil } diff --git a/pkg/sdk/testint/failover_groups_integration_test.go b/pkg/sdk/testint/failover_groups_integration_test.go index cb048695ac..8b32594b1d 100644 --- a/pkg/sdk/testint/failover_groups_integration_test.go +++ b/pkg/sdk/testint/failover_groups_integration_test.go @@ -8,15 +8,13 @@ import ( "time" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/avast/retry-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestInt_FailoverGroupsCreate(t *testing.T) { - if os.Getenv("SNOWFLAKE_TEST_BUSINESS_CRITICAL_FEATURES") != "1" { - t.Skip("Skipping TestInt_FailoverGroupsCreate") - } client := testClient(t) ctx := testContext(t) shareTest, shareCleanup := createShare(t, client) @@ -74,6 +72,38 @@ func TestInt_FailoverGroupsCreate(t *testing.T) { assert.Equal(t, shareTest.ID().Name(), fgShares[0].Name()) }) + t.Run("test with identifier containing a dot", func(t *testing.T) { + shareId := sdk.NewAccountObjectIdentifier(random.AlphanumericN(6) + "." + random.AlphanumericN(6)) + + shareWithDot, shareWithDotCleanup := createShareWithOptions(t, client, shareId, &sdk.CreateShareOptions{}) + t.Cleanup(shareWithDotCleanup) + + id := sdk.RandomAccountObjectIdentifier() + objectTypes := []sdk.PluralObjectType{ + sdk.PluralObjectTypeShares, + } + allowedAccounts := []sdk.AccountIdentifier{ + getAccountIdentifier(t, testSecondaryClient(t)), + } + err := client.FailoverGroups.Create(ctx, id, objectTypes, allowedAccounts, &sdk.CreateFailoverGroupOptions{ + AllowedShares: []sdk.AccountObjectIdentifier{ + shareWithDot.ID(), + }, + IgnoreEditionCheck: sdk.Bool(true), + }) + require.NoError(t, err) + cleanupFailoverGroup := func() { + err := client.FailoverGroups.Drop(ctx, id, nil) + require.NoError(t, err) + } + t.Cleanup(cleanupFailoverGroup) + + fgShares, err := client.FailoverGroups.ShowShares(ctx, id) + require.NoError(t, err) + assert.Equal(t, 1, len(fgShares)) + assert.Equal(t, shareWithDot.ID().Name(), fgShares[0].Name()) + }) + t.Run("test with allowed integration types", func(t *testing.T) { id := sdk.RandomAccountObjectIdentifier() objectTypes := []sdk.PluralObjectType{ diff --git a/pkg/sdk/testint/helpers_test.go b/pkg/sdk/testint/helpers_test.go index 311503bd8f..c817a2b661 100644 --- a/pkg/sdk/testint/helpers_test.go +++ b/pkg/sdk/testint/helpers_test.go @@ -656,12 +656,12 @@ func createFailoverGroupWithOptions(t *testing.T, client *sdk.Client, objectType func createShare(t *testing.T, client *sdk.Client) (*sdk.Share, func()) { t.Helper() - return createShareWithOptions(t, client, &sdk.CreateShareOptions{}) + id := sdk.RandomAccountObjectIdentifier() + return createShareWithOptions(t, client, id, &sdk.CreateShareOptions{}) } -func createShareWithOptions(t *testing.T, client *sdk.Client, opts *sdk.CreateShareOptions) (*sdk.Share, func()) { +func createShareWithOptions(t *testing.T, client *sdk.Client, id sdk.AccountObjectIdentifier, opts *sdk.CreateShareOptions) (*sdk.Share, func()) { t.Helper() - id := sdk.RandomAccountObjectIdentifier() ctx := context.Background() err := client.Shares.Create(ctx, id, opts) require.NoError(t, err) From 4d76e709a07dbb7bcfce525ba40237b587caf7c5 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 27 Feb 2024 11:26:36 +0100 Subject: [PATCH 3/6] Add test confirming bad syntax in snowflake docs --- pkg/sdk/failover_groups.go | 2 +- .../failover_groups_integration_test.go | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/pkg/sdk/failover_groups.go b/pkg/sdk/failover_groups.go index bb42f24db5..3ee16460b5 100644 --- a/pkg/sdk/failover_groups.go +++ b/pkg/sdk/failover_groups.go @@ -183,8 +183,8 @@ func (opts *AlterSourceFailoverGroupOptions) validate() error { type FailoverGroupSet struct { ObjectTypes []PluralObjectType `ddl:"parameter" sql:"OBJECT_TYPES"` - ReplicationSchedule *string `ddl:"parameter,single_quotes" sql:"REPLICATION_SCHEDULE"` AllowedIntegrationTypes []IntegrationType `ddl:"parameter" sql:"ALLOWED_INTEGRATION_TYPES"` + ReplicationSchedule *string `ddl:"parameter,single_quotes" sql:"REPLICATION_SCHEDULE"` } func (v *FailoverGroupSet) validate() error { diff --git a/pkg/sdk/testint/failover_groups_integration_test.go b/pkg/sdk/testint/failover_groups_integration_test.go index 8b32594b1d..0ae95a3bac 100644 --- a/pkg/sdk/testint/failover_groups_integration_test.go +++ b/pkg/sdk/testint/failover_groups_integration_test.go @@ -134,6 +134,78 @@ func TestInt_FailoverGroupsCreate(t *testing.T) { }) } +func TestInt_Issue2544(t *testing.T) { + client := testClient(t) + ctx := testContext(t) + + t.Run("alter object types, replication schedule, and allowed integration types at the same time", func(t *testing.T) { + id := sdk.RandomAccountObjectIdentifier() + objectTypes := []sdk.PluralObjectType{ + sdk.PluralObjectTypeIntegrations, + sdk.PluralObjectTypeDatabases, + } + allowedAccounts := []sdk.AccountIdentifier{ + getAccountIdentifier(t, testSecondaryClient(t)), + } + allowedIntegrationTypes := []sdk.IntegrationType{ + sdk.IntegrationTypeAPIIntegrations, + sdk.IntegrationTypeNotificationIntegrations, + } + replicationSchedule := "10 MINUTE" + err := client.FailoverGroups.Create(ctx, id, objectTypes, allowedAccounts, &sdk.CreateFailoverGroupOptions{ + AllowedDatabases: []sdk.AccountObjectIdentifier{ + testDb(t).ID(), + }, + AllowedIntegrationTypes: allowedIntegrationTypes, + ReplicationSchedule: sdk.String(replicationSchedule), + }) + require.NoError(t, err) + cleanupFailoverGroup := func() { + err := client.FailoverGroups.Drop(ctx, id, nil) + require.NoError(t, err) + } + t.Cleanup(cleanupFailoverGroup) + + newObjectTypes := []sdk.PluralObjectType{ + sdk.PluralObjectTypeIntegrations, + } + newAllowedIntegrationTypes := []sdk.IntegrationType{ + sdk.IntegrationTypeAPIIntegrations, + } + newReplicationSchedule := "20 MINUTE" + + // does not work together: + opts := &sdk.AlterSourceFailoverGroupOptions{ + Set: &sdk.FailoverGroupSet{ + ObjectTypes: newObjectTypes, + AllowedIntegrationTypes: newAllowedIntegrationTypes, + ReplicationSchedule: sdk.String(newReplicationSchedule), + }, + } + err = client.FailoverGroups.AlterSource(ctx, id, opts) + require.Error(t, err) + require.ErrorContains(t, err, "unexpected 'REPLICATION_SCHEDULE'") + + // works as two separate alters: + opts = &sdk.AlterSourceFailoverGroupOptions{ + Set: &sdk.FailoverGroupSet{ + ObjectTypes: newObjectTypes, + AllowedIntegrationTypes: newAllowedIntegrationTypes, + }, + } + err = client.FailoverGroups.AlterSource(ctx, id, opts) + require.NoError(t, err) + + opts = &sdk.AlterSourceFailoverGroupOptions{ + Set: &sdk.FailoverGroupSet{ + ReplicationSchedule: sdk.String(newReplicationSchedule), + }, + } + err = client.FailoverGroups.AlterSource(ctx, id, opts) + require.NoError(t, err) + }) +} + func TestInt_CreateSecondaryReplicationGroup(t *testing.T) { // TODO: Business Critical Snowflake Edition (SNOW-1002023) if os.Getenv("SNOWFLAKE_TEST_BUSINESS_CRITICAL_FEATURES") != "1" { From dea54910b3558c40d0d709388f4d0809e068b78c Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 27 Feb 2024 11:53:49 +0100 Subject: [PATCH 4/6] Fix failover group resource --- pkg/resources/failover_group.go | 53 +++++++++++-------- .../failover_group_acceptance_test.go | 42 +++++++++++++++ .../failover_groups_integration_test.go | 15 ++++-- 3 files changed, 83 insertions(+), 27 deletions(-) diff --git a/pkg/resources/failover_group.go b/pkg/resources/failover_group.go index ded941ddcd..7309836930 100644 --- a/pkg/resources/failover_group.go +++ b/pkg/resources/failover_group.go @@ -423,29 +423,6 @@ func UpdateFailoverGroup(d *schema.ResourceData, meta interface{}) error { runSet = true } - if d.HasChange("replication_schedule") { - _, n := d.GetChange("replication_schedule") - replicationSchedule := n.([]interface{})[0].(map[string]interface{}) - c := replicationSchedule["cron"].([]interface{}) - if len(c) > 0 { - if len(c) > 0 { - cron := c[0].(map[string]interface{}) - cronExpression := cron["expression"].(string) - cronExpression = "USING CRON " + cronExpression - if v, ok := cron["time_zone"]; ok { - timeZone := v.(string) - if timeZone != "" { - cronExpression = cronExpression + " " + timeZone - } - } - opts.Set.ReplicationSchedule = &cronExpression - } - } else { - opts.Set.ReplicationSchedule = sdk.String(fmt.Sprintf("%d MINUTE", replicationSchedule["interval"].(int))) - } - runSet = true - } - if d.HasChange("allowed_integration_types") { _, n := d.GetChange("allowed_integration_types") newAllowedIntegrationTypes := expandStringList(n.(*schema.Set).List()) @@ -462,6 +439,36 @@ func UpdateFailoverGroup(d *schema.ResourceData, meta interface{}) error { } } + if d.HasChange("replication_schedule") { + _, n := d.GetChange("replication_schedule") + replicationSchedule := n.([]interface{})[0].(map[string]interface{}) + c := replicationSchedule["cron"].([]interface{}) + var updatedReplicationSchedule string + if len(c) > 0 { + cron := c[0].(map[string]interface{}) + cronExpression := cron["expression"].(string) + cronExpression = "USING CRON " + cronExpression + if v, ok := cron["time_zone"]; ok { + timeZone := v.(string) + if timeZone != "" { + cronExpression = cronExpression + " " + timeZone + } + } + updatedReplicationSchedule = cronExpression + } else { + updatedReplicationSchedule = fmt.Sprintf("%d MINUTE", replicationSchedule["interval"].(int)) + } + + err := client.FailoverGroups.AlterSource(ctx, id, &sdk.AlterSourceFailoverGroupOptions{ + Set: &sdk.FailoverGroupSet{ + ReplicationSchedule: sdk.String(updatedReplicationSchedule), + }, + }) + if err != nil { + return err + } + } + if d.HasChange("allowed_databases") { o, n := d.GetChange("allowed_databases") oad := expandStringList(o.(*schema.Set).List()) diff --git a/pkg/resources/failover_group_acceptance_test.go b/pkg/resources/failover_group_acceptance_test.go index e1ae0b89d1..e55fb6e3c5 100644 --- a/pkg/resources/failover_group_acceptance_test.go +++ b/pkg/resources/failover_group_acceptance_test.go @@ -210,6 +210,34 @@ func TestAcc_FailoverGroup_issue2517(t *testing.T) { }) } +func TestAcc_FailoverGroup_issue2544(t *testing.T) { + randomCharacters := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) + + accountName := testenvs.GetOrSkipTest(t, testenvs.BusinessCriticalAccount) + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, + PreCheck: func() { acc.TestAccPreCheck(t) }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(tfversion.Version1_5_0), + }, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: failoverGroupBasic(randomCharacters, accountName, acc.TestDatabaseName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("snowflake_failover_group.fg", "name", randomCharacters), + ), + }, + { + Config: failoverGroupWithChanges(randomCharacters, accountName, 20), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("snowflake_failover_group.fg", "name", randomCharacters), + ), + }, + }, + }) +} + func failoverGroupBasic(randomCharacters, accountName, databaseName string) string { return fmt.Sprintf(` resource "snowflake_failover_group" "fg" { @@ -292,3 +320,17 @@ resource "snowflake_failover_group" "fg" { } `, randomCharacters, accountName, databaseName) } + +func failoverGroupWithChanges(randomCharacters string, accountName string, interval int) string { + return fmt.Sprintf(` +resource "snowflake_failover_group" "fg" { + name = "%[1]s" + object_types = ["DATABASES", "INTEGRATIONS"] + allowed_accounts= ["%[2]s"] + allowed_integration_types = ["NOTIFICATION INTEGRATIONS"] + replication_schedule { + interval = %d + } +} +`, randomCharacters, accountName, interval) +} diff --git a/pkg/sdk/testint/failover_groups_integration_test.go b/pkg/sdk/testint/failover_groups_integration_test.go index 0ae95a3bac..e0e64ffac8 100644 --- a/pkg/sdk/testint/failover_groups_integration_test.go +++ b/pkg/sdk/testint/failover_groups_integration_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testenvs" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/avast/retry-go" @@ -20,6 +21,9 @@ func TestInt_FailoverGroupsCreate(t *testing.T) { shareTest, shareCleanup := createShare(t, client) t.Cleanup(shareCleanup) + accountName := testenvs.GetOrSkipTest(t, testenvs.BusinessCriticalAccount) + businessCriticalAccountId := sdk.NewAccountIdentifierFromFullyQualifiedName(accountName) + t.Run("test complete", func(t *testing.T) { id := sdk.RandomAccountObjectIdentifier() objectTypes := []sdk.PluralObjectType{ @@ -27,7 +31,7 @@ func TestInt_FailoverGroupsCreate(t *testing.T) { sdk.PluralObjectTypeDatabases, } allowedAccounts := []sdk.AccountIdentifier{ - getAccountIdentifier(t, testSecondaryClient(t)), + businessCriticalAccountId, } replicationSchedule := "10 MINUTE" err := client.FailoverGroups.Create(ctx, id, objectTypes, allowedAccounts, &sdk.CreateFailoverGroupOptions{ @@ -83,7 +87,7 @@ func TestInt_FailoverGroupsCreate(t *testing.T) { sdk.PluralObjectTypeShares, } allowedAccounts := []sdk.AccountIdentifier{ - getAccountIdentifier(t, testSecondaryClient(t)), + businessCriticalAccountId, } err := client.FailoverGroups.Create(ctx, id, objectTypes, allowedAccounts, &sdk.CreateFailoverGroupOptions{ AllowedShares: []sdk.AccountObjectIdentifier{ @@ -110,7 +114,7 @@ func TestInt_FailoverGroupsCreate(t *testing.T) { sdk.PluralObjectTypeIntegrations, } allowedAccounts := []sdk.AccountIdentifier{ - getAccountIdentifier(t, testSecondaryClient(t)), + businessCriticalAccountId, } allowedIntegrationTypes := []sdk.IntegrationType{ sdk.IntegrationTypeAPIIntegrations, @@ -138,6 +142,9 @@ func TestInt_Issue2544(t *testing.T) { client := testClient(t) ctx := testContext(t) + accountName := testenvs.GetOrSkipTest(t, testenvs.BusinessCriticalAccount) + businessCriticalAccountId := sdk.NewAccountIdentifierFromFullyQualifiedName(accountName) + t.Run("alter object types, replication schedule, and allowed integration types at the same time", func(t *testing.T) { id := sdk.RandomAccountObjectIdentifier() objectTypes := []sdk.PluralObjectType{ @@ -145,7 +152,7 @@ func TestInt_Issue2544(t *testing.T) { sdk.PluralObjectTypeDatabases, } allowedAccounts := []sdk.AccountIdentifier{ - getAccountIdentifier(t, testSecondaryClient(t)), + businessCriticalAccountId, } allowedIntegrationTypes := []sdk.IntegrationType{ sdk.IntegrationTypeAPIIntegrations, From f80b9c710e5a627409ef2d15a018c4ca4f3ad63e Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 27 Feb 2024 11:59:40 +0100 Subject: [PATCH 5/6] Ignore leading and trailing whitespace for pipes statement diff References: #2560 --- pkg/resources/pipe.go | 4 ++-- pkg/resources/pipe_acceptance_test.go | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pkg/resources/pipe.go b/pkg/resources/pipe.go index 1676d31d56..558f0e479e 100644 --- a/pkg/resources/pipe.go +++ b/pkg/resources/pipe.go @@ -101,8 +101,8 @@ func pipeCopyStatementDiffSuppress(_, o, n string, _ *schema.ResourceData) bool o = strings.ReplaceAll(o, "\r\n", "\n") n = strings.ReplaceAll(n, "\r\n", "\n") - // trim off any trailing line endings - return strings.TrimRight(o, ";\r\n") == strings.TrimRight(n, ";\r\n") + // trim off any trailing line endings and leading/trailing whitespace + return strings.TrimSpace(strings.TrimRight(o, ";\r\n")) == strings.TrimSpace(strings.TrimRight(n, ";\r\n")) } // CreatePipe implements schema.CreateFunc. diff --git a/pkg/resources/pipe_acceptance_test.go b/pkg/resources/pipe_acceptance_test.go index 1d3a78a486..9d5509d417 100644 --- a/pkg/resources/pipe_acceptance_test.go +++ b/pkg/resources/pipe_acceptance_test.go @@ -2,24 +2,25 @@ package resources_test import ( "fmt" - "os" "strings" "testing" acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/tfversion" ) func TestAcc_Pipe(t *testing.T) { - if _, ok := os.LookupEnv("SKIP_PIPE_TESTS"); ok { - t.Skip("Skipping TestAcc_Pipe") - } accName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) resource.Test(t, resource.TestCase{ - Providers: acc.TestAccProviders(), - PreCheck: func() { acc.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, + PreCheck: func() { acc.TestAccPreCheck(t) }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(tfversion.Version1_5_0), + }, CheckDestroy: nil, Steps: []resource.TestStep{ { @@ -37,6 +38,7 @@ func TestAcc_Pipe(t *testing.T) { }) } +// whitespace in copy_statement matters for the tests, change with caution! func pipeConfig(name string, databaseName string, schemaName string) string { s := ` resource "snowflake_table" "test" { @@ -69,7 +71,7 @@ resource "snowflake_pipe" "test" { name = "%s" comment = "Terraform acceptance test" copy_statement = < Date: Tue, 27 Feb 2024 12:02:08 +0100 Subject: [PATCH 6/6] Update TODOs --- pkg/sdk/testint/failover_groups_integration_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/sdk/testint/failover_groups_integration_test.go b/pkg/sdk/testint/failover_groups_integration_test.go index e0e64ffac8..1632d1eb22 100644 --- a/pkg/sdk/testint/failover_groups_integration_test.go +++ b/pkg/sdk/testint/failover_groups_integration_test.go @@ -213,8 +213,8 @@ func TestInt_Issue2544(t *testing.T) { }) } +// TODO [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed func TestInt_CreateSecondaryReplicationGroup(t *testing.T) { - // TODO: Business Critical Snowflake Edition (SNOW-1002023) if os.Getenv("SNOWFLAKE_TEST_BUSINESS_CRITICAL_FEATURES") != "1" { t.Skip("Skipping TestInt_FailoverGroupsCreate") } @@ -290,6 +290,7 @@ func TestInt_CreateSecondaryReplicationGroup(t *testing.T) { assert.Equal(t, 2, len(failoverGroups)) } +// TODO [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed func TestInt_FailoverGroupsAlterSource(t *testing.T) { if os.Getenv("SNOWFLAKE_TEST_BUSINESS_CRITICAL_FEATURES") != "1" { t.Skip("Skipping TestInt_FailoverGroupsCreate") @@ -647,8 +648,8 @@ func TestInt_FailoverGroupsAlterSource(t *testing.T) { }) } +// TODO [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed func TestInt_FailoverGroupsAlterTarget(t *testing.T) { - // TODO: Business Critical Snowflake Edition (SNOW-1002023) if os.Getenv("SNOWFLAKE_TEST_BUSINESS_CRITICAL_FEATURES") != "1" { t.Skip("Skipping TestInt_FailoverGroupsCreate") } @@ -773,6 +774,7 @@ func TestInt_FailoverGroupsAlterTarget(t *testing.T) { }) } +// TODO [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed func TestInt_FailoverGroupsDrop(t *testing.T) { if os.Getenv("SNOWFLAKE_TEST_BUSINESS_CRITICAL_FEATURES") != "1" { t.Skip("Skipping TestInt_FailoverGroupsCreate") @@ -795,6 +797,7 @@ func TestInt_FailoverGroupsDrop(t *testing.T) { }) } +// TODO [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed func TestInt_FailoverGroupsShow(t *testing.T) { if os.Getenv("SNOWFLAKE_TEST_BUSINESS_CRITICAL_FEATURES") != "1" { t.Skip("Skipping TestInt_FailoverGroupsCreate") @@ -827,6 +830,7 @@ func TestInt_FailoverGroupsShow(t *testing.T) { }) } +// TODO [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed func TestInt_FailoverGroupsShowDatabases(t *testing.T) { if os.Getenv("SNOWFLAKE_TEST_BUSINESS_CRITICAL_FEATURES") != "1" { t.Skip("Skipping TestInt_FailoverGroupsCreate") @@ -860,6 +864,7 @@ func TestInt_FailoverGroupsShowDatabases(t *testing.T) { assert.Equal(t, testDb(t).ID(), databases[0]) } +// TODO [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed func TestInt_FailoverGroupsShowShares(t *testing.T) { if _, ok := os.LookupEnv("SNOWFLAKE_TEST_BUSINESS_CRITICAL_FEATURES"); !ok { t.Skip("Skipping TestInt_FailoverGroupsCreate")