Skip to content

Commit

Permalink
fix: Fix QUOTED_IDENTIFIERS_IGNORE_CASE parameter test (#2841)
Browse files Browse the repository at this point in the history
Setting `QUOTED_IDENTIFIERS_IGNORE_CASE` in
`TestAcc_Parameters_QuotedIdentifiersIgnoreCaseCanBeSet` was interfering
with the tests being run on other branches. It resulted in seemingly
random `Database 'XYZ' does not exist or not authorized` errors for
database that exists, works moments before and moments after. Sequence
of example statements:
```
-- 2024-05-28 11:28:34.634 +0000
-- CREATE MATERIALIZED VIEW "int_test_db_IT_C0E0DFE82EF6223390C3723866862A273A406F10"."int_test_sc_IT_C0E0DFE82EF6223390C3723866862A273A406F10"."AFKRZIIT_C0E0DFE82EF6223390C3723866862A273A406F10" CLUSTER BY ("ID") AS SELECT id FROM "int_test_db_IT_C0E0DFE82EF6223390C3723866862A273A406F10"."int_test_sc_IT_C0E0DFE82EF6223390C3723866862A273A406F10"."VYODPJIT_C0E0DFE82EF6223390C3723866862A273A406F10"
...
-- 2024-05-28 11:28:35.019 +0000
-- ALTER ACCOUNT SET QUOTED_IDENTIFIERS_IGNORE_CASE = true
...
-- 2024-05-28 11:28:35.123 +0000
-- SHOW MATERIALIZED VIEWS LIKE 'AFKRZIIT_C0E0DFE82EF6223390C3723866862A273A406F10' IN SCHEMA "int_test_db_IT_C0E0DFE82EF6223390C3723866862A273A406F10"."int_test_sc_IT_C0E0DFE82EF6223390C3723866862A273A406F10"
```

What was done:
- test `TestAcc_Parameters_QuotedIdentifiersIgnoreCaseCanBeSet` creates
new user and sets the `QUOTED_IDENTIFIERS_IGNORE_CASE` parameter on it
- fail-fast guards added to integration and acceptance tests setups to
prevent running tests when `QUOTED_IDENTIFIERS_IGNORE_CASE` is set to
true initially
  • Loading branch information
sfc-gh-asawicki authored May 29, 2024
1 parent 82d1c09 commit 92ad1d3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
21 changes: 21 additions & 0 deletions pkg/acceptance/helpers/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package helpers

import (
"context"
"fmt"
"log"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
)

func EnsureQuotedIdentifiersIgnoreCaseIsSetToFalse(client *sdk.Client, ctx context.Context) error {
log.Printf("[DEBUG] Making sure QUOTED_IDENTIFIERS_IGNORE_CASE parameter is set correctly")
param, err := client.Parameters.ShowAccountParameter(ctx, sdk.AccountParameterQuotedIdentifiersIgnoreCase)
if err != nil {
return fmt.Errorf("checking QUOTED_IDENTIFIERS_IGNORE_CASE resulted in error: %w", err)
}
if param.Value != "false" {
return fmt.Errorf("parameter QUOTED_IDENTIFIERS_IGNORE_CASE has value %s, expected: false", param.Value)
}
return nil
}
8 changes: 8 additions & 0 deletions pkg/acceptance/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ func TestAccPreCheck(t *testing.T) {
if err := atc.secondaryClient.Warehouses.Create(ctx, warehouseId, &sdk.CreateWarehouseOptions{IfNotExists: sdk.Bool(true)}); err != nil {
t.Fatal(err)
}

if err := helpers.EnsureQuotedIdentifiersIgnoreCaseIsSetToFalse(atc.client, ctx); err != nil {
t.Fatal(err)
}

if err := helpers.EnsureQuotedIdentifiersIgnoreCaseIsSetToFalse(atc.secondaryClient, ctx); err != nil {
t.Fatal(err)
}
})
}

Expand Down
21 changes: 17 additions & 4 deletions pkg/datasources/parameters_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ func TestAcc_Parameters_TransactionAbortOnErrorCanBeSet(t *testing.T) {
}

// proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2353 is fixed
// done on user, to not interfere with other parallel tests on the same account
func TestAcc_Parameters_QuotedIdentifiersIgnoreCaseCanBeSet(t *testing.T) {
userId := acc.TestClient().Ids.RandomAccountObjectIdentifier()

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
Expand All @@ -104,15 +107,25 @@ func TestAcc_Parameters_QuotedIdentifiersIgnoreCaseCanBeSet(t *testing.T) {
},
Steps: []resource.TestStep{
{
Config: `resource "snowflake_account_parameter" "test" {
key = "QUOTED_IDENTIFIERS_IGNORE_CASE"
value = "true"
}`,
Config: sessionParameterOnUser(userId.Name()),
},
},
})
}

func sessionParameterOnUser(userName string) string {
return fmt.Sprintf(
`
resource "snowflake_user" "u" {
name = "%s"
}
resource "snowflake_session_parameter" "test" {
key = "QUOTED_IDENTIFIERS_IGNORE_CASE"
value = "true"
user = snowflake_user.u.name
}`, userName)
}

func parametersConfigOnAccount() string {
return `data "snowflake_parameters" "p" {
parameter_type = "ACCOUNT"
Expand Down
9 changes: 9 additions & 0 deletions pkg/sdk/testint/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ func (itc *integrationTestContext) initialize() error {
itc.testClient = helpers.NewTestClient(c, TestDatabaseName, TestSchemaName, TestWarehouseName, random.IntegrationTestsSuffix)
itc.secondaryTestClient = helpers.NewTestClient(secondaryClient, TestDatabaseName, TestSchemaName, TestWarehouseName, random.IntegrationTestsSuffix)

err = helpers.EnsureQuotedIdentifiersIgnoreCaseIsSetToFalse(itc.client, itc.ctx)
if err != nil {
return err
}
err = helpers.EnsureQuotedIdentifiersIgnoreCaseIsSetToFalse(itc.secondaryClient, itc.secondaryCtx)
if err != nil {
return err
}

return nil
}

Expand Down

0 comments on commit 92ad1d3

Please sign in to comment.