From d373e41a34404d16a96bb7b660e12a8ba1acf0ff Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Thu, 18 Apr 2024 13:55:14 +0200 Subject: [PATCH 1/3] Introduce schema test client and move random package --- .../helpers}/random/random_helpers.go | 0 pkg/acceptance/helpers/schema_client.go | 49 +++++++++++++++++++ pkg/acceptance/helpers/test_client.go | 2 + pkg/sdk/alerts_test.go | 2 +- pkg/sdk/applications_gen_test.go | 2 +- pkg/sdk/database_role_test.go | 2 +- pkg/sdk/event_tables_gen_test.go | 2 +- pkg/sdk/functions_gen_test.go | 2 +- pkg/sdk/masking_policy_test.go | 2 +- pkg/sdk/password_policy_test.go | 2 +- pkg/sdk/procedures_gen_test.go | 2 +- pkg/sdk/random.go | 2 +- pkg/sdk/sequences_gen_test.go | 2 +- pkg/sdk/shares_test.go | 2 +- pkg/sdk/tables_test.go | 2 +- pkg/sdk/tags_test.go | 2 +- pkg/sdk/testint/accounts_integration_test.go | 2 +- pkg/sdk/testint/alerts_integration_test.go | 2 +- .../application_packages_integration_test.go | 2 +- .../application_roles_gen_integration_test.go | 2 +- .../testint/applications_integration_test.go | 2 +- pkg/sdk/testint/comments_integration_test.go | 3 +- .../testint/database_role_integration_test.go | 2 +- pkg/sdk/testint/databases_integration_test.go | 2 +- .../testint/dynamic_table_integration_test.go | 2 +- .../testint/event_tables_integration_test.go | 2 +- .../external_functions_integration_test.go | 2 +- .../external_tables_integration_test.go | 2 +- .../failover_groups_integration_test.go | 2 +- .../testint/file_format_integration_test.go | 2 +- pkg/sdk/testint/functions_integration_test.go | 2 +- pkg/sdk/testint/grants_integration_test.go | 2 +- pkg/sdk/testint/helpers_test.go | 2 +- .../managed_accounts_gen_integration_test.go | 2 +- .../masking_policy_integration_test.go | 2 +- ...materialized_views_gen_integration_test.go | 2 +- .../network_policies_gen_integration_test.go | 2 +- .../network_rule_gen_integration_test.go | 2 +- .../password_policy_integration_test.go | 2 +- pkg/sdk/testint/pipes_integration_test.go | 3 +- .../policy_references_integration_test.go | 2 +- .../testint/procedures_integration_test.go | 2 +- .../replication_functions_integration_test.go | 2 +- .../resource_monitors_integration_test.go | 2 +- pkg/sdk/testint/roles_integration_test.go | 2 +- ...ow_access_policies_gen_integration_test.go | 2 +- pkg/sdk/testint/schemas_integration_test.go | 2 +- pkg/sdk/testint/sequences_integration_test.go | 2 +- .../session_policies_gen_integration_test.go | 2 +- pkg/sdk/testint/setup_test.go | 2 +- pkg/sdk/testint/shares_integration_test.go | 2 +- .../testint/stages_gen_integration_test.go | 2 +- .../testint/streamlits_integration_test.go | 2 +- .../testint/streams_gen_integration_test.go | 6 +-- .../system_functions_integration_test.go | 2 +- pkg/sdk/testint/tables_integration_test.go | 2 +- pkg/sdk/testint/tags_integration_test.go | 2 +- pkg/sdk/testint/tasks_gen_integration_test.go | 2 +- pkg/sdk/testint/users_integration_test.go | 2 +- pkg/sdk/testint/views_gen_integration_test.go | 2 +- pkg/sdk/users_test.go | 2 +- pkg/sdk/validations_test.go | 2 +- 62 files changed, 113 insertions(+), 62 deletions(-) rename pkg/{sdk/internal => acceptance/helpers}/random/random_helpers.go (100%) create mode 100644 pkg/acceptance/helpers/schema_client.go diff --git a/pkg/sdk/internal/random/random_helpers.go b/pkg/acceptance/helpers/random/random_helpers.go similarity index 100% rename from pkg/sdk/internal/random/random_helpers.go rename to pkg/acceptance/helpers/random/random_helpers.go diff --git a/pkg/acceptance/helpers/schema_client.go b/pkg/acceptance/helpers/schema_client.go new file mode 100644 index 0000000000..7e176c33db --- /dev/null +++ b/pkg/acceptance/helpers/schema_client.go @@ -0,0 +1,49 @@ +package helpers + +import ( + "context" + "errors" + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/stretchr/testify/require" +) + +type SchemaClient struct { + context *TestClientContext +} + +func NewSchemaClient(context *TestClientContext) *SchemaClient { + return &SchemaClient{ + context: context, + } +} + +func (c *SchemaClient) client() sdk.Schemas { + return c.context.client.Schemas +} + +func (c *SchemaClient) CreateSchema(t *testing.T, database *sdk.Database) (*sdk.Schema, func()) { + t.Helper() + return c.CreateSchemaWithIdentifier(t, database, random.StringRange(8, 28)) +} + +func (c *SchemaClient) CreateSchemaWithIdentifier(t *testing.T, database *sdk.Database, name string) (*sdk.Schema, func()) { + t.Helper() + ctx := context.Background() + schemaID := sdk.NewDatabaseObjectIdentifier(database.Name, name) + err := c.client().Create(ctx, schemaID, nil) + require.NoError(t, err) + schema, err := c.client().ShowByID(ctx, sdk.NewDatabaseObjectIdentifier(database.Name, name)) + require.NoError(t, err) + return schema, func() { + err := c.client().Drop(ctx, schemaID, nil) + if errors.Is(err, sdk.ErrObjectNotExistOrAuthorized) { + return + } + require.NoError(t, err) + err = c.context.client.Sessions.UseSchema(ctx, sdk.NewDatabaseObjectIdentifier(c.context.database, c.context.schema)) + require.NoError(t, err) + } +} diff --git a/pkg/acceptance/helpers/test_client.go b/pkg/acceptance/helpers/test_client.go index 022884ef72..3aa9003fc3 100644 --- a/pkg/acceptance/helpers/test_client.go +++ b/pkg/acceptance/helpers/test_client.go @@ -6,6 +6,7 @@ type TestClient struct { context *TestClientContext Database *DatabaseClient + Schema *SchemaClient } func NewTestClient(c *sdk.Client, database string, schema string, warehouse string) *TestClient { @@ -18,6 +19,7 @@ func NewTestClient(c *sdk.Client, database string, schema string, warehouse stri return &TestClient{ context: context, Database: NewDatabaseClient(context), + Schema: NewSchemaClient(context), } } diff --git a/pkg/sdk/alerts_test.go b/pkg/sdk/alerts_test.go index 8466e5bc2d..dc87618607 100644 --- a/pkg/sdk/alerts_test.go +++ b/pkg/sdk/alerts_test.go @@ -3,7 +3,7 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestAlertCreate(t *testing.T) { diff --git a/pkg/sdk/applications_gen_test.go b/pkg/sdk/applications_gen_test.go index 0f64cfd209..b3ed262e0d 100644 --- a/pkg/sdk/applications_gen_test.go +++ b/pkg/sdk/applications_gen_test.go @@ -3,7 +3,7 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestApplications_Create(t *testing.T) { diff --git a/pkg/sdk/database_role_test.go b/pkg/sdk/database_role_test.go index 645db94160..539ff0de51 100644 --- a/pkg/sdk/database_role_test.go +++ b/pkg/sdk/database_role_test.go @@ -3,7 +3,7 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestDatabaseRoleCreate(t *testing.T) { diff --git a/pkg/sdk/event_tables_gen_test.go b/pkg/sdk/event_tables_gen_test.go index af08c6eee2..3b89678e74 100644 --- a/pkg/sdk/event_tables_gen_test.go +++ b/pkg/sdk/event_tables_gen_test.go @@ -3,7 +3,7 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestEventTables_Create(t *testing.T) { diff --git a/pkg/sdk/functions_gen_test.go b/pkg/sdk/functions_gen_test.go index 19e552b2cd..77f3442d68 100644 --- a/pkg/sdk/functions_gen_test.go +++ b/pkg/sdk/functions_gen_test.go @@ -3,7 +3,7 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestFunctions_CreateForJava(t *testing.T) { diff --git a/pkg/sdk/masking_policy_test.go b/pkg/sdk/masking_policy_test.go index becb6e615f..445e5d38f7 100644 --- a/pkg/sdk/masking_policy_test.go +++ b/pkg/sdk/masking_policy_test.go @@ -3,7 +3,7 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestMaskingPolicyCreate(t *testing.T) { diff --git a/pkg/sdk/password_policy_test.go b/pkg/sdk/password_policy_test.go index ddac1d2f87..650ceda676 100644 --- a/pkg/sdk/password_policy_test.go +++ b/pkg/sdk/password_policy_test.go @@ -3,7 +3,7 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestPasswordPolicyCreate(t *testing.T) { diff --git a/pkg/sdk/procedures_gen_test.go b/pkg/sdk/procedures_gen_test.go index 1a9b989602..9b500dd811 100644 --- a/pkg/sdk/procedures_gen_test.go +++ b/pkg/sdk/procedures_gen_test.go @@ -3,7 +3,7 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestProcedures_CreateForJava(t *testing.T) { diff --git a/pkg/sdk/random.go b/pkg/sdk/random.go index f92fa2853a..b759e05da9 100644 --- a/pkg/sdk/random.go +++ b/pkg/sdk/random.go @@ -1,7 +1,7 @@ package sdk import ( - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) // Helper methods in this file are used both in SDK tests and also in integration tests. diff --git a/pkg/sdk/sequences_gen_test.go b/pkg/sdk/sequences_gen_test.go index d58b11245a..6d8cef615c 100644 --- a/pkg/sdk/sequences_gen_test.go +++ b/pkg/sdk/sequences_gen_test.go @@ -3,7 +3,7 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestSequences_Create(t *testing.T) { diff --git a/pkg/sdk/shares_test.go b/pkg/sdk/shares_test.go index c7d07fcd87..f394d36764 100644 --- a/pkg/sdk/shares_test.go +++ b/pkg/sdk/shares_test.go @@ -3,7 +3,7 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestSharesCreate(t *testing.T) { diff --git a/pkg/sdk/tables_test.go b/pkg/sdk/tables_test.go index 4faeacf145..6b34fd3c24 100644 --- a/pkg/sdk/tables_test.go +++ b/pkg/sdk/tables_test.go @@ -3,7 +3,7 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/tags_test.go b/pkg/sdk/tags_test.go index b977dafbca..a52f036662 100644 --- a/pkg/sdk/tags_test.go +++ b/pkg/sdk/tags_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestTagCreate(t *testing.T) { diff --git a/pkg/sdk/testint/accounts_integration_test.go b/pkg/sdk/testint/accounts_integration_test.go index addb97b0d6..c89da51407 100644 --- a/pkg/sdk/testint/accounts_integration_test.go +++ b/pkg/sdk/testint/accounts_integration_test.go @@ -7,8 +7,8 @@ import ( "testing" "time" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "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/brianvoe/gofakeit/v6" "github.com/stretchr/testify/assert" diff --git a/pkg/sdk/testint/alerts_integration_test.go b/pkg/sdk/testint/alerts_integration_test.go index b3964529a0..53b1c690d2 100644 --- a/pkg/sdk/testint/alerts_integration_test.go +++ b/pkg/sdk/testint/alerts_integration_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/application_packages_integration_test.go b/pkg/sdk/testint/application_packages_integration_test.go index 950fcab6dd..c90f6646be 100644 --- a/pkg/sdk/testint/application_packages_integration_test.go +++ b/pkg/sdk/testint/application_packages_integration_test.go @@ -8,8 +8,8 @@ import ( "strconv" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/application_roles_gen_integration_test.go b/pkg/sdk/testint/application_roles_gen_integration_test.go index 7aa1f571e8..b0397c1522 100644 --- a/pkg/sdk/testint/application_roles_gen_integration_test.go +++ b/pkg/sdk/testint/application_roles_gen_integration_test.go @@ -5,9 +5,9 @@ import ( "fmt" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/applications_integration_test.go b/pkg/sdk/testint/applications_integration_test.go index c74afc53de..18d7c46d59 100644 --- a/pkg/sdk/testint/applications_integration_test.go +++ b/pkg/sdk/testint/applications_integration_test.go @@ -6,8 +6,8 @@ import ( "strconv" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/comments_integration_test.go b/pkg/sdk/testint/comments_integration_test.go index 18afc97d52..ab950bb327 100644 --- a/pkg/sdk/testint/comments_integration_test.go +++ b/pkg/sdk/testint/comments_integration_test.go @@ -3,8 +3,9 @@ package testint import ( "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/database_role_integration_test.go b/pkg/sdk/testint/database_role_integration_test.go index ae4a0a3446..1f767a306f 100644 --- a/pkg/sdk/testint/database_role_integration_test.go +++ b/pkg/sdk/testint/database_role_integration_test.go @@ -3,9 +3,9 @@ package testint import ( "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/databases_integration_test.go b/pkg/sdk/testint/databases_integration_test.go index 401fe884d9..adbbf4d859 100644 --- a/pkg/sdk/testint/databases_integration_test.go +++ b/pkg/sdk/testint/databases_integration_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/dynamic_table_integration_test.go b/pkg/sdk/testint/dynamic_table_integration_test.go index 99218acf56..8ee3a7b8cd 100644 --- a/pkg/sdk/testint/dynamic_table_integration_test.go +++ b/pkg/sdk/testint/dynamic_table_integration_test.go @@ -5,8 +5,8 @@ import ( "errors" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/event_tables_integration_test.go b/pkg/sdk/testint/event_tables_integration_test.go index 8d6818d3d1..e1b02b8674 100644 --- a/pkg/sdk/testint/event_tables_integration_test.go +++ b/pkg/sdk/testint/event_tables_integration_test.go @@ -4,9 +4,9 @@ import ( "context" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/external_functions_integration_test.go b/pkg/sdk/testint/external_functions_integration_test.go index 207ed15294..a6ff57a3d7 100644 --- a/pkg/sdk/testint/external_functions_integration_test.go +++ b/pkg/sdk/testint/external_functions_integration_test.go @@ -5,8 +5,8 @@ import ( "fmt" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/external_tables_integration_test.go b/pkg/sdk/testint/external_tables_integration_test.go index e4510712a6..723533c897 100644 --- a/pkg/sdk/testint/external_tables_integration_test.go +++ b/pkg/sdk/testint/external_tables_integration_test.go @@ -5,9 +5,9 @@ import ( "fmt" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/failover_groups_integration_test.go b/pkg/sdk/testint/failover_groups_integration_test.go index 992b9cc4ab..428c46c8e0 100644 --- a/pkg/sdk/testint/failover_groups_integration_test.go +++ b/pkg/sdk/testint/failover_groups_integration_test.go @@ -6,9 +6,9 @@ import ( "testing" "time" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "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" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/sdk/testint/file_format_integration_test.go b/pkg/sdk/testint/file_format_integration_test.go index 8fd547add9..a697911fd3 100644 --- a/pkg/sdk/testint/file_format_integration_test.go +++ b/pkg/sdk/testint/file_format_integration_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/functions_integration_test.go b/pkg/sdk/testint/functions_integration_test.go index 10f00c6f0e..9351037f6c 100644 --- a/pkg/sdk/testint/functions_integration_test.go +++ b/pkg/sdk/testint/functions_integration_test.go @@ -7,9 +7,9 @@ import ( "testing" "time" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/grants_integration_test.go b/pkg/sdk/testint/grants_integration_test.go index 6fdccd9154..574d9ba87b 100644 --- a/pkg/sdk/testint/grants_integration_test.go +++ b/pkg/sdk/testint/grants_integration_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/helpers_test.go b/pkg/sdk/testint/helpers_test.go index cf2f9b7ea0..7a1d4af5ec 100644 --- a/pkg/sdk/testint/helpers_test.go +++ b/pkg/sdk/testint/helpers_test.go @@ -9,8 +9,8 @@ import ( "path/filepath" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/managed_accounts_gen_integration_test.go b/pkg/sdk/testint/managed_accounts_gen_integration_test.go index f8d4e60dfa..0a87fe71b0 100644 --- a/pkg/sdk/testint/managed_accounts_gen_integration_test.go +++ b/pkg/sdk/testint/managed_accounts_gen_integration_test.go @@ -4,10 +4,10 @@ import ( "strings" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "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/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/masking_policy_integration_test.go b/pkg/sdk/testint/masking_policy_integration_test.go index 6c50bb94a1..d0a3459598 100644 --- a/pkg/sdk/testint/masking_policy_integration_test.go +++ b/pkg/sdk/testint/masking_policy_integration_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/materialized_views_gen_integration_test.go b/pkg/sdk/testint/materialized_views_gen_integration_test.go index 4a3982936a..19bee276c0 100644 --- a/pkg/sdk/testint/materialized_views_gen_integration_test.go +++ b/pkg/sdk/testint/materialized_views_gen_integration_test.go @@ -5,9 +5,9 @@ import ( "fmt" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/network_policies_gen_integration_test.go b/pkg/sdk/testint/network_policies_gen_integration_test.go index 1ec5e3a3d7..1397f80925 100644 --- a/pkg/sdk/testint/network_policies_gen_integration_test.go +++ b/pkg/sdk/testint/network_policies_gen_integration_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/network_rule_gen_integration_test.go b/pkg/sdk/testint/network_rule_gen_integration_test.go index 011379ec16..cadd079645 100644 --- a/pkg/sdk/testint/network_rule_gen_integration_test.go +++ b/pkg/sdk/testint/network_rule_gen_integration_test.go @@ -4,8 +4,8 @@ import ( "errors" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/password_policy_integration_test.go b/pkg/sdk/testint/password_policy_integration_test.go index c11a18aca9..454505e76b 100644 --- a/pkg/sdk/testint/password_policy_integration_test.go +++ b/pkg/sdk/testint/password_policy_integration_test.go @@ -4,8 +4,8 @@ import ( "errors" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/pipes_integration_test.go b/pkg/sdk/testint/pipes_integration_test.go index 22cfe4794d..aef2eba5bc 100644 --- a/pkg/sdk/testint/pipes_integration_test.go +++ b/pkg/sdk/testint/pipes_integration_test.go @@ -5,8 +5,9 @@ import ( "fmt" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/policy_references_integration_test.go b/pkg/sdk/testint/policy_references_integration_test.go index c7c4b0b722..6871d87f6a 100644 --- a/pkg/sdk/testint/policy_references_integration_test.go +++ b/pkg/sdk/testint/policy_references_integration_test.go @@ -3,8 +3,8 @@ package testint import ( "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/procedures_integration_test.go b/pkg/sdk/testint/procedures_integration_test.go index 6fc3554e4a..74e08fa043 100644 --- a/pkg/sdk/testint/procedures_integration_test.go +++ b/pkg/sdk/testint/procedures_integration_test.go @@ -5,9 +5,9 @@ import ( "fmt" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/replication_functions_integration_test.go b/pkg/sdk/testint/replication_functions_integration_test.go index 979ec15f78..dca9c0ded1 100644 --- a/pkg/sdk/testint/replication_functions_integration_test.go +++ b/pkg/sdk/testint/replication_functions_integration_test.go @@ -3,8 +3,8 @@ package testint import ( "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/resource_monitors_integration_test.go b/pkg/sdk/testint/resource_monitors_integration_test.go index 106a118f85..2eb3ff8c50 100644 --- a/pkg/sdk/testint/resource_monitors_integration_test.go +++ b/pkg/sdk/testint/resource_monitors_integration_test.go @@ -4,8 +4,8 @@ import ( "testing" "time" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/roles_integration_test.go b/pkg/sdk/testint/roles_integration_test.go index ec90885608..04a863603c 100644 --- a/pkg/sdk/testint/roles_integration_test.go +++ b/pkg/sdk/testint/roles_integration_test.go @@ -3,8 +3,8 @@ package testint import ( "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/row_access_policies_gen_integration_test.go b/pkg/sdk/testint/row_access_policies_gen_integration_test.go index 033026d806..4d7892357d 100644 --- a/pkg/sdk/testint/row_access_policies_gen_integration_test.go +++ b/pkg/sdk/testint/row_access_policies_gen_integration_test.go @@ -6,9 +6,9 @@ import ( "strings" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/schemas_integration_test.go b/pkg/sdk/testint/schemas_integration_test.go index 82a4845e8b..d50fb099cb 100644 --- a/pkg/sdk/testint/schemas_integration_test.go +++ b/pkg/sdk/testint/schemas_integration_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/sequences_integration_test.go b/pkg/sdk/testint/sequences_integration_test.go index e484782074..63cb3a6ac9 100644 --- a/pkg/sdk/testint/sequences_integration_test.go +++ b/pkg/sdk/testint/sequences_integration_test.go @@ -4,9 +4,9 @@ import ( "errors" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/session_policies_gen_integration_test.go b/pkg/sdk/testint/session_policies_gen_integration_test.go index 1f70f2cf15..61b1174d1d 100644 --- a/pkg/sdk/testint/session_policies_gen_integration_test.go +++ b/pkg/sdk/testint/session_policies_gen_integration_test.go @@ -3,9 +3,9 @@ package testint import ( "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/setup_test.go b/pkg/sdk/testint/setup_test.go index b1077ca6ee..2abd2ee805 100644 --- a/pkg/sdk/testint/setup_test.go +++ b/pkg/sdk/testint/setup_test.go @@ -9,9 +9,9 @@ import ( "time" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testprofiles" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/snowflakedb/gosnowflake" ) diff --git a/pkg/sdk/testint/shares_integration_test.go b/pkg/sdk/testint/shares_integration_test.go index 40074a383f..792d142425 100644 --- a/pkg/sdk/testint/shares_integration_test.go +++ b/pkg/sdk/testint/shares_integration_test.go @@ -3,8 +3,8 @@ package testint import ( "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/stages_gen_integration_test.go b/pkg/sdk/testint/stages_gen_integration_test.go index 36bb47ddb5..c1131cc0d7 100644 --- a/pkg/sdk/testint/stages_gen_integration_test.go +++ b/pkg/sdk/testint/stages_gen_integration_test.go @@ -5,9 +5,9 @@ import ( "fmt" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "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/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/streamlits_integration_test.go b/pkg/sdk/testint/streamlits_integration_test.go index a262885e03..f73fc5c34d 100644 --- a/pkg/sdk/testint/streamlits_integration_test.go +++ b/pkg/sdk/testint/streamlits_integration_test.go @@ -4,9 +4,9 @@ import ( "errors" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/streams_gen_integration_test.go b/pkg/sdk/testint/streams_gen_integration_test.go index 3b1074f47c..29d74ea7a4 100644 --- a/pkg/sdk/testint/streams_gen_integration_test.go +++ b/pkg/sdk/testint/streams_gen_integration_test.go @@ -5,11 +5,9 @@ import ( "fmt" "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" - + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/system_functions_integration_test.go b/pkg/sdk/testint/system_functions_integration_test.go index 0f87be17e0..9ec69ed169 100644 --- a/pkg/sdk/testint/system_functions_integration_test.go +++ b/pkg/sdk/testint/system_functions_integration_test.go @@ -5,8 +5,8 @@ import ( "fmt" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/tables_integration_test.go b/pkg/sdk/testint/tables_integration_test.go index 5e0fa22cdb..f0d25a4678 100644 --- a/pkg/sdk/testint/tables_integration_test.go +++ b/pkg/sdk/testint/tables_integration_test.go @@ -8,9 +8,9 @@ import ( "strings" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/tags_integration_test.go b/pkg/sdk/testint/tags_integration_test.go index 3d638c006f..6d83d606e5 100644 --- a/pkg/sdk/testint/tags_integration_test.go +++ b/pkg/sdk/testint/tags_integration_test.go @@ -5,9 +5,9 @@ import ( "errors" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/tasks_gen_integration_test.go b/pkg/sdk/testint/tasks_gen_integration_test.go index 81f5f068a7..d3c54e174b 100644 --- a/pkg/sdk/testint/tasks_gen_integration_test.go +++ b/pkg/sdk/testint/tasks_gen_integration_test.go @@ -4,8 +4,8 @@ import ( "errors" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/users_integration_test.go b/pkg/sdk/testint/users_integration_test.go index 58d598c5b0..c3ddde8dd1 100644 --- a/pkg/sdk/testint/users_integration_test.go +++ b/pkg/sdk/testint/users_integration_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/testint/views_gen_integration_test.go b/pkg/sdk/testint/views_gen_integration_test.go index 0b1c0568e9..15359c0564 100644 --- a/pkg/sdk/testint/views_gen_integration_test.go +++ b/pkg/sdk/testint/views_gen_integration_test.go @@ -5,9 +5,9 @@ import ( "fmt" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/sdk/users_test.go b/pkg/sdk/users_test.go index 67a5334a9b..03269d42c5 100644 --- a/pkg/sdk/users_test.go +++ b/pkg/sdk/users_test.go @@ -3,7 +3,7 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestUserCreate(t *testing.T) { diff --git a/pkg/sdk/validations_test.go b/pkg/sdk/validations_test.go index 3725c52661..cc1027b0fd 100644 --- a/pkg/sdk/validations_test.go +++ b/pkg/sdk/validations_test.go @@ -3,7 +3,7 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/stretchr/testify/assert" ) From c0d506e5baba5098df96d39963595c4fd3081fb4 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Thu, 18 Apr 2024 15:23:06 +0200 Subject: [PATCH 2/3] Use schema helpers --- pkg/acceptance/helpers/database_client.go | 14 ++++++++ pkg/acceptance/helpers/schema_client.go | 29 ++++++++++++---- pkg/resources/database_acceptance_test.go | 9 +---- pkg/resources/schema_acceptance_test.go | 31 ++--------------- pkg/sdk/testint/alerts_integration_test.go | 2 +- .../context_functions_integration_test.go | 2 +- pkg/sdk/testint/databases_integration_test.go | 4 +-- .../testint/dynamic_table_integration_test.go | 2 +- .../testint/event_tables_integration_test.go | 2 +- .../external_tables_integration_test.go | 2 +- .../testint/file_format_integration_test.go | 4 +-- pkg/sdk/testint/functions_integration_test.go | 2 +- pkg/sdk/testint/grants_integration_test.go | 8 ++--- pkg/sdk/testint/helpers_test.go | 33 +++---------------- .../masking_policy_integration_test.go | 2 +- ...materialized_views_gen_integration_test.go | 2 +- .../network_rule_gen_integration_test.go | 2 +- .../password_policy_integration_test.go | 2 +- pkg/sdk/testint/pipes_integration_test.go | 4 +-- .../testint/procedures_integration_test.go | 2 +- ...ow_access_policies_gen_integration_test.go | 2 +- pkg/sdk/testint/schemas_integration_test.go | 16 ++++----- pkg/sdk/testint/sequences_integration_test.go | 2 +- pkg/sdk/testint/sessions_integration_test.go | 2 +- .../testint/stages_gen_integration_test.go | 2 +- .../testint/streamlits_integration_test.go | 2 +- .../testint/streams_gen_integration_test.go | 4 +-- .../system_functions_integration_test.go | 4 +-- pkg/sdk/testint/tables_integration_test.go | 2 +- pkg/sdk/testint/tags_integration_test.go | 4 +-- pkg/sdk/testint/tasks_gen_integration_test.go | 2 +- pkg/sdk/testint/views_gen_integration_test.go | 4 +-- 32 files changed, 88 insertions(+), 116 deletions(-) diff --git a/pkg/acceptance/helpers/database_client.go b/pkg/acceptance/helpers/database_client.go index 072afff36c..35cd340e9b 100644 --- a/pkg/acceptance/helpers/database_client.go +++ b/pkg/acceptance/helpers/database_client.go @@ -83,3 +83,17 @@ func (d *DatabaseClient) CreateSecondaryDatabaseWithOptions(t *testing.T, id sdk require.NoError(t, err) } } + +func (d *DatabaseClient) UpdateDataRetentionTime(t *testing.T, id sdk.AccountObjectIdentifier, days int) func() { + t.Helper() + ctx := context.Background() + + return func() { + err := d.client().Alter(ctx, id, &sdk.AlterDatabaseOptions{ + Set: &sdk.DatabaseSet{ + DataRetentionTimeInDays: sdk.Int(days), + }, + }) + require.NoError(t, err) + } +} diff --git a/pkg/acceptance/helpers/schema_client.go b/pkg/acceptance/helpers/schema_client.go index 7e176c33db..780d310822 100644 --- a/pkg/acceptance/helpers/schema_client.go +++ b/pkg/acceptance/helpers/schema_client.go @@ -2,7 +2,6 @@ package helpers import ( "context" - "errors" "testing" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" @@ -37,13 +36,31 @@ func (c *SchemaClient) CreateSchemaWithIdentifier(t *testing.T, database *sdk.Da require.NoError(t, err) schema, err := c.client().ShowByID(ctx, sdk.NewDatabaseObjectIdentifier(database.Name, name)) require.NoError(t, err) - return schema, func() { - err := c.client().Drop(ctx, schemaID, nil) - if errors.Is(err, sdk.ErrObjectNotExistOrAuthorized) { - return - } + return schema, c.DropSchemaFunc(t, schemaID) +} + +func (c *SchemaClient) DropSchemaFunc(t *testing.T, id sdk.DatabaseObjectIdentifier) func() { + t.Helper() + ctx := context.Background() + + return func() { + err := c.client().Drop(ctx, id, &sdk.DropSchemaOptions{IfExists: sdk.Bool(true)}) require.NoError(t, err) err = c.context.client.Sessions.UseSchema(ctx, sdk.NewDatabaseObjectIdentifier(c.context.database, c.context.schema)) require.NoError(t, err) } } + +func (c *SchemaClient) UpdateDataRetentionTime(t *testing.T, id sdk.DatabaseObjectIdentifier, days int) func() { + t.Helper() + ctx := context.Background() + + return func() { + err := c.client().Alter(ctx, id, &sdk.AlterSchemaOptions{ + Set: &sdk.SchemaSet{ + DataRetentionTimeInDays: sdk.Int(days), + }, + }) + require.NoError(t, err) + } +} diff --git a/pkg/resources/database_acceptance_test.go b/pkg/resources/database_acceptance_test.go index 9b07ccb1b2..9eed2a565b 100644 --- a/pkg/resources/database_acceptance_test.go +++ b/pkg/resources/database_acceptance_test.go @@ -306,14 +306,7 @@ func TestAcc_Database_DefaultDataRetentionTime_SetOutsideOfTerraform(t *testing. ), }, { - PreConfig: func() { - err := client.Databases.Alter(context.Background(), id, &sdk.AlterDatabaseOptions{ - Set: &sdk.DatabaseSet{ - DataRetentionTimeInDays: sdk.Int(20), - }, - }) - require.NoError(t, err) - }, + PreConfig: acc.TestClient().Database.UpdateDataRetentionTime(t, id, 20), ConfigDirectory: acc.ConfigurationDirectory("TestAcc_Database_DefaultDataRetentionTime/WithoutDataRetentionSet"), ConfigVariables: configVariablesWithoutDatabaseDataRetentionTime(), Check: resource.ComposeTestCheckFunc( diff --git a/pkg/resources/schema_acceptance_test.go b/pkg/resources/schema_acceptance_test.go index dd79c75e6d..e9cdf0f846 100644 --- a/pkg/resources/schema_acceptance_test.go +++ b/pkg/resources/schema_acceptance_test.go @@ -19,7 +19,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/plancheck" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-plugin-testing/tfversion" - "github.com/stretchr/testify/require" ) func TestAcc_Schema(t *testing.T) { @@ -289,7 +288,7 @@ func TestAcc_Schema_DefaultDataRetentionTime_SetOutsideOfTerraform(t *testing.T) ), }, { - PreConfig: setSchemaDataRetentionTime(t, id, 20), + PreConfig: acc.TestClient().Schema.UpdateDataRetentionTime(t, id, 20), ConfigDirectory: acc.ConfigurationDirectory("TestAcc_Schema_DefaultDataRetentionTime/WithoutDataRetentionSet"), ConfigVariables: configVariablesWithoutSchemaDataRetentionTime(5), Check: resource.ComposeTestCheckFunc( @@ -335,7 +334,7 @@ func TestAcc_Schema_RemoveDatabaseOutsideOfTerraform(t *testing.T) { }, { PreConfig: func() { - removeSchemaOutsideOfTerraform(t, acc.TestDatabaseName, schemaName) + acc.TestClient().Schema.DropSchemaFunc(t, sdk.NewDatabaseObjectIdentifier(acc.TestDatabaseName, schemaName))() }, RefreshState: true, ExpectNonEmptyPlan: true, @@ -425,29 +424,3 @@ func checkDatabaseAndSchemaDataRetentionTime(id sdk.DatabaseObjectIdentifier, ex return nil } } - -func setSchemaDataRetentionTime(t *testing.T, id sdk.DatabaseObjectIdentifier, days int) func() { - t.Helper() - - return func() { - client := acc.Client(t) - ctx := context.Background() - - err := client.Schemas.Alter(ctx, id, &sdk.AlterSchemaOptions{ - Set: &sdk.SchemaSet{ - DataRetentionTimeInDays: sdk.Int(days), - }, - }) - require.NoError(t, err) - } -} - -func removeSchemaOutsideOfTerraform(t *testing.T, databaseName string, schemaName string) { - t.Helper() - - client := acc.Client(t) - ctx := context.Background() - - err := client.Schemas.Drop(ctx, sdk.NewDatabaseObjectIdentifier(databaseName, schemaName), new(sdk.DropSchemaOptions)) - require.NoError(t, err) -} diff --git a/pkg/sdk/testint/alerts_integration_test.go b/pkg/sdk/testint/alerts_integration_test.go index 53b1c690d2..a8f91a1a23 100644 --- a/pkg/sdk/testint/alerts_integration_test.go +++ b/pkg/sdk/testint/alerts_integration_test.go @@ -406,7 +406,7 @@ func TestInt_AlertsShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/context_functions_integration_test.go b/pkg/sdk/testint/context_functions_integration_test.go index 29298da63f..5f7044e1d1 100644 --- a/pkg/sdk/testint/context_functions_integration_test.go +++ b/pkg/sdk/testint/context_functions_integration_test.go @@ -82,7 +82,7 @@ func TestInt_CurrentSchema(t *testing.T) { // new database and schema created on purpose databaseTest, databaseCleanup := testClientHelper().Database.CreateDatabase(t) t.Cleanup(databaseCleanup) - schemaTest, schemaCleanup := createSchema(t, client, databaseTest) + schemaTest, schemaCleanup := testClientHelper().Schema.CreateSchema(t, databaseTest) t.Cleanup(schemaCleanup) err := client.Sessions.UseSchema(ctx, schemaTest.ID()) require.NoError(t, err) diff --git a/pkg/sdk/testint/databases_integration_test.go b/pkg/sdk/testint/databases_integration_test.go index adbbf4d859..07ad1f270a 100644 --- a/pkg/sdk/testint/databases_integration_test.go +++ b/pkg/sdk/testint/databases_integration_test.go @@ -56,7 +56,7 @@ func TestInt_DatabasesCreate(t *testing.T) { // new database and schema created on purpose databaseTest, databaseCleanup := testClientHelper().Database.CreateDatabase(t) t.Cleanup(databaseCleanup) - schemaTest, schemaCleanup := createSchema(t, client, databaseTest) + schemaTest, schemaCleanup := testClientHelper().Schema.CreateSchema(t, databaseTest) t.Cleanup(schemaCleanup) tagTest, tagCleanup := createTag(t, client, databaseTest, schemaTest) t.Cleanup(tagCleanup) @@ -198,7 +198,7 @@ func TestInt_DatabasesDescribe(t *testing.T) { // new database and schema created on purpose databaseTest, databaseCleanup := testClientHelper().Database.CreateDatabase(t) t.Cleanup(databaseCleanup) - schemaTest, schemaCleanup := createSchema(t, client, databaseTest) + schemaTest, schemaCleanup := testClientHelper().Schema.CreateSchema(t, databaseTest) t.Cleanup(schemaCleanup) ctx := testContext(t) databaseDetails, err := client.Databases.Describe(ctx, databaseTest.ID()) diff --git a/pkg/sdk/testint/dynamic_table_integration_test.go b/pkg/sdk/testint/dynamic_table_integration_test.go index 8ee3a7b8cd..295256e020 100644 --- a/pkg/sdk/testint/dynamic_table_integration_test.go +++ b/pkg/sdk/testint/dynamic_table_integration_test.go @@ -221,7 +221,7 @@ func TestInt_DynamicTablesShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/event_tables_integration_test.go b/pkg/sdk/testint/event_tables_integration_test.go index e1b02b8674..862ba950d3 100644 --- a/pkg/sdk/testint/event_tables_integration_test.go +++ b/pkg/sdk/testint/event_tables_integration_test.go @@ -299,7 +299,7 @@ func TestInt_EventTableShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/external_tables_integration_test.go b/pkg/sdk/testint/external_tables_integration_test.go index 723533c897..3e1da02a62 100644 --- a/pkg/sdk/testint/external_tables_integration_test.go +++ b/pkg/sdk/testint/external_tables_integration_test.go @@ -447,7 +447,7 @@ func TestInt_ExternalTablesShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/file_format_integration_test.go b/pkg/sdk/testint/file_format_integration_test.go index a697911fd3..a55166ff44 100644 --- a/pkg/sdk/testint/file_format_integration_test.go +++ b/pkg/sdk/testint/file_format_integration_test.go @@ -506,7 +506,7 @@ func TestInt_FileFormatsShowById(t *testing.T) { // new database and schema created on purpose databaseTest2, cleanupDatabase2 := testClientHelper().Database.CreateDatabase(t) t.Cleanup(cleanupDatabase2) - schemaTest2, cleanupSchema2 := createSchema(t, client, databaseTest2) + schemaTest2, cleanupSchema2 := testClientHelper().Schema.CreateSchema(t, databaseTest2) t.Cleanup(cleanupSchema2) t.Run("show format in different schema", func(t *testing.T) { @@ -549,7 +549,7 @@ func TestInt_FileFormatsShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/functions_integration_test.go b/pkg/sdk/testint/functions_integration_test.go index 9351037f6c..f334a4344c 100644 --- a/pkg/sdk/testint/functions_integration_test.go +++ b/pkg/sdk/testint/functions_integration_test.go @@ -492,7 +492,7 @@ func TestInt_FunctionsShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/grants_integration_test.go b/pkg/sdk/testint/grants_integration_test.go index 574d9ba87b..b7801eb92a 100644 --- a/pkg/sdk/testint/grants_integration_test.go +++ b/pkg/sdk/testint/grants_integration_test.go @@ -235,7 +235,7 @@ func TestInt_GrantAndRevokePrivilegesToAccountRole(t *testing.T) { }) t.Run("grant and revoke on all pipes", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, itc.client, testDb(t), random.AlphaN(20)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, testDb(t), random.AlphaN(20)) t.Cleanup(schemaCleanup) table, tableCleanup := createTable(t, itc.client, testDb(t), schema) @@ -295,7 +295,7 @@ func TestInt_GrantAndRevokePrivilegesToAccountRole(t *testing.T) { }) t.Run("grant and revoke on all pipes with multiple errors", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, itc.client, testDb(t), random.AlphaN(20)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, testDb(t), random.AlphaN(20)) t.Cleanup(schemaCleanup) table, tableCleanup := createTable(t, itc.client, testDb(t), schema) @@ -580,7 +580,7 @@ func TestInt_GrantAndRevokePrivilegesToDatabaseRole(t *testing.T) { }) t.Run("grant and revoke on all pipes", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, itc.client, testDb(t), random.AlphaN(20)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, testDb(t), random.AlphaN(20)) t.Cleanup(schemaCleanup) table, tableCleanup := createTable(t, itc.client, testDb(t), schema) @@ -640,7 +640,7 @@ func TestInt_GrantAndRevokePrivilegesToDatabaseRole(t *testing.T) { }) t.Run("grant and revoke on all pipes with multiple errors", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, itc.client, testDb(t), random.AlphaN(20)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, testDb(t), random.AlphaN(20)) t.Cleanup(schemaCleanup) table, tableCleanup := createTable(t, itc.client, testDb(t), schema) diff --git a/pkg/sdk/testint/helpers_test.go b/pkg/sdk/testint/helpers_test.go index 7a1d4af5ec..d1c88e7cda 100644 --- a/pkg/sdk/testint/helpers_test.go +++ b/pkg/sdk/testint/helpers_test.go @@ -3,7 +3,6 @@ package testint import ( "context" "database/sql" - "errors" "fmt" "os" "path/filepath" @@ -46,30 +45,6 @@ func useWarehouse(t *testing.T, client *sdk.Client, warehouseID sdk.AccountObjec } } -func createSchema(t *testing.T, client *sdk.Client, database *sdk.Database) (*sdk.Schema, func()) { - t.Helper() - return createSchemaWithIdentifier(t, client, database, random.StringRange(8, 28)) -} - -func createSchemaWithIdentifier(t *testing.T, client *sdk.Client, database *sdk.Database, name string) (*sdk.Schema, func()) { - t.Helper() - ctx := context.Background() - schemaID := sdk.NewDatabaseObjectIdentifier(database.Name, name) - err := client.Schemas.Create(ctx, schemaID, nil) - require.NoError(t, err) - schema, err := client.Schemas.ShowByID(ctx, sdk.NewDatabaseObjectIdentifier(database.Name, name)) - require.NoError(t, err) - return schema, func() { - err := client.Schemas.Drop(ctx, schemaID, nil) - if errors.Is(err, sdk.ErrObjectNotExistOrAuthorized) { - return - } - require.NoError(t, err) - err = client.Sessions.UseSchema(ctx, testSchema(t).ID()) - require.NoError(t, err) - } -} - func createWarehouse(t *testing.T, client *sdk.Client) (*sdk.Warehouse, func()) { t.Helper() return createWarehouseWithOptions(t, client, &sdk.CreateWarehouseOptions{}) @@ -162,7 +137,7 @@ func createDynamicTableWithOptions(t *testing.T, client *sdk.Client, warehouse * } var schemaCleanup func() if schema == nil { - schema, schemaCleanup = createSchema(t, client, database) + schema, schemaCleanup = testClientHelper().Schema.CreateSchema(t, database) } var tableCleanup func() if table == nil { @@ -297,7 +272,7 @@ func createPasswordPolicyWithOptions(t *testing.T, client *sdk.Client, database } var schemaCleanup func() if schema == nil { - schema, schemaCleanup = createSchema(t, client, database) + schema, schemaCleanup = testClientHelper().Schema.CreateSchema(t, database) } name := random.UUID() id := sdk.NewSchemaObjectIdentifier(schema.DatabaseName, schema.Name, name) @@ -434,7 +409,7 @@ func createMaskingPolicyWithOptions(t *testing.T, client *sdk.Client, database * } var schemaCleanup func() if schema == nil { - schema, schemaCleanup = createSchema(t, client, database) + schema, schemaCleanup = testClientHelper().Schema.CreateSchema(t, database) } name := random.String() id := sdk.NewSchemaObjectIdentifier(schema.DatabaseName, schema.Name, name) @@ -481,7 +456,7 @@ func createAlertWithOptions(t *testing.T, client *sdk.Client, database *sdk.Data } var schemaCleanup func() if schema == nil { - schema, schemaCleanup = createSchema(t, client, database) + schema, schemaCleanup = testClientHelper().Schema.CreateSchema(t, database) } var warehouseCleanup func() if warehouse == nil { diff --git a/pkg/sdk/testint/masking_policy_integration_test.go b/pkg/sdk/testint/masking_policy_integration_test.go index d0a3459598..5dc9819594 100644 --- a/pkg/sdk/testint/masking_policy_integration_test.go +++ b/pkg/sdk/testint/masking_policy_integration_test.go @@ -418,7 +418,7 @@ func TestInt_MaskingPoliciesShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/materialized_views_gen_integration_test.go b/pkg/sdk/testint/materialized_views_gen_integration_test.go index 19bee276c0..6384ec37a2 100644 --- a/pkg/sdk/testint/materialized_views_gen_integration_test.go +++ b/pkg/sdk/testint/materialized_views_gen_integration_test.go @@ -440,7 +440,7 @@ func TestInt_MaterializedViewsShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/network_rule_gen_integration_test.go b/pkg/sdk/testint/network_rule_gen_integration_test.go index cadd079645..64c65f374f 100644 --- a/pkg/sdk/testint/network_rule_gen_integration_test.go +++ b/pkg/sdk/testint/network_rule_gen_integration_test.go @@ -164,7 +164,7 @@ func TestInt_NetworkRulesShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/password_policy_integration_test.go b/pkg/sdk/testint/password_policy_integration_test.go index 454505e76b..1c2f7e4cc1 100644 --- a/pkg/sdk/testint/password_policy_integration_test.go +++ b/pkg/sdk/testint/password_policy_integration_test.go @@ -336,7 +336,7 @@ func TestInt_PasswordPoliciesShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/pipes_integration_test.go b/pkg/sdk/testint/pipes_integration_test.go index aef2eba5bc..763498d39c 100644 --- a/pkg/sdk/testint/pipes_integration_test.go +++ b/pkg/sdk/testint/pipes_integration_test.go @@ -25,7 +25,7 @@ func TestInt_CreatePipeWithStrangeSchemaName(t *testing.T) { schemaIdentifier := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, "tcK1>AJ+") // creating a new schema on purpose - schema, schemaCleanup := createSchemaWithIdentifier(t, itc.client, testDb(t), schemaIdentifier.Name()) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, testDb(t), schemaIdentifier.Name()) t.Cleanup(schemaCleanup) table, tableCleanup := createTable(t, itc.client, testDb(t), schema) @@ -384,7 +384,7 @@ func TestInt_PipesShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/procedures_integration_test.go b/pkg/sdk/testint/procedures_integration_test.go index 74e08fa043..dbd386982e 100644 --- a/pkg/sdk/testint/procedures_integration_test.go +++ b/pkg/sdk/testint/procedures_integration_test.go @@ -1007,7 +1007,7 @@ func TestInt_ProceduresShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/row_access_policies_gen_integration_test.go b/pkg/sdk/testint/row_access_policies_gen_integration_test.go index 4d7892357d..6ce243872b 100644 --- a/pkg/sdk/testint/row_access_policies_gen_integration_test.go +++ b/pkg/sdk/testint/row_access_policies_gen_integration_test.go @@ -340,7 +340,7 @@ func TestInt_RowAccessPoliciesShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/schemas_integration_test.go b/pkg/sdk/testint/schemas_integration_test.go index d50fb099cb..2abfe6d263 100644 --- a/pkg/sdk/testint/schemas_integration_test.go +++ b/pkg/sdk/testint/schemas_integration_test.go @@ -15,7 +15,7 @@ func TestInt_SchemasCreate(t *testing.T) { ctx := testContext(t) // new schema created on purpose - schema, cleanupSchema := createSchema(t, client, testDb(t)) + schema, cleanupSchema := testClientHelper().Schema.CreateSchema(t, testDb(t)) t.Cleanup(cleanupSchema) t.Run("replace", func(t *testing.T) { @@ -118,7 +118,7 @@ func TestInt_SchemasAlter(t *testing.T) { t.Run("rename to", func(t *testing.T) { // new schema created on purpose - schema, _ := createSchema(t, client, testDb(t)) + schema, _ := testClientHelper().Schema.CreateSchema(t, testDb(t)) t.Cleanup(func() { err := client.Sessions.UseSchema(ctx, testSchema(t).ID()) require.NoError(t, err) @@ -139,9 +139,9 @@ func TestInt_SchemasAlter(t *testing.T) { t.Run("swap with", func(t *testing.T) { // new schemas created on purpose - schema, cleanupSchema := createSchema(t, client, testDb(t)) + schema, cleanupSchema := testClientHelper().Schema.CreateSchema(t, testDb(t)) t.Cleanup(cleanupSchema) - swapSchema, cleanupSwapSchema := createSchema(t, client, testDb(t)) + swapSchema, cleanupSwapSchema := testClientHelper().Schema.CreateSchema(t, testDb(t)) t.Cleanup(cleanupSwapSchema) table, _ := createTable(t, client, testDb(t), schema) @@ -165,7 +165,7 @@ func TestInt_SchemasAlter(t *testing.T) { t.Run("set", func(t *testing.T) { // new schema created on purpose - schema, cleanupSchema := createSchema(t, client, testDb(t)) + schema, cleanupSchema := testClientHelper().Schema.CreateSchema(t, testDb(t)) t.Cleanup(cleanupSchema) comment := random.Comment() @@ -279,7 +279,7 @@ func TestInt_SchemasAlter(t *testing.T) { t.Run("enable managed access", func(t *testing.T) { // new schema created on purpose - schema, cleanupSchema := createSchema(t, client, testDb(t)) + schema, cleanupSchema := testClientHelper().Schema.CreateSchema(t, testDb(t)) t.Cleanup(cleanupSchema) err := client.Schemas.Alter(ctx, schema.ID(), &sdk.AlterSchemaOptions{ @@ -299,7 +299,7 @@ func TestInt_SchemasShow(t *testing.T) { ctx := testContext(t) // new schema created on purpose - schema, cleanupSchema := createSchema(t, client, testDb(t)) + schema, cleanupSchema := testClientHelper().Schema.CreateSchema(t, testDb(t)) t.Cleanup(cleanupSchema) t.Run("no options", func(t *testing.T) { @@ -341,7 +341,7 @@ func TestInt_SchemasDrop(t *testing.T) { ctx := testContext(t) // new schema created on purpose - schema, _ := createSchema(t, client, testDb(t)) + schema, _ := testClientHelper().Schema.CreateSchema(t, testDb(t)) t.Cleanup(func() { err := client.Sessions.UseSchema(ctx, testSchema(t).ID()) require.NoError(t, err) diff --git a/pkg/sdk/testint/sequences_integration_test.go b/pkg/sdk/testint/sequences_integration_test.go index 63cb3a6ac9..8790209052 100644 --- a/pkg/sdk/testint/sequences_integration_test.go +++ b/pkg/sdk/testint/sequences_integration_test.go @@ -197,7 +197,7 @@ func TestInt_SequencesShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/sessions_integration_test.go b/pkg/sdk/testint/sessions_integration_test.go index 555dd785b5..8a2abc806a 100644 --- a/pkg/sdk/testint/sessions_integration_test.go +++ b/pkg/sdk/testint/sessions_integration_test.go @@ -145,7 +145,7 @@ func TestInt_UseSchema(t *testing.T) { // new database and schema created on purpose database, databaseCleanup := testClientHelper().Database.CreateDatabase(t) t.Cleanup(databaseCleanup) - schema, schemaCleanup := createSchema(t, client, database) + schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t, database) t.Cleanup(schemaCleanup) err := client.Sessions.UseSchema(ctx, schema.ID()) require.NoError(t, err) diff --git a/pkg/sdk/testint/stages_gen_integration_test.go b/pkg/sdk/testint/stages_gen_integration_test.go index c1131cc0d7..765f06eab2 100644 --- a/pkg/sdk/testint/stages_gen_integration_test.go +++ b/pkg/sdk/testint/stages_gen_integration_test.go @@ -580,7 +580,7 @@ func TestInt_StagesShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/streamlits_integration_test.go b/pkg/sdk/testint/streamlits_integration_test.go index f73fc5c34d..41ff783687 100644 --- a/pkg/sdk/testint/streamlits_integration_test.go +++ b/pkg/sdk/testint/streamlits_integration_test.go @@ -318,7 +318,7 @@ func TestInt_StreamlitsShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/streams_gen_integration_test.go b/pkg/sdk/testint/streams_gen_integration_test.go index 29d74ea7a4..cd43f38d27 100644 --- a/pkg/sdk/testint/streams_gen_integration_test.go +++ b/pkg/sdk/testint/streams_gen_integration_test.go @@ -18,7 +18,7 @@ func TestInt_Streams(t *testing.T) { db := testDb(t) - schema, cleanupSchema := createSchema(t, client, db) + schema, cleanupSchema := testClientHelper().Schema.CreateSchema(t, db) t.Cleanup(cleanupSchema) assertStream := func(t *testing.T, s *sdk.Stream, id sdk.SchemaObjectIdentifier, sourceType string, mode string) { @@ -450,7 +450,7 @@ func TestInt_StreamsShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/system_functions_integration_test.go b/pkg/sdk/testint/system_functions_integration_test.go index 9ec69ed169..d01c85c437 100644 --- a/pkg/sdk/testint/system_functions_integration_test.go +++ b/pkg/sdk/testint/system_functions_integration_test.go @@ -50,7 +50,7 @@ func TestInt_GetTag(t *testing.T) { func TestInt_PipeStatus(t *testing.T) { client := testClient(t) - schema, schemaCleanup := createSchemaWithIdentifier(t, itc.client, testDb(t), random.AlphaN(20)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, testDb(t), random.AlphaN(20)) t.Cleanup(schemaCleanup) table, tableCleanup := createTable(t, itc.client, testDb(t), schema) @@ -99,7 +99,7 @@ func TestInt_PipeForceResume(t *testing.T) { role, roleCleanup := createRole(t, client) t.Cleanup(roleCleanup) - schema, schemaCleanup := createSchemaWithIdentifier(t, itc.client, testDb(t), random.AlphaN(20)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, testDb(t), random.AlphaN(20)) t.Cleanup(schemaCleanup) table, tableCleanup := createTable(t, itc.client, testDb(t), schema) diff --git a/pkg/sdk/testint/tables_integration_test.go b/pkg/sdk/testint/tables_integration_test.go index f0d25a4678..34a6d25664 100644 --- a/pkg/sdk/testint/tables_integration_test.go +++ b/pkg/sdk/testint/tables_integration_test.go @@ -1025,7 +1025,7 @@ func TestInt_TablesShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/tags_integration_test.go b/pkg/sdk/testint/tags_integration_test.go index 6d83d606e5..068aae74c1 100644 --- a/pkg/sdk/testint/tags_integration_test.go +++ b/pkg/sdk/testint/tags_integration_test.go @@ -18,7 +18,7 @@ func TestInt_Tags(t *testing.T) { databaseTest, databaseCleanup := testClientHelper().Database.CreateDatabase(t) t.Cleanup(databaseCleanup) - schemaTest, schemaCleanup := createSchema(t, client, databaseTest) + schemaTest, schemaCleanup := testClientHelper().Schema.CreateSchema(t, databaseTest) t.Cleanup(schemaCleanup) assertTagHandle := func(t *testing.T, tag *sdk.Tag, expectedName string, expectedComment string, expectedAllowedValues []string) { @@ -302,7 +302,7 @@ func TestInt_TagsShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/tasks_gen_integration_test.go b/pkg/sdk/testint/tasks_gen_integration_test.go index d3c54e174b..03082b0908 100644 --- a/pkg/sdk/testint/tasks_gen_integration_test.go +++ b/pkg/sdk/testint/tasks_gen_integration_test.go @@ -751,7 +751,7 @@ func TestInt_TasksShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) diff --git a/pkg/sdk/testint/views_gen_integration_test.go b/pkg/sdk/testint/views_gen_integration_test.go index 15359c0564..eeeabfb41e 100644 --- a/pkg/sdk/testint/views_gen_integration_test.go +++ b/pkg/sdk/testint/views_gen_integration_test.go @@ -493,7 +493,7 @@ func TestInt_Views(t *testing.T) { t.Run("show view by id: same name in different schemas", func(t *testing.T) { // we assume that SF returns views alphabetically schemaName := "aaaa" + random.StringRange(8, 28) - schema, schemaCleanup := createSchemaWithIdentifier(t, client, testDb(t), schemaName) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, testDb(t), schemaName) t.Cleanup(schemaCleanup) name := random.String() @@ -561,7 +561,7 @@ func TestInt_ViewsShowByID(t *testing.T) { } t.Run("show by id - same name in different schemas", func(t *testing.T) { - schema, schemaCleanup := createSchemaWithIdentifier(t, client, databaseTest, random.AlphaN(8)) + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, databaseTest, random.AlphaN(8)) t.Cleanup(schemaCleanup) name := random.AlphaN(4) From 66b2ea326ecf935da3a2a5a8be063f3473456055 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Thu, 18 Apr 2024 15:41:32 +0200 Subject: [PATCH 3/3] Introduce show helper functions --- pkg/acceptance/helpers/database_client.go | 7 ++++ pkg/acceptance/helpers/schema_client.go | 7 ++++ pkg/resources/database_acceptance_test.go | 30 ++++++++--------- pkg/resources/schema_acceptance_test.go | 32 ++++++++----------- .../replication_functions_integration_test.go | 2 +- 5 files changed, 43 insertions(+), 35 deletions(-) diff --git a/pkg/acceptance/helpers/database_client.go b/pkg/acceptance/helpers/database_client.go index 35cd340e9b..75065c4f9c 100644 --- a/pkg/acceptance/helpers/database_client.go +++ b/pkg/acceptance/helpers/database_client.go @@ -97,3 +97,10 @@ func (d *DatabaseClient) UpdateDataRetentionTime(t *testing.T, id sdk.AccountObj require.NoError(t, err) } } + +func (d *DatabaseClient) Show(t *testing.T, id sdk.AccountObjectIdentifier) (*sdk.Database, error) { + t.Helper() + ctx := context.Background() + + return d.client().ShowByID(ctx, id) +} diff --git a/pkg/acceptance/helpers/schema_client.go b/pkg/acceptance/helpers/schema_client.go index 780d310822..b620c5cea3 100644 --- a/pkg/acceptance/helpers/schema_client.go +++ b/pkg/acceptance/helpers/schema_client.go @@ -64,3 +64,10 @@ func (c *SchemaClient) UpdateDataRetentionTime(t *testing.T, id sdk.DatabaseObje require.NoError(t, err) } } + +func (c *SchemaClient) Show(t *testing.T, id sdk.DatabaseObjectIdentifier) (*sdk.Schema, error) { + t.Helper() + ctx := context.Background() + + return c.client().ShowByID(ctx, id) +} diff --git a/pkg/resources/database_acceptance_test.go b/pkg/resources/database_acceptance_test.go index 9eed2a565b..a09456baa6 100644 --- a/pkg/resources/database_acceptance_test.go +++ b/pkg/resources/database_acceptance_test.go @@ -213,7 +213,7 @@ func TestAcc_Database_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithoutDatabaseDataRetentionTime(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_database.test", "data_retention_time_in_days", "-1"), - checkAccountAndDatabaseDataRetentionTime(id, 5, 5), + checkAccountAndDatabaseDataRetentionTime(t, id, 5, 5), ), }, { @@ -222,7 +222,7 @@ func TestAcc_Database_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithoutDatabaseDataRetentionTime(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_database.test", "data_retention_time_in_days", "-1"), - checkAccountAndDatabaseDataRetentionTime(id, 10, 10), + checkAccountAndDatabaseDataRetentionTime(t, id, 10, 10), ), }, { @@ -230,7 +230,7 @@ func TestAcc_Database_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithDatabaseDataRetentionTime(5), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_database.test", "data_retention_time_in_days", "5"), - checkAccountAndDatabaseDataRetentionTime(id, 10, 5), + checkAccountAndDatabaseDataRetentionTime(t, id, 10, 5), ), }, { @@ -238,7 +238,7 @@ func TestAcc_Database_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithDatabaseDataRetentionTime(15), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_database.test", "data_retention_time_in_days", "15"), - checkAccountAndDatabaseDataRetentionTime(id, 10, 15), + checkAccountAndDatabaseDataRetentionTime(t, id, 10, 15), ), }, { @@ -246,7 +246,7 @@ func TestAcc_Database_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithoutDatabaseDataRetentionTime(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_database.test", "data_retention_time_in_days", "-1"), - checkAccountAndDatabaseDataRetentionTime(id, 10, 10), + checkAccountAndDatabaseDataRetentionTime(t, id, 10, 10), ), }, { @@ -254,7 +254,7 @@ func TestAcc_Database_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithDatabaseDataRetentionTime(0), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_database.test", "data_retention_time_in_days", "0"), - checkAccountAndDatabaseDataRetentionTime(id, 10, 0), + checkAccountAndDatabaseDataRetentionTime(t, id, 10, 0), ), }, { @@ -262,7 +262,7 @@ func TestAcc_Database_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithDatabaseDataRetentionTime(3), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_database.test", "data_retention_time_in_days", "3"), - checkAccountAndDatabaseDataRetentionTime(id, 10, 3), + checkAccountAndDatabaseDataRetentionTime(t, id, 10, 3), ), }, }, @@ -302,7 +302,7 @@ func TestAcc_Database_DefaultDataRetentionTime_SetOutsideOfTerraform(t *testing. ConfigVariables: configVariablesWithoutDatabaseDataRetentionTime(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_database.test", "data_retention_time_in_days", "-1"), - checkAccountAndDatabaseDataRetentionTime(id, 5, 5), + checkAccountAndDatabaseDataRetentionTime(t, id, 5, 5), ), }, { @@ -311,7 +311,7 @@ func TestAcc_Database_DefaultDataRetentionTime_SetOutsideOfTerraform(t *testing. ConfigVariables: configVariablesWithoutDatabaseDataRetentionTime(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_database.test", "data_retention_time_in_days", "-1"), - checkAccountAndDatabaseDataRetentionTime(id, 5, 5), + checkAccountAndDatabaseDataRetentionTime(t, id, 5, 5), ), }, { @@ -320,7 +320,7 @@ func TestAcc_Database_DefaultDataRetentionTime_SetOutsideOfTerraform(t *testing. ConfigVariables: configVariablesWithDatabaseDataRetentionTime(3), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_database.test", "data_retention_time_in_days", "3"), - checkAccountAndDatabaseDataRetentionTime(id, 10, 3), + checkAccountAndDatabaseDataRetentionTime(t, id, 10, 3), ), ConfigPlanChecks: resource.ConfigPlanChecks{ PostApplyPostRefresh: []plancheck.PlanCheck{ @@ -385,10 +385,7 @@ func getSecondaryAccount(t *testing.T) string { func testAccCheckDatabaseExistence(t *testing.T, id string, shouldExist bool) func(state *terraform.State) error { t.Helper() return func(state *terraform.State) error { - client := acc.Client(t) - ctx := context.Background() - - _, err := client.Databases.ShowByID(ctx, sdk.NewAccountObjectIdentifier(id)) + _, err := acc.TestClient().Database.Show(t, sdk.NewAccountObjectIdentifier(id)) if shouldExist { if err != nil { return fmt.Errorf("error while retrieving database %s, err = %w", id, err) @@ -429,13 +426,14 @@ func testAccCheckIfDatabaseIsReplicated(t *testing.T, id string) func(state *ter } } -func checkAccountAndDatabaseDataRetentionTime(id sdk.AccountObjectIdentifier, expectedAccountRetentionDays int, expectedDatabaseRetentionsDays int) func(state *terraform.State) error { +func checkAccountAndDatabaseDataRetentionTime(t *testing.T, id sdk.AccountObjectIdentifier, expectedAccountRetentionDays int, expectedDatabaseRetentionsDays int) func(state *terraform.State) error { + t.Helper() return func(state *terraform.State) error { providerContext := acc.TestAccProvider.Meta().(*provider.Context) client := providerContext.Client ctx := context.Background() - database, err := client.Databases.ShowByID(ctx, id) + database, err := acc.TestClient().Database.Show(t, id) if err != nil { return err } diff --git a/pkg/resources/schema_acceptance_test.go b/pkg/resources/schema_acceptance_test.go index e9cdf0f846..d92f89af68 100644 --- a/pkg/resources/schema_acceptance_test.go +++ b/pkg/resources/schema_acceptance_test.go @@ -1,7 +1,6 @@ package resources_test import ( - "context" "fmt" "regexp" "strconv" @@ -10,7 +9,6 @@ import ( acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/provider" "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/config" @@ -196,7 +194,7 @@ func TestAcc_Schema_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithoutSchemaDataRetentionTime(5), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_schema.test", "data_retention_days", "-1"), - checkDatabaseAndSchemaDataRetentionTime(id, 5, 5), + checkDatabaseAndSchemaDataRetentionTime(t, id, 5, 5), ), }, { @@ -204,7 +202,7 @@ func TestAcc_Schema_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithoutSchemaDataRetentionTime(10), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_schema.test", "data_retention_days", "-1"), - checkDatabaseAndSchemaDataRetentionTime(id, 10, 10), + checkDatabaseAndSchemaDataRetentionTime(t, id, 10, 10), ), }, { @@ -212,7 +210,7 @@ func TestAcc_Schema_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithSchemaDataRetentionTime(10, 5), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_schema.test", "data_retention_days", "5"), - checkDatabaseAndSchemaDataRetentionTime(id, 10, 5), + checkDatabaseAndSchemaDataRetentionTime(t, id, 10, 5), ), }, { @@ -220,7 +218,7 @@ func TestAcc_Schema_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithSchemaDataRetentionTime(10, 15), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_schema.test", "data_retention_days", "15"), - checkDatabaseAndSchemaDataRetentionTime(id, 10, 15), + checkDatabaseAndSchemaDataRetentionTime(t, id, 10, 15), ), }, { @@ -228,7 +226,7 @@ func TestAcc_Schema_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithoutSchemaDataRetentionTime(10), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_schema.test", "data_retention_days", "-1"), - checkDatabaseAndSchemaDataRetentionTime(id, 10, 10), + checkDatabaseAndSchemaDataRetentionTime(t, id, 10, 10), ), }, { @@ -236,7 +234,7 @@ func TestAcc_Schema_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithSchemaDataRetentionTime(10, 0), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_schema.test", "data_retention_days", "0"), - checkDatabaseAndSchemaDataRetentionTime(id, 10, 0), + checkDatabaseAndSchemaDataRetentionTime(t, id, 10, 0), ), }, { @@ -244,7 +242,7 @@ func TestAcc_Schema_DefaultDataRetentionTime(t *testing.T) { ConfigVariables: configVariablesWithSchemaDataRetentionTime(10, 3), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_schema.test", "data_retention_days", "3"), - checkDatabaseAndSchemaDataRetentionTime(id, 10, 3), + checkDatabaseAndSchemaDataRetentionTime(t, id, 10, 3), ), }, }, @@ -284,7 +282,7 @@ func TestAcc_Schema_DefaultDataRetentionTime_SetOutsideOfTerraform(t *testing.T) ConfigVariables: configVariablesWithoutSchemaDataRetentionTime(5), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_schema.test", "data_retention_days", "-1"), - checkDatabaseAndSchemaDataRetentionTime(id, 5, 5), + checkDatabaseAndSchemaDataRetentionTime(t, id, 5, 5), ), }, { @@ -293,7 +291,7 @@ func TestAcc_Schema_DefaultDataRetentionTime_SetOutsideOfTerraform(t *testing.T) ConfigVariables: configVariablesWithoutSchemaDataRetentionTime(5), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_schema.test", "data_retention_days", "-1"), - checkDatabaseAndSchemaDataRetentionTime(id, 5, 5), + checkDatabaseAndSchemaDataRetentionTime(t, id, 5, 5), ), }, { @@ -301,7 +299,7 @@ func TestAcc_Schema_DefaultDataRetentionTime_SetOutsideOfTerraform(t *testing.T) ConfigVariables: configVariablesWithSchemaDataRetentionTime(10, 3), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_schema.test", "data_retention_days", "3"), - checkDatabaseAndSchemaDataRetentionTime(id, 10, 3), + checkDatabaseAndSchemaDataRetentionTime(t, id, 10, 3), ), ConfigPlanChecks: resource.ConfigPlanChecks{ PostApplyPostRefresh: []plancheck.PlanCheck{ @@ -384,17 +382,15 @@ func TestAcc_Schema_RemoveSchemaOutsideOfTerraform(t *testing.T) { }) } -func checkDatabaseAndSchemaDataRetentionTime(id sdk.DatabaseObjectIdentifier, expectedDatabaseRetentionsDays int, expectedSchemaRetentionDays int) func(state *terraform.State) error { +func checkDatabaseAndSchemaDataRetentionTime(t *testing.T, id sdk.DatabaseObjectIdentifier, expectedDatabaseRetentionsDays int, expectedSchemaRetentionDays int) func(state *terraform.State) error { + t.Helper() return func(state *terraform.State) error { - client := acc.TestAccProvider.Meta().(*provider.Context).Client - ctx := context.Background() - - schema, err := client.Schemas.ShowByID(ctx, id) + schema, err := acc.TestClient().Schema.Show(t, id) if err != nil { return err } - database, err := client.Databases.ShowByID(ctx, sdk.NewAccountObjectIdentifier(id.DatabaseName())) + database, err := acc.TestClient().Database.Show(t, sdk.NewAccountObjectIdentifier(id.DatabaseName())) if err != nil { return err } diff --git a/pkg/sdk/testint/replication_functions_integration_test.go b/pkg/sdk/testint/replication_functions_integration_test.go index dca9c0ded1..dc4dfb6e4c 100644 --- a/pkg/sdk/testint/replication_functions_integration_test.go +++ b/pkg/sdk/testint/replication_functions_integration_test.go @@ -45,7 +45,7 @@ func TestInt_ShowReplicationDatabases(t *testing.T) { err = client.Databases.AlterReplication(ctx, db2.ID(), &sdk.AlterDatabaseReplicationOptions{EnableReplication: &sdk.EnableReplication{ToAccounts: []sdk.AccountIdentifier{secondaryAccountId}}}) require.NoError(t, err) - db3, dbCleanup3 := testClientHelper().Database.CreateSecondaryDatabaseWithOptions(t, sdk.NewAccountObjectIdentifier(db3Name), sdk.NewExternalObjectIdentifier(accountId, db.ID()), &sdk.CreateSecondaryDatabaseOptions{}) + db3, dbCleanup3 := secondaryTestClientHelper().Database.CreateSecondaryDatabaseWithOptions(t, sdk.NewAccountObjectIdentifier(db3Name), sdk.NewExternalObjectIdentifier(accountId, db.ID()), &sdk.CreateSecondaryDatabaseOptions{}) t.Cleanup(dbCleanup3) getByName := func(replicationDatabases []sdk.ReplicationDatabase, name sdk.AccountObjectIdentifier) *sdk.ReplicationDatabase {