From ca90fdefc18f6c77627e602df46650e17cb54eaa Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 15 Oct 2024 10:03:05 +0200 Subject: [PATCH] chore: Add tests to 3117 and bump build time (#3133) - Document two tests for #3117 - Bump acceptance tests build time --- Makefile | 2 +- pkg/acceptance/helpers/database_client.go | 8 +++ pkg/acceptance/helpers/schema_client.go | 8 +++ pkg/resources/alert_acceptance_test.go | 80 +++++++++++++++++++++-- 4 files changed, 92 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 99a213fb55..e81c234249 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ test: test-client ## run unit and integration tests go test -v -cover -timeout=45m ./... test-acceptance: ## run acceptance tests - TF_ACC=1 SF_TF_ACC_TEST_CONFIGURE_CLIENT_ONCE=true TEST_SF_TF_REQUIRE_TEST_OBJECT_SUFFIX=1 go test -run "^TestAcc_" -v -cover -timeout=90m ./... + TF_ACC=1 SF_TF_ACC_TEST_CONFIGURE_CLIENT_ONCE=true TEST_SF_TF_REQUIRE_TEST_OBJECT_SUFFIX=1 go test -run "^TestAcc_" -v -cover -timeout=120m ./... test-integration: ## run SDK integration tests TEST_SF_TF_REQUIRE_TEST_OBJECT_SUFFIX=1 go test -run "^TestInt_" -v -cover -timeout=45m ./... diff --git a/pkg/acceptance/helpers/database_client.go b/pkg/acceptance/helpers/database_client.go index d5474476b3..a0ea93ebab 100644 --- a/pkg/acceptance/helpers/database_client.go +++ b/pkg/acceptance/helpers/database_client.go @@ -184,3 +184,11 @@ func (c *DatabaseClient) ShowAllReplicationDatabases(t *testing.T) ([]sdk.Replic return c.context.client.ReplicationFunctions.ShowReplicationDatabases(ctx, nil) } + +func (c *DatabaseClient) Alter(t *testing.T, id sdk.AccountObjectIdentifier, opts *sdk.AlterDatabaseOptions) { + t.Helper() + ctx := context.Background() + + err := c.client().Alter(ctx, id, opts) + require.NoError(t, err) +} diff --git a/pkg/acceptance/helpers/schema_client.go b/pkg/acceptance/helpers/schema_client.go index ac77595262..7c58b90560 100644 --- a/pkg/acceptance/helpers/schema_client.go +++ b/pkg/acceptance/helpers/schema_client.go @@ -104,3 +104,11 @@ func (c *SchemaClient) ShowWithOptions(t *testing.T, opts *sdk.ShowSchemaOptions require.NoError(t, err) return schemas } + +func (c *SchemaClient) Alter(t *testing.T, id sdk.DatabaseObjectIdentifier, opts *sdk.AlterSchemaOptions) { + t.Helper() + ctx := context.Background() + + err := c.client().Alter(ctx, id, opts) + require.NoError(t, err) +} diff --git a/pkg/resources/alert_acceptance_test.go b/pkg/resources/alert_acceptance_test.go index d36bb9bbc4..7dd9853e6e 100644 --- a/pkg/resources/alert_acceptance_test.go +++ b/pkg/resources/alert_acceptance_test.go @@ -9,6 +9,7 @@ import ( acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testenvs" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -222,14 +223,14 @@ func TestAcc_Alert_Issue3117(t *testing.T) { Source: "Snowflake-Labs/snowflake", }, }, - Config: alertIssue3117Config(id, acc.TestClient().Ids.WarehouseId()), + Config: alertIssue3117Config(id, acc.TestClient().Ids.WarehouseId(), "test_alert"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_alert.test_alert", "name", id.Name()), ), }, { ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, - Config: alertIssue3117Config(id, acc.TestClient().Ids.WarehouseId()), + Config: alertIssue3117Config(id, acc.TestClient().Ids.WarehouseId(), "test_alert"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_alert.test_alert", "name", id.Name()), ), @@ -238,9 +239,78 @@ func TestAcc_Alert_Issue3117(t *testing.T) { }) } -func alertIssue3117Config(alertId sdk.SchemaObjectIdentifier, warehouseId sdk.AccountObjectIdentifier) string { +// Can't reproduce the issue, leaving the test for now. +func TestAcc_Alert_Issue3117_PatternMatching(t *testing.T) { + suffix := acc.TestClient().Ids.Alpha() + id1 := acc.TestClient().Ids.NewSchemaObjectIdentifier("prefix1" + suffix) + id2 := acc.TestClient().Ids.NewSchemaObjectIdentifier("prefix_" + suffix) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, + PreCheck: func() { acc.TestAccPreCheck(t) }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(tfversion.Version1_5_0), + }, + CheckDestroy: acc.CheckDestroy(t, resources.Alert), + Steps: []resource.TestStep{ + { + Config: alertIssue3117Config(id1, acc.TestClient().Ids.WarehouseId(), "test_alert_1"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("snowflake_alert.test_alert_1", "name", id1.Name()), + ), + }, + { + Config: alertIssue3117Config(id1, acc.TestClient().Ids.WarehouseId(), "test_alert_1") + alertIssue3117Config(id2, acc.TestClient().Ids.WarehouseId(), "test_alert_2"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("snowflake_alert.test_alert_1", "name", id1.Name()), + resource.TestCheckResourceAttr("snowflake_alert.test_alert_2", "name", id2.Name()), + ), + }, + }, + }) +} + +// Can't reproduce the issue, leaving the test for now. +func TestAcc_Alert_Issue3117_IgnoreQuotedIdentifierCase(t *testing.T) { + _ = testenvs.GetOrSkipTest(t, testenvs.EnableAcceptance) + acc.TestAccPreCheck(t) + + database, databaseCleanup := acc.TestClient().Database.CreateDatabase(t) + t.Cleanup(databaseCleanup) + + schema, schemaCleanup := acc.TestClient().Schema.CreateSchemaInDatabase(t, database.ID()) + t.Cleanup(schemaCleanup) + + id := acc.TestClient().Ids.NewSchemaObjectIdentifierInSchema("small_"+acc.TestClient().Ids.Alpha(), schema.ID()) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, + PreCheck: func() { acc.TestAccPreCheck(t) }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(tfversion.Version1_5_0), + }, + CheckDestroy: acc.CheckDestroy(t, resources.Alert), + Steps: []resource.TestStep{ + { + PreConfig: func() { + acc.TestClient().Database.Alter(t, database.ID(), &sdk.AlterDatabaseOptions{ + Set: &sdk.DatabaseSet{ + QuotedIdentifiersIgnoreCase: sdk.Bool(true), + }, + }) + }, + Config: alertIssue3117Config(id, acc.TestClient().Ids.WarehouseId(), "test_alert"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("snowflake_alert.test_alert", "name", id.Name()), + ), + }, + }, + }) +} + +func alertIssue3117Config(alertId sdk.SchemaObjectIdentifier, warehouseId sdk.AccountObjectIdentifier, resourceName string) string { return fmt.Sprintf(` -resource "snowflake_alert" "test_alert" { +resource "snowflake_alert" "%[5]s" { database = "%[1]s" schema = "%[2]s" name = "%[3]s" @@ -256,5 +326,5 @@ resource "snowflake_alert" "test_alert" { enabled = true comment = "Alert config for GH issue 3117" } -`, alertId.DatabaseName(), alertId.SchemaName(), alertId.Name(), warehouseId.Name()) +`, alertId.DatabaseName(), alertId.SchemaName(), alertId.Name(), warehouseId.Name(), resourceName) }