From 36ead8576d0ea54f9cc361d2baf9593006dc801f Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 27 May 2024 13:21:35 +0200 Subject: [PATCH] chore: Random ids rework part3 (#2833) Continuation of ids rework: - Do not use `random.String()` for the identifiers - Do not use `random.StringN()` for the identifiers - Do not use `random.UUID()` for the identifiers - Do not use `random.AlphanumericN()` for the identifiers - Do not use `random.Alpha()` for the identifiers - Do not use `random.StringRange()` for the identifiers --- pkg/acceptance/helpers/database_client.go | 5 +- .../helpers/database_role_client.go | 3 +- .../helpers/dynamic_table_client.go | 5 +- pkg/acceptance/helpers/ids_generator.go | 34 ++++- .../helpers/masking_policy_client.go | 5 +- .../helpers/random/random_helpers.go | 19 +-- pkg/acceptance/helpers/role_client.go | 5 +- pkg/acceptance/helpers/schema_client.go | 15 +- pkg/acceptance/helpers/share_client.go | 8 +- pkg/acceptance/helpers/table_client.go | 21 ++- pkg/acceptance/helpers/user_client.go | 5 +- .../dynamic_table_acceptance_test.go | 6 +- .../external_table_acceptance_test.go | 23 ++- .../grant_ownership_acceptance_test.go | 14 +- ...vileges_to_account_role_acceptance_test.go | 124 +++++++---------- ...ileges_to_database_role_acceptance_test.go | 4 +- ...rant_privileges_to_role_acceptance_test.go | 22 ++- ...ant_privileges_to_share_acceptance_test.go | 5 +- pkg/resources/schema_acceptance_test.go | 5 +- pkg/resources/view_acceptance_test.go | 4 +- pkg/sdk/alerts_test.go | 6 +- pkg/sdk/applications_gen_test.go | 4 +- pkg/sdk/database_role_test.go | 6 +- pkg/sdk/event_tables_gen_test.go | 8 +- pkg/sdk/functions_gen_test.go | 4 +- pkg/sdk/masking_policy_test.go | 6 +- pkg/sdk/password_policy_test.go | 4 +- pkg/sdk/procedures_gen_test.go | 4 +- pkg/sdk/random_test.go | 13 ++ pkg/sdk/sequences_gen_test.go | 4 +- pkg/sdk/tables_test.go | 10 +- pkg/sdk/tags_test.go | 6 +- pkg/sdk/testint/accounts_integration_test.go | 2 +- pkg/sdk/testint/alerts_integration_test.go | 30 ++-- .../application_packages_integration_test.go | 2 +- .../testint/applications_integration_test.go | 8 +- .../testint/database_role_integration_test.go | 37 ++--- .../testint/dynamic_table_integration_test.go | 27 ++-- .../testint/event_tables_integration_test.go | 31 ++--- .../external_functions_integration_test.go | 14 +- .../external_tables_integration_test.go | 72 +++++----- .../testint/file_format_integration_test.go | 24 ++-- pkg/sdk/testint/functions_integration_test.go | 58 ++++---- pkg/sdk/testint/grants_integration_test.go | 5 +- .../managed_accounts_gen_integration_test.go | 6 +- .../masking_policy_integration_test.go | 35 ++--- ...materialized_views_gen_integration_test.go | 14 +- .../network_policies_gen_integration_test.go | 4 +- .../network_rule_gen_integration_test.go | 18 +-- .../password_policy_integration_test.go | 33 ++--- pkg/sdk/testint/pipes_integration_test.go | 23 ++- .../policy_references_integration_test.go | 11 +- .../testint/procedures_integration_test.go | 56 ++++---- .../replication_functions_integration_test.go | 7 +- ...ow_access_policies_gen_integration_test.go | 12 +- pkg/sdk/testint/schemas_integration_test.go | 10 +- pkg/sdk/testint/sequences_integration_test.go | 29 ++-- .../session_policies_gen_integration_test.go | 24 ++-- .../testint/stages_gen_integration_test.go | 50 +++---- .../testint/streamlits_integration_test.go | 39 +++--- .../testint/streams_gen_integration_test.go | 52 ++++--- pkg/sdk/testint/tables_integration_test.go | 131 ++++++------------ pkg/sdk/testint/tags_integration_test.go | 40 ++---- pkg/sdk/testint/tasks_gen_integration_test.go | 60 +++----- pkg/sdk/testint/users_integration_test.go | 17 ++- pkg/sdk/testint/views_gen_integration_test.go | 25 ++-- pkg/sdk/users_test.go | 6 +- pkg/sdk/validations_test.go | 5 +- v1-preparations/ESSENTIAL_GA_OBJECTS.MD | 2 +- 69 files changed, 625 insertions(+), 801 deletions(-) diff --git a/pkg/acceptance/helpers/database_client.go b/pkg/acceptance/helpers/database_client.go index 9ef2821abe..308130d8c8 100644 --- a/pkg/acceptance/helpers/database_client.go +++ b/pkg/acceptance/helpers/database_client.go @@ -30,10 +30,9 @@ func (c *DatabaseClient) CreateDatabase(t *testing.T) (*sdk.Database, func()) { return c.CreateDatabaseWithOptions(t, c.ids.RandomAccountObjectIdentifier(), &sdk.CreateDatabaseOptions{}) } -// TODO [SNOW-955520]: we have to control the name -func (c *DatabaseClient) CreateDatabaseWithName(t *testing.T, name string) (*sdk.Database, func()) { +func (c *DatabaseClient) CreateDatabaseWithIdentifier(t *testing.T, id sdk.AccountObjectIdentifier) (*sdk.Database, func()) { t.Helper() - return c.CreateDatabaseWithOptions(t, sdk.NewAccountObjectIdentifier(name), &sdk.CreateDatabaseOptions{}) + return c.CreateDatabaseWithOptions(t, id, &sdk.CreateDatabaseOptions{}) } func (c *DatabaseClient) CreateDatabaseWithOptions(t *testing.T, id sdk.AccountObjectIdentifier, opts *sdk.CreateDatabaseOptions) (*sdk.Database, func()) { diff --git a/pkg/acceptance/helpers/database_role_client.go b/pkg/acceptance/helpers/database_role_client.go index 7ea5b4e624..96adf35aa0 100644 --- a/pkg/acceptance/helpers/database_role_client.go +++ b/pkg/acceptance/helpers/database_role_client.go @@ -5,7 +5,6 @@ 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/stretchr/testify/require" ) @@ -33,7 +32,7 @@ func (c *DatabaseRoleClient) CreateDatabaseRole(t *testing.T) (*sdk.DatabaseRole func (c *DatabaseRoleClient) CreateDatabaseRoleInDatabase(t *testing.T, databaseId sdk.AccountObjectIdentifier) (*sdk.DatabaseRole, func()) { t.Helper() - return c.CreateDatabaseRoleInDatabaseWithName(t, databaseId, random.String()) + return c.CreateDatabaseRoleInDatabaseWithName(t, databaseId, c.ids.Alpha()) } func (c *DatabaseRoleClient) CreateDatabaseRoleWithName(t *testing.T, name string) (*sdk.DatabaseRole, func()) { diff --git a/pkg/acceptance/helpers/dynamic_table_client.go b/pkg/acceptance/helpers/dynamic_table_client.go index 520f526b89..035c4ef59c 100644 --- a/pkg/acceptance/helpers/dynamic_table_client.go +++ b/pkg/acceptance/helpers/dynamic_table_client.go @@ -28,12 +28,11 @@ func (c *DynamicTableClient) client() sdk.DynamicTables { func (c *DynamicTableClient) CreateDynamicTable(t *testing.T, tableId sdk.SchemaObjectIdentifier) (*sdk.DynamicTable, func()) { t.Helper() - return c.CreateDynamicTableWithOptions(t, c.ids.SchemaId(), random.AlphaN(12), c.ids.WarehouseId(), tableId) + return c.CreateDynamicTableWithOptions(t, c.ids.RandomSchemaObjectIdentifier(), c.ids.WarehouseId(), tableId) } -func (c *DynamicTableClient) CreateDynamicTableWithOptions(t *testing.T, schemaId sdk.DatabaseObjectIdentifier, name string, warehouseId sdk.AccountObjectIdentifier, tableId sdk.SchemaObjectIdentifier) (*sdk.DynamicTable, func()) { +func (c *DynamicTableClient) CreateDynamicTableWithOptions(t *testing.T, id sdk.SchemaObjectIdentifier, warehouseId sdk.AccountObjectIdentifier, tableId sdk.SchemaObjectIdentifier) (*sdk.DynamicTable, func()) { t.Helper() - id := sdk.NewSchemaObjectIdentifierInSchema(schemaId, name) targetLag := sdk.TargetLag{ MaximumDuration: sdk.String("2 minutes"), } diff --git a/pkg/acceptance/helpers/ids_generator.go b/pkg/acceptance/helpers/ids_generator.go index 001d1d3359..ec74e0d8aa 100644 --- a/pkg/acceptance/helpers/ids_generator.go +++ b/pkg/acceptance/helpers/ids_generator.go @@ -33,10 +33,6 @@ func (c *IdsGenerator) AccountIdentifierWithLocator() sdk.AccountIdentifier { return sdk.NewAccountIdentifierFromAccountLocator(c.context.client.GetAccountLocator()) } -func (c *IdsGenerator) NewSchemaObjectIdentifier(name string) sdk.SchemaObjectIdentifier { - return sdk.NewSchemaObjectIdentifierInSchema(c.SchemaId(), name) -} - func (c *IdsGenerator) RandomAccountObjectIdentifier() sdk.AccountObjectIdentifier { return sdk.NewAccountObjectIdentifier(c.Alpha()) } @@ -49,14 +45,42 @@ func (c *IdsGenerator) RandomAccountObjectIdentifierContaining(part string) sdk. return sdk.NewAccountObjectIdentifier(c.AlphaContaining(part)) } +func (c *IdsGenerator) NewDatabaseObjectIdentifier(name string) sdk.DatabaseObjectIdentifier { + return sdk.NewDatabaseObjectIdentifier(c.DatabaseId().Name(), name) +} + func (c *IdsGenerator) RandomDatabaseObjectIdentifier() sdk.DatabaseObjectIdentifier { - return sdk.NewDatabaseObjectIdentifier(c.DatabaseId().Name(), c.Alpha()) + return c.RandomDatabaseObjectIdentifierInDatabase(c.DatabaseId()) +} + +func (c *IdsGenerator) RandomDatabaseObjectIdentifierInDatabase(databaseId sdk.AccountObjectIdentifier) sdk.DatabaseObjectIdentifier { + return sdk.NewDatabaseObjectIdentifier(databaseId.Name(), c.Alpha()) +} + +func (c *IdsGenerator) RandomDatabaseObjectIdentifierWithPrefix(prefix string) sdk.DatabaseObjectIdentifier { + return sdk.NewDatabaseObjectIdentifier(c.DatabaseId().Name(), c.AlphaWithPrefix(prefix)) +} + +func (c *IdsGenerator) NewSchemaObjectIdentifier(name string) sdk.SchemaObjectIdentifier { + return sdk.NewSchemaObjectIdentifierInSchema(c.SchemaId(), name) +} + +func (c *IdsGenerator) NewSchemaObjectIdentifierInSchema(name string, schemaId sdk.DatabaseObjectIdentifier) sdk.SchemaObjectIdentifier { + return sdk.NewSchemaObjectIdentifierInSchema(schemaId, name) } func (c *IdsGenerator) RandomSchemaObjectIdentifier() sdk.SchemaObjectIdentifier { return c.RandomSchemaObjectIdentifierInSchema(c.SchemaId()) } +func (c *IdsGenerator) RandomSchemaObjectIdentifierWithPrefix(prefix string) sdk.SchemaObjectIdentifier { + return sdk.NewSchemaObjectIdentifierInSchema(c.SchemaId(), c.AlphaWithPrefix(prefix)) +} + +func (c *IdsGenerator) RandomSchemaObjectIdentifierWithArguments(arguments []sdk.DataType) sdk.SchemaObjectIdentifier { + return sdk.NewSchemaObjectIdentifierWithArguments(c.SchemaId().DatabaseName(), c.SchemaId().Name(), c.Alpha(), arguments) +} + func (c *IdsGenerator) RandomSchemaObjectIdentifierInSchema(schemaId sdk.DatabaseObjectIdentifier) sdk.SchemaObjectIdentifier { return sdk.NewSchemaObjectIdentifierInSchema(schemaId, c.Alpha()) } diff --git a/pkg/acceptance/helpers/masking_policy_client.go b/pkg/acceptance/helpers/masking_policy_client.go index 740b62f7a9..01fb857104 100644 --- a/pkg/acceptance/helpers/masking_policy_client.go +++ b/pkg/acceptance/helpers/masking_policy_client.go @@ -4,7 +4,6 @@ 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/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -35,11 +34,11 @@ func (c *MaskingPolicyClient) CreateMaskingPolicyInSchema(t *testing.T, schemaId t.Helper() signature := []sdk.TableColumnSignature{ { - Name: random.String(), + Name: c.ids.Alpha(), Type: sdk.DataTypeVARCHAR, }, { - Name: random.String(), + Name: c.ids.Alpha(), Type: sdk.DataTypeVARCHAR, }, } diff --git a/pkg/acceptance/helpers/random/random_helpers.go b/pkg/acceptance/helpers/random/random_helpers.go index 5734dcbdd9..ca5f4bde14 100644 --- a/pkg/acceptance/helpers/random/random_helpers.go +++ b/pkg/acceptance/helpers/random/random_helpers.go @@ -14,6 +14,17 @@ func Comment() string { return gofakeit.Sentence(10) } +func Password() string { + return StringN(12) +} + +// AdminName returns admin name acceptable by Snowflake: +// 090088 (22000): ADMIN_NAME can only contain letters, numbers and underscores. +// 090089 (22000): ADMIN_NAME must start with a letter. +func AdminName() string { + return AlphaN(1) + AlphanumericN(11) +} + func Bool() bool { return gofakeit.Bool() } @@ -33,11 +44,3 @@ func AlphanumericN(num int) string { func AlphaN(num int) string { return gofakeit.Password(true, true, false, false, false, num) } - -func StringRange(min, max int) string { - return gofakeit.Password(true, true, true, true, false, IntRange(min, max)) -} - -func IntRange(min, max int) int { - return gofakeit.IntRange(min, max) -} diff --git a/pkg/acceptance/helpers/role_client.go b/pkg/acceptance/helpers/role_client.go index 9e36712500..af89bbf157 100644 --- a/pkg/acceptance/helpers/role_client.go +++ b/pkg/acceptance/helpers/role_client.go @@ -45,10 +45,9 @@ func (c *RoleClient) CreateRole(t *testing.T) (*sdk.Role, func()) { return c.CreateRoleWithRequest(t, sdk.NewCreateRoleRequest(c.ids.RandomAccountObjectIdentifier())) } -// TODO [SNOW-955520]: we have to control the name -func (c *RoleClient) CreateRoleWithName(t *testing.T, name string) (*sdk.Role, func()) { +func (c *RoleClient) CreateRoleWithIdentifier(t *testing.T, id sdk.AccountObjectIdentifier) (*sdk.Role, func()) { t.Helper() - return c.CreateRoleWithRequest(t, sdk.NewCreateRoleRequest(sdk.NewAccountObjectIdentifier(name))) + return c.CreateRoleWithRequest(t, sdk.NewCreateRoleRequest(id)) } func (c *RoleClient) CreateRoleGrantedToCurrentUser(t *testing.T) (*sdk.Role, func()) { diff --git a/pkg/acceptance/helpers/schema_client.go b/pkg/acceptance/helpers/schema_client.go index 6aef08747c..10bd11083f 100644 --- a/pkg/acceptance/helpers/schema_client.go +++ b/pkg/acceptance/helpers/schema_client.go @@ -4,7 +4,6 @@ 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/stretchr/testify/require" ) @@ -32,23 +31,23 @@ func (c *SchemaClient) CreateSchema(t *testing.T) (*sdk.Schema, func()) { func (c *SchemaClient) CreateSchemaInDatabase(t *testing.T, databaseId sdk.AccountObjectIdentifier) (*sdk.Schema, func()) { t.Helper() - return c.CreateSchemaInDatabaseWithIdentifier(t, databaseId, random.AlphaN(12)) + return c.CreateSchemaWithIdentifier(t, c.ids.RandomDatabaseObjectIdentifierInDatabase(databaseId)) } func (c *SchemaClient) CreateSchemaWithName(t *testing.T, name string) (*sdk.Schema, func()) { t.Helper() - return c.CreateSchemaInDatabaseWithIdentifier(t, c.ids.DatabaseId(), name) + return c.CreateSchemaWithIdentifier(t, c.ids.NewDatabaseObjectIdentifier(name)) } -func (c *SchemaClient) CreateSchemaInDatabaseWithIdentifier(t *testing.T, databaseId sdk.AccountObjectIdentifier, name string) (*sdk.Schema, func()) { +func (c *SchemaClient) CreateSchemaWithIdentifier(t *testing.T, id sdk.DatabaseObjectIdentifier) (*sdk.Schema, func()) { t.Helper() ctx := context.Background() - schemaID := sdk.NewDatabaseObjectIdentifier(databaseId.Name(), name) - err := c.client().Create(ctx, schemaID, nil) + + err := c.client().Create(ctx, id, nil) require.NoError(t, err) - schema, err := c.client().ShowByID(ctx, sdk.NewDatabaseObjectIdentifier(databaseId.Name(), name)) + schema, err := c.client().ShowByID(ctx, id) require.NoError(t, err) - return schema, c.DropSchemaFunc(t, schemaID) + return schema, c.DropSchemaFunc(t, id) } func (c *SchemaClient) DropSchemaFunc(t *testing.T, id sdk.DatabaseObjectIdentifier) func() { diff --git a/pkg/acceptance/helpers/share_client.go b/pkg/acceptance/helpers/share_client.go index 1ac0f1e8e7..e61a6f53ea 100644 --- a/pkg/acceptance/helpers/share_client.go +++ b/pkg/acceptance/helpers/share_client.go @@ -4,7 +4,6 @@ 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/stretchr/testify/require" ) @@ -28,13 +27,12 @@ func (c *ShareClient) client() sdk.Shares { func (c *ShareClient) CreateShare(t *testing.T) (*sdk.Share, func()) { t.Helper() // TODO(SNOW-1058419): Try with identifier containing dot during identifiers rework - return c.CreateShareWithName(t, random.AlphanumericN(12)) + return c.CreateShareWithIdentifier(t, c.ids.RandomAccountObjectIdentifier()) } -// TODO [SNOW-955520]: we have to control the name -func (c *ShareClient) CreateShareWithName(t *testing.T, name string) (*sdk.Share, func()) { +func (c *ShareClient) CreateShareWithIdentifier(t *testing.T, id sdk.AccountObjectIdentifier) (*sdk.Share, func()) { t.Helper() - return c.CreateShareWithOptions(t, sdk.NewAccountObjectIdentifier(name), &sdk.CreateShareOptions{}) + return c.CreateShareWithOptions(t, id, &sdk.CreateShareOptions{}) } func (c *ShareClient) CreateShareWithOptions(t *testing.T, id sdk.AccountObjectIdentifier, opts *sdk.CreateShareOptions) (*sdk.Share, func()) { diff --git a/pkg/acceptance/helpers/table_client.go b/pkg/acceptance/helpers/table_client.go index 230b1de21b..1c7b830817 100644 --- a/pkg/acceptance/helpers/table_client.go +++ b/pkg/acceptance/helpers/table_client.go @@ -7,7 +7,6 @@ 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/stretchr/testify/require" ) @@ -33,20 +32,32 @@ func (c *TableClient) CreateTable(t *testing.T) (*sdk.Table, func()) { return c.CreateTableInSchema(t, c.ids.SchemaId()) } +func (c *TableClient) CreateTableWithName(t *testing.T, name string) (*sdk.Table, func()) { + t.Helper() + + columns := []sdk.TableColumnRequest{ + *sdk.NewTableColumnRequest("id", sdk.DataTypeNumber), + } + return c.CreateTableWithIdAndColumns(t, c.ids.NewSchemaObjectIdentifier(name), columns) +} + func (c *TableClient) CreateTableInSchema(t *testing.T, schemaId sdk.DatabaseObjectIdentifier) (*sdk.Table, func()) { t.Helper() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("id", sdk.DataTypeNumber), } - name := random.StringRange(8, 28) - return c.CreateTableWithColumns(t, schemaId, name, columns) + return c.CreateTableWithIdAndColumns(t, c.ids.RandomSchemaObjectIdentifierInSchema(schemaId), columns) } -func (c *TableClient) CreateTableWithColumns(t *testing.T, schemaId sdk.DatabaseObjectIdentifier, name string, columns []sdk.TableColumnRequest) (*sdk.Table, func()) { +func (c *TableClient) CreateTableWithColumns(t *testing.T, columns []sdk.TableColumnRequest) (*sdk.Table, func()) { t.Helper() - id := sdk.NewSchemaObjectIdentifierInSchema(schemaId, name) + return c.CreateTableWithIdAndColumns(t, c.ids.RandomSchemaObjectIdentifier(), columns) +} + +func (c *TableClient) CreateTableWithIdAndColumns(t *testing.T, id sdk.SchemaObjectIdentifier, columns []sdk.TableColumnRequest) (*sdk.Table, func()) { + t.Helper() ctx := context.Background() dbCreateRequest := sdk.NewCreateTableRequest(id, columns) diff --git a/pkg/acceptance/helpers/user_client.go b/pkg/acceptance/helpers/user_client.go index 0331b4abe5..617e9637ba 100644 --- a/pkg/acceptance/helpers/user_client.go +++ b/pkg/acceptance/helpers/user_client.go @@ -29,10 +29,9 @@ func (c *UserClient) CreateUser(t *testing.T) (*sdk.User, func()) { return c.CreateUserWithOptions(t, c.ids.RandomAccountObjectIdentifier(), &sdk.CreateUserOptions{}) } -// TODO [SNOW-955520]: we have to control the name -func (c *UserClient) CreateUserWithName(t *testing.T, name string) (*sdk.User, func()) { +func (c *UserClient) CreateUserWithPrefix(t *testing.T, prefix string) (*sdk.User, func()) { t.Helper() - return c.CreateUserWithOptions(t, sdk.NewAccountObjectIdentifier(name), &sdk.CreateUserOptions{}) + return c.CreateUserWithOptions(t, c.ids.RandomAccountObjectIdentifierWithPrefix(prefix), &sdk.CreateUserOptions{}) } func (c *UserClient) CreateUserWithOptions(t *testing.T, id sdk.AccountObjectIdentifier, opts *sdk.CreateUserOptions) (*sdk.User, func()) { diff --git a/pkg/resources/dynamic_table_acceptance_test.go b/pkg/resources/dynamic_table_acceptance_test.go index 04d92f45a7..a5876a188f 100644 --- a/pkg/resources/dynamic_table_acceptance_test.go +++ b/pkg/resources/dynamic_table_acceptance_test.go @@ -156,12 +156,14 @@ func TestAcc_DynamicTable_basic(t *testing.T) { // TestAcc_DynamicTable_issue2173 proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2173 issue. func TestAcc_DynamicTable_issue2173(t *testing.T) { - dynamicTableName := acc.TestClient().Ids.Alpha() + dynamicTableId := acc.TestClient().Ids.RandomSchemaObjectIdentifier() + dynamicTableName := dynamicTableId.Name() tableName := dynamicTableName + "_table" tableId := acc.TestClient().Ids.NewSchemaObjectIdentifier(tableName) query := fmt.Sprintf(`select "ID" from %s`, tableId.FullyQualifiedName()) otherSchema := acc.TestClient().Ids.Alpha() otherSchemaId := sdk.NewDatabaseObjectIdentifier(acc.TestDatabaseName, otherSchema) + newDynamicTableId := acc.TestClient().Ids.NewSchemaObjectIdentifierInSchema(dynamicTableName, otherSchemaId) m := func() map[string]config.Variable { return map[string]config.Variable{ "name": config.StringVariable(dynamicTableName), @@ -196,7 +198,7 @@ func TestAcc_DynamicTable_issue2173(t *testing.T) { }, { PreConfig: func() { - acc.TestClient().DynamicTable.CreateDynamicTableWithOptions(t, otherSchemaId, dynamicTableName, acc.TestClient().Ids.WarehouseId(), tableId) + acc.TestClient().DynamicTable.CreateDynamicTableWithOptions(t, newDynamicTableId, acc.TestClient().Ids.WarehouseId(), tableId) }, ConfigDirectory: config.TestStepDirectory(), ConfigVariables: m(), diff --git a/pkg/resources/external_table_acceptance_test.go b/pkg/resources/external_table_acceptance_test.go index fb59f5729a..24f575a5ba 100644 --- a/pkg/resources/external_table_acceptance_test.go +++ b/pkg/resources/external_table_acceptance_test.go @@ -98,7 +98,7 @@ func TestAcc_ExternalTable_basic(t *testing.T) { { ConfigDirectory: acc.ConfigurationSameAsStepN(2), ConfigVariables: configVariables, - Check: externalTableContainsData(name, func(rows []map[string]*any) bool { + Check: externalTableContainsData(id, func(rows []map[string]*any) bool { expectedNames := []string{"one", "two", "three"} names := make([]string, 3) for i, row := range rows { @@ -132,7 +132,8 @@ func TestAcc_ExternalTable_basic(t *testing.T) { func TestAcc_ExternalTable_CorrectDataTypes(t *testing.T) { awsBucketURL, awsKeyId, awsSecretKey := getExternalTableTestEnvsOrSkipTest(t) - name := acc.TestClient().Ids.Alpha() + id := acc.TestClient().Ids.RandomSchemaObjectIdentifier() + name := id.Name() resourceName := "snowflake_external_table.test_table" innerDirectory := "/external_tables_test_data/" @@ -175,7 +176,7 @@ func TestAcc_ExternalTable_CorrectDataTypes(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "column.1.name", "age"), resource.TestCheckResourceAttr(resourceName, "column.1.type", "number(2, 2)"), resource.TestCheckResourceAttr(resourceName, "column.1.as", "value:age::number"), - expectTableToHaveColumnDataTypes(name, []sdk.DataType{ + expectTableToHaveColumnDataTypes(id, []sdk.DataType{ sdk.DataTypeVariant, "VARCHAR(200)", "NUMBER(2,2)", @@ -190,7 +191,8 @@ func TestAcc_ExternalTable_CorrectDataTypes(t *testing.T) { func TestAcc_ExternalTable_CanCreateWithPartitions(t *testing.T) { awsBucketURL, awsKeyId, awsSecretKey := getExternalTableTestEnvsOrSkipTest(t) - name := acc.TestClient().Ids.Alpha() + id := acc.TestClient().Ids.RandomSchemaObjectIdentifier() + name := id.Name() resourceName := "snowflake_external_table.test_table" innerDirectory := "/external_tables_test_data/" @@ -238,7 +240,7 @@ func TestAcc_ExternalTable_CanCreateWithPartitions(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "column.2.name", "age"), resource.TestCheckResourceAttr(resourceName, "column.2.type", "number(2, 2)"), resource.TestCheckResourceAttr(resourceName, "column.2.as", "value:age::number"), - expectTableDDLContains(name, "partition by (FILENAME)"), + expectTableDDLContains(id, "partition by (FILENAME)"), ), }, }, @@ -322,11 +324,10 @@ func getExternalTableTestEnvsOrSkipTest(t *testing.T) (string, string, string) { return awsBucketURL, awsKeyId, awsSecretKey } -func externalTableContainsData(name string, contains func(rows []map[string]*any) bool) func(state *terraform.State) error { +func externalTableContainsData(id sdk.SchemaObjectIdentifier, contains func(rows []map[string]*any) bool) func(state *terraform.State) error { return func(state *terraform.State) error { client := acc.TestAccProvider.Meta().(*provider.Context).Client ctx := context.Background() - id := acc.TestClient().Ids.NewSchemaObjectIdentifier(name) rows, err := client.QueryUnsafe(ctx, fmt.Sprintf("select * from %s", id.FullyQualifiedName())) if err != nil { return err @@ -357,11 +358,10 @@ func publishExternalTablesTestData(t *testing.T, stageName sdk.SchemaObjectIdent } } -func expectTableToHaveColumnDataTypes(tableName string, expectedDataTypes []sdk.DataType) func(s *terraform.State) error { +func expectTableToHaveColumnDataTypes(id sdk.SchemaObjectIdentifier, expectedDataTypes []sdk.DataType) func(s *terraform.State) error { return func(s *terraform.State) error { client := acc.TestAccProvider.Meta().(*provider.Context).Client ctx := context.Background() - id := acc.TestClient().Ids.NewSchemaObjectIdentifier(tableName) columnsDesc, err := client.ExternalTables.DescribeColumns(ctx, sdk.NewDescribeExternalTableColumnsRequest(id)) if err != nil { return err @@ -380,18 +380,17 @@ func expectTableToHaveColumnDataTypes(tableName string, expectedDataTypes []sdk. }) if !slices.Equal(expectedDataTypes, actualTableDataTypes) { - return fmt.Errorf("expected table %s to have columns with data types: %v, got: %v", tableName, expectedDataTypes, actualTableDataTypes) + return fmt.Errorf("expected table %s to have columns with data types: %v, got: %v", id.FullyQualifiedName(), expectedDataTypes, actualTableDataTypes) } return nil } } -func expectTableDDLContains(tableName string, substr string) func(s *terraform.State) error { +func expectTableDDLContains(id sdk.SchemaObjectIdentifier, substr string) func(s *terraform.State) error { return func(s *terraform.State) error { client := acc.TestAccProvider.Meta().(*provider.Context).Client ctx := context.Background() - id := acc.TestClient().Ids.NewSchemaObjectIdentifier(tableName) rows, err := client.QueryUnsafe(ctx, fmt.Sprintf("select get_ddl('table', '%s')", id.FullyQualifiedName())) if err != nil { diff --git a/pkg/resources/grant_ownership_acceptance_test.go b/pkg/resources/grant_ownership_acceptance_test.go index 7e6a256b8e..d5c2532b4e 100644 --- a/pkg/resources/grant_ownership_acceptance_test.go +++ b/pkg/resources/grant_ownership_acceptance_test.go @@ -598,7 +598,7 @@ func TestAcc_GrantOwnership_TargetObjectRemovedOutsideTerraform(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, cleanupDatabase = acc.TestClient().Database.CreateDatabaseWithName(t, databaseName) + _, cleanupDatabase = acc.TestClient().Database.CreateDatabaseWithIdentifier(t, databaseId) t.Cleanup(cleanupDatabase) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantOwnership/OnObject_Database_ToAccountRole_NoDatabaseResource"), @@ -639,7 +639,7 @@ func TestAcc_GrantOwnership_AccountRoleRemovedOutsideTerraform(t *testing.T) { accountRoleName := accountRoleId.Name() accountRoleFullyQualifiedName := accountRoleId.FullyQualifiedName() - _, cleanupAccountRole := acc.TestClient().Role.CreateRoleWithName(t, accountRoleName) + _, cleanupAccountRole := acc.TestClient().Role.CreateRoleWithIdentifier(t, accountRoleId) t.Cleanup(cleanupAccountRole) configVariables := config.Variables{ @@ -883,8 +883,8 @@ func TestAcc_GrantOwnership_ForceOwnershipTransferOnCreate(t *testing.T) { databaseFullyQualifiedName := databaseId.FullyQualifiedName() accountRoleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - accountRoleName := accountRoleId.Name() - newDatabaseOwningAccountRoleName := acc.TestClient().Ids.Alpha() + newDatabaseOwningAccountRoleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() + newDatabaseOwningAccountRoleName := newDatabaseOwningAccountRoleId.Name() configVariables := config.Variables{ "account_role_name": config.StringVariable(newDatabaseOwningAccountRoleName), @@ -901,11 +901,11 @@ func TestAcc_GrantOwnership_ForceOwnershipTransferOnCreate(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - role, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, accountRoleName) + role, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, accountRoleId) t.Cleanup(roleCleanup) - _, newRoleCleanup := acc.TestClient().Role.CreateRoleWithName(t, newDatabaseOwningAccountRoleName) + _, newRoleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, newDatabaseOwningAccountRoleId) t.Cleanup(newRoleCleanup) - database, databaseCleanup := acc.TestClient().Database.CreateDatabaseWithName(t, databaseName) + database, databaseCleanup := acc.TestClient().Database.CreateDatabaseWithIdentifier(t, databaseId) t.Cleanup(databaseCleanup) acc.TestClient().Role.GrantOwnershipOnAccountObject(t, role.ID(), database.ID(), sdk.ObjectTypeDatabase) }, diff --git a/pkg/resources/grant_privileges_to_account_role_acceptance_test.go b/pkg/resources/grant_privileges_to_account_role_acceptance_test.go index 97612ad71c..02f7916afa 100644 --- a/pkg/resources/grant_privileges_to_account_role_acceptance_test.go +++ b/pkg/resources/grant_privileges_to_account_role_acceptance_test.go @@ -19,7 +19,6 @@ import ( func TestAcc_GrantPrivilegesToAccountRole_OnAccount(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() configVariables := config.Variables{ "name": config.StringVariable(roleFullyQualifiedName), @@ -41,7 +40,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnAccount(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnAccount"), @@ -69,7 +68,6 @@ func TestAcc_GrantPrivilegesToAccountRole_OnAccount(t *testing.T) { func TestAcc_GrantPrivilegesToAccountRole_OnAccount_PrivilegesReversed(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() configVariables := config.Variables{ "name": config.StringVariable(roleFullyQualifiedName), @@ -91,7 +89,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnAccount_PrivilegesReversed(t *testin Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnAccount"), @@ -119,7 +117,6 @@ func TestAcc_GrantPrivilegesToAccountRole_OnAccount_PrivilegesReversed(t *testin func TestAcc_GrantPrivilegesToAccountRole_OnAccountObject(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() databaseName := acc.TestClient().Ids.DatabaseId().FullyQualifiedName() configVariables := config.Variables{ @@ -143,7 +140,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnAccountObject(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnAccountObject"), @@ -183,7 +180,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnAccountObject(t *testing.T) { // This proves that infinite plan is not produced as in snowflake_grant_privileges_to_role. // More details can be found in the fix pr https://github.com/Snowflake-Labs/terraform-provider-snowflake/pull/2364. func TestAcc_GrantPrivilegesToApplicationRole_OnAccountObject_InfinitePlan(t *testing.T) { - name := acc.TestClient().Ids.Alpha() + roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -194,12 +191,12 @@ func TestAcc_GrantPrivilegesToApplicationRole_OnAccountObject_InfinitePlan(t *te Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, name) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnAccountObject_InfinitePlan"), ConfigVariables: config.Variables{ - "name": config.StringVariable(name), + "name": config.StringVariable(roleId.Name()), "database": config.StringVariable(acc.TestDatabaseName), }, ConfigPlanChecks: resource.ConfigPlanChecks{ @@ -214,7 +211,6 @@ func TestAcc_GrantPrivilegesToApplicationRole_OnAccountObject_InfinitePlan(t *te func TestAcc_GrantPrivilegesToAccountRole_OnSchema(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() configVariables := config.Variables{ "name": config.StringVariable(roleFullyQualifiedName), @@ -240,7 +236,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchema(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnSchema"), @@ -268,7 +264,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchema(t *testing.T) { } func TestAcc_GrantPrivilegesToAccountRole_OnSchema_ExactlyOneOf(t *testing.T) { - name := acc.TestClient().Ids.Alpha() + roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -279,7 +275,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchema_ExactlyOneOf(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, name) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnSchema_ExactlyOneOf"), @@ -292,7 +288,6 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchema_ExactlyOneOf(t *testing.T) { func TestAcc_GrantPrivilegesToAccountRole_OnAllSchemasInDatabase(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() databaseName := acc.TestClient().Ids.DatabaseId().FullyQualifiedName() configVariables := config.Variables{ @@ -316,7 +311,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnAllSchemasInDatabase(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnAllSchemasInDatabase"), @@ -345,7 +340,6 @@ func TestAcc_GrantPrivilegesToAccountRole_OnAllSchemasInDatabase(t *testing.T) { func TestAcc_GrantPrivilegesToAccountRole_OnFutureSchemasInDatabase(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() databaseName := acc.TestClient().Ids.DatabaseId().FullyQualifiedName() configVariables := config.Variables{ @@ -369,7 +363,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnFutureSchemasInDatabase(t *testing.T Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnFutureSchemasInDatabase"), @@ -398,7 +392,6 @@ func TestAcc_GrantPrivilegesToAccountRole_OnFutureSchemasInDatabase(t *testing.T func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnObject(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() tableId := acc.TestClient().Ids.RandomSchemaObjectIdentifier() configVariables := config.Variables{ @@ -424,7 +417,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnObject(t *testing.T) Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnSchemaObject_OnObject"), @@ -453,7 +446,8 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnObject(t *testing.T) } func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnObject_OwnershipPrivilege(t *testing.T) { - name := acc.TestClient().Ids.Alpha() + roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() + name := roleId.Name() tableName := acc.TestClient().Ids.Alpha() configVariables := config.Variables{ "name": config.StringVariable(name), @@ -476,7 +470,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnObject_OwnershipPrivi Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, name) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnSchemaObject_OnObject"), @@ -489,7 +483,6 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnObject_OwnershipPrivi func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnAll_InDatabase(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() databaseName := acc.TestClient().Ids.DatabaseId().FullyQualifiedName() configVariables := config.Variables{ @@ -514,7 +507,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnAll_InDatabase(t *tes Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnSchemaObject_OnAll_InDatabase"), @@ -545,7 +538,6 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnAll_InDatabase(t *tes func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnAllPipes(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() databaseName := acc.TestClient().Ids.DatabaseId().FullyQualifiedName() configVariables := config.Variables{ @@ -568,7 +560,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnAllPipes(t *testing.T Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnAllPipes"), @@ -598,7 +590,6 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnAllPipes(t *testing.T func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnFuture_InDatabase(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() databaseName := acc.TestClient().Ids.DatabaseId().FullyQualifiedName() configVariables := config.Variables{ @@ -623,7 +614,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnFuture_InDatabase(t * Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnSchemaObject_OnFuture_InDatabase"), @@ -656,7 +647,6 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnFuture_InDatabase(t * func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnFuture_Streamlits_InDatabase(t *testing.T) { t.Skip("Fix after it starts working on Snowflake side, reference: SNOW-1272222") roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() databaseName := acc.TestClient().Ids.DatabaseId().FullyQualifiedName() configVariables := config.Variables{ @@ -679,7 +669,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnFuture_Streamlits_InD Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnSchemaObject_OnFuture_InDatabase"), @@ -692,7 +682,6 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnFuture_Streamlits_InD func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnAll_Streamlits_InDatabase(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() databaseName := acc.TestClient().Ids.DatabaseId().FullyQualifiedName() configVariables := config.Variables{ @@ -716,7 +705,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnAll_Streamlits_InData Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnSchemaObject_OnAll_InDatabase"), @@ -739,7 +728,6 @@ func TestAcc_GrantPrivilegesToAccountRole_OnSchemaObject_OnAll_Streamlits_InData func TestAcc_GrantPrivilegesToAccountRole_UpdatePrivileges(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() databaseName := acc.TestClient().Ids.DatabaseId().FullyQualifiedName() configVariables := func(allPrivileges bool, privileges []sdk.AccountObjectPrivilege) config.Variables { @@ -771,7 +759,7 @@ func TestAcc_GrantPrivilegesToAccountRole_UpdatePrivileges(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/UpdatePrivileges/privileges"), @@ -832,7 +820,6 @@ func TestAcc_GrantPrivilegesToAccountRole_UpdatePrivileges(t *testing.T) { func TestAcc_GrantPrivilegesToAccountRole_UpdatePrivileges_SnowflakeChecked(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - name := roleId.Name() schemaName := "test_database_role_schema_name" configVariables := func(allPrivileges bool, privileges []string, schemaName string) config.Variables { configVariables := config.Variables{ @@ -865,7 +852,7 @@ func TestAcc_GrantPrivilegesToAccountRole_UpdatePrivileges_SnowflakeChecked(t *t Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, name) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/UpdatePrivileges_SnowflakeChecked/privileges"), @@ -921,7 +908,6 @@ func TestAcc_GrantPrivilegesToAccountRole_UpdatePrivileges_SnowflakeChecked(t *t func TestAcc_GrantPrivilegesToAccountRole_AlwaysApply(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() databaseName := acc.TestClient().Ids.DatabaseId().FullyQualifiedName() configVariables := func(alwaysApply bool) config.Variables { @@ -944,7 +930,7 @@ func TestAcc_GrantPrivilegesToAccountRole_AlwaysApply(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/AlwaysApply"), @@ -1014,8 +1000,10 @@ func TestAcc_GrantPrivilegesToAccountRole_AlwaysApply(t *testing.T) { } func TestAcc_GrantPrivilegesToAccountRole_ImportedPrivileges(t *testing.T) { - sharedDatabaseName := acc.TestClient().Ids.Alpha() - shareName := acc.TestClient().Ids.Alpha() + sharedDatabaseId := acc.TestClient().Ids.RandomAccountObjectIdentifier() + sharedDatabaseName := sharedDatabaseId.Name() + shareId := acc.TestClient().Ids.RandomAccountObjectIdentifier() + shareName := shareId.Name() roleName := acc.TestClient().Ids.Alpha() secondaryAccountName := acc.SecondaryTestClient().Context.CurrentAccount(t) configVariables := config.Variables{ @@ -1038,7 +1026,7 @@ func TestAcc_GrantPrivilegesToAccountRole_ImportedPrivileges(t *testing.T) { CheckDestroy: acc.CheckAccountRolePrivilegesRevoked(t), Steps: []resource.TestStep{ { - PreConfig: func() { createSharedDatabaseOnSecondaryAccount(t, sharedDatabaseName, shareName) }, + PreConfig: func() { createSharedDatabaseOnSecondaryAccount(t, sharedDatabaseId, shareId) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/ImportedPrivileges"), ConfigVariables: configVariables, ConfigPlanChecks: resource.ConfigPlanChecks{ @@ -1064,9 +1052,10 @@ func TestAcc_GrantPrivilegesToAccountRole_ImportedPrivileges(t *testing.T) { // proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1998 is fixed func TestAcc_GrantPrivilegesToAccountRole_ImportedPrivilegesOnSnowflakeDatabase(t *testing.T) { - name := acc.TestClient().Ids.Alpha() + roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() + roleName := roleId.Name() configVariables := config.Variables{ - "role_name": config.StringVariable(name), + "role_name": config.StringVariable(roleName), "privileges": config.ListVariable( config.StringVariable(sdk.AccountObjectPrivilegeImportedPrivileges.String()), ), @@ -1083,7 +1072,7 @@ func TestAcc_GrantPrivilegesToAccountRole_ImportedPrivilegesOnSnowflakeDatabase( Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, name) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/ImportedPrivilegesOnSnowflakeDatabase"), @@ -1114,12 +1103,10 @@ func TestAcc_GrantPrivilegesToAccountRole_ImportedPrivilegesOnSnowflakeDatabase( // TODO(SNOW-1213622): Add test for custom applications using on_account_object.object_type = "DATABASE" func TestAcc_GrantPrivilegesToAccountRole_MultiplePartsInRoleName(t *testing.T) { - nameBytes := []byte(acc.TestClient().Ids.Alpha()) - nameBytes[3] = '.' - nameBytes[6] = '.' - name := string(nameBytes) + roleId := acc.TestClient().Ids.RandomAccountObjectIdentifierContaining(".") + roleName := roleId.Name() configVariables := config.Variables{ - "name": config.StringVariable(name), + "name": config.StringVariable(roleName), "privileges": config.ListVariable( config.StringVariable(string(sdk.GlobalPrivilegeCreateDatabase)), config.StringVariable(string(sdk.GlobalPrivilegeCreateRole)), @@ -1138,13 +1125,13 @@ func TestAcc_GrantPrivilegesToAccountRole_MultiplePartsInRoleName(t *testing.T) Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, name) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnAccount"), ConfigVariables: configVariables, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "account_role_name", name), + resource.TestCheckResourceAttr(resourceName, "account_role_name", roleName), ), }, }, @@ -1154,7 +1141,6 @@ func TestAcc_GrantPrivilegesToAccountRole_MultiplePartsInRoleName(t *testing.T) // proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2533 is fixed func TestAcc_GrantPrivilegesToAccountRole_OnExternalVolume(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() externalVolumeName := acc.TestClient().Ids.Alpha() configVariables := config.Variables{ @@ -1177,7 +1163,7 @@ func TestAcc_GrantPrivilegesToAccountRole_OnExternalVolume(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) cleanupExternalVolume := createExternalVolume(t, externalVolumeName) t.Cleanup(cleanupExternalVolume) @@ -1202,7 +1188,6 @@ func TestAcc_GrantPrivilegesToAccountRole_OnExternalVolume(t *testing.T) { // proved https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2651 func TestAcc_GrantPrivilegesToAccountRole_MLPrivileges(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() configVariables := config.Variables{ "name": config.StringVariable(roleFullyQualifiedName), @@ -1228,7 +1213,7 @@ func TestAcc_GrantPrivilegesToAccountRole_MLPrivileges(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnSchema"), @@ -1256,7 +1241,6 @@ func TestAcc_GrantPrivilegesToAccountRole_MLPrivileges(t *testing.T) { // proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2459 is fixed func TestAcc_GrantPrivilegesToAccountRole_ChangeWithGrantOptionsOutsideOfTerraform_WithGrantOptions(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() tableId := acc.TestClient().Ids.RandomSchemaObjectIdentifier() tableName := tableId.Name() @@ -1282,7 +1266,7 @@ func TestAcc_GrantPrivilegesToAccountRole_ChangeWithGrantOptionsOutsideOfTerrafo Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigPlanChecks: resource.ConfigPlanChecks{ @@ -1318,7 +1302,6 @@ func TestAcc_GrantPrivilegesToAccountRole_ChangeWithGrantOptionsOutsideOfTerrafo // proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2459 is fixed func TestAcc_GrantPrivilegesToAccountRole_ChangeWithGrantOptionsOutsideOfTerraform_WithoutGrantOptions(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() tableId := acc.TestClient().Ids.RandomSchemaObjectIdentifier() tableName := tableId.Name() @@ -1344,7 +1327,7 @@ func TestAcc_GrantPrivilegesToAccountRole_ChangeWithGrantOptionsOutsideOfTerrafo Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigPlanChecks: resource.ConfigPlanChecks{ @@ -1433,9 +1416,9 @@ func revokeAndGrantPrivilegesOnTableToAccountRole( // proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2621 doesn't apply to this resource func TestAcc_GrantPrivilegesToAccountRole_RemoveGrantedObjectOutsideTerraform(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() - databaseName := acc.TestClient().Ids.Alpha() + databaseId := acc.TestClient().Ids.RandomAccountObjectIdentifier() + databaseName := databaseId.Name() configVariables := config.Variables{ "name": config.StringVariable(roleFullyQualifiedName), "database": config.StringVariable(databaseName), @@ -1457,8 +1440,8 @@ func TestAcc_GrantPrivilegesToAccountRole_RemoveGrantedObjectOutsideTerraform(t Steps: []resource.TestStep{ { PreConfig: func() { - _, databaseCleanup = acc.TestClient().Database.CreateDatabaseWithName(t, databaseName) - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, databaseCleanup = acc.TestClient().Database.CreateDatabaseWithIdentifier(t, databaseId) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnAccountObject"), @@ -1478,9 +1461,9 @@ func TestAcc_GrantPrivilegesToAccountRole_RemoveGrantedObjectOutsideTerraform(t // proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2621 doesn't apply to this resource func TestAcc_GrantPrivilegesToAccountRole_RemoveAccountRoleOutsideTerraform(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() - databaseName := acc.TestClient().Ids.Alpha() + databaseId := acc.TestClient().Ids.RandomAccountObjectIdentifier() + databaseName := databaseId.Name() configVariables := config.Variables{ "name": config.StringVariable(roleFullyQualifiedName), "database": config.StringVariable(databaseName), @@ -1502,9 +1485,9 @@ func TestAcc_GrantPrivilegesToAccountRole_RemoveAccountRoleOutsideTerraform(t *t Steps: []resource.TestStep{ { PreConfig: func() { - _, dbCleanup := acc.TestClient().Database.CreateDatabaseWithName(t, databaseName) + _, dbCleanup := acc.TestClient().Database.CreateDatabaseWithIdentifier(t, databaseId) t.Cleanup(dbCleanup) - _, roleCleanup = acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup = acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/OnAccountObject"), @@ -1524,7 +1507,6 @@ func TestAcc_GrantPrivilegesToAccountRole_RemoveAccountRoleOutsideTerraform(t *t // proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2689 is fixed func TestAcc_GrantPrivilegesToAccountRole_AlwaysApply_SetAfterCreate(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() databaseName := acc.TestClient().Ids.DatabaseId().FullyQualifiedName() configVariables := func(alwaysApply bool) config.Variables { @@ -1547,7 +1529,7 @@ func TestAcc_GrantPrivilegesToAccountRole_AlwaysApply_SetAfterCreate(t *testing. Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToAccountRole/AlwaysApply"), @@ -1562,13 +1544,13 @@ func TestAcc_GrantPrivilegesToAccountRole_AlwaysApply_SetAfterCreate(t *testing. }) } -func createSharedDatabaseOnSecondaryAccount(t *testing.T, databaseName string, shareName string) { +func createSharedDatabaseOnSecondaryAccount(t *testing.T, databaseId sdk.AccountObjectIdentifier, shareId sdk.AccountObjectIdentifier) { t.Helper() - database, databaseCleanup := acc.SecondaryTestClient().Database.CreateDatabaseWithName(t, databaseName) + database, databaseCleanup := acc.SecondaryTestClient().Database.CreateDatabaseWithIdentifier(t, databaseId) t.Cleanup(databaseCleanup) - share, shareCleanup := acc.SecondaryTestClient().Share.CreateShareWithName(t, shareName) + share, shareCleanup := acc.SecondaryTestClient().Share.CreateShareWithIdentifier(t, shareId) t.Cleanup(shareCleanup) acc.SecondaryTestClient().Role.GrantPrivilegeOnDatabaseToShare(t, database.ID(), share.ID()) diff --git a/pkg/resources/grant_privileges_to_database_role_acceptance_test.go b/pkg/resources/grant_privileges_to_database_role_acceptance_test.go index 8b174fd5c5..6ca99ccec4 100644 --- a/pkg/resources/grant_privileges_to_database_role_acceptance_test.go +++ b/pkg/resources/grant_privileges_to_database_role_acceptance_test.go @@ -1105,7 +1105,7 @@ func TestAcc_GrantPrivilegesToDatabaseRole_RemoveGrantedObjectOutsideTerraform(t Steps: []resource.TestStep{ { PreConfig: func() { - _, databaseCleanup = acc.TestClient().Database.CreateDatabaseWithName(t, databaseName) + _, databaseCleanup = acc.TestClient().Database.CreateDatabaseWithIdentifier(t, databaseId) t.Cleanup(databaseCleanup) _, databaseRoleCleanup := acc.TestClient().DatabaseRole.CreateDatabaseRoleInDatabaseWithName(t, databaseId, name) t.Cleanup(databaseRoleCleanup) @@ -1149,7 +1149,7 @@ func TestAcc_GrantPrivilegesToDatabaseRole_RemoveDatabaseRoleOutsideTerraform(t Steps: []resource.TestStep{ { PreConfig: func() { - _, dbCleanup := acc.TestClient().Database.CreateDatabaseWithName(t, databaseName) + _, dbCleanup := acc.TestClient().Database.CreateDatabaseWithIdentifier(t, databaseId) t.Cleanup(dbCleanup) _, databaseRoleCleanup = acc.TestClient().DatabaseRole.CreateDatabaseRoleInDatabaseWithName(t, databaseId, name) t.Cleanup(databaseRoleCleanup) diff --git a/pkg/resources/grant_privileges_to_role_acceptance_test.go b/pkg/resources/grant_privileges_to_role_acceptance_test.go index 1c0e6df217..b09a9747b9 100644 --- a/pkg/resources/grant_privileges_to_role_acceptance_test.go +++ b/pkg/resources/grant_privileges_to_role_acceptance_test.go @@ -961,7 +961,6 @@ func TestAcc_GrantPrivilegesToRole_onSchemaObject_futureInDatabase_externalTable func TestAcc_GrantPrivilegesToRole_OnAllPipes(t *testing.T) { roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() - roleName := roleId.Name() roleFullyQualifiedName := roleId.FullyQualifiedName() databaseName := acc.TestClient().Ids.DatabaseId().FullyQualifiedName() configVariables := config.Variables{ @@ -984,7 +983,7 @@ func TestAcc_GrantPrivilegesToRole_OnAllPipes(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToRole/OnAllPipes"), @@ -1079,8 +1078,10 @@ resource "snowflake_grant_privileges_to_role" "test_invalidation" { } func TestAcc_GrantPrivilegesToRole_ImportedPrivileges(t *testing.T) { - sharedDatabaseName := acc.TestClient().Ids.Alpha() - shareName := acc.TestClient().Ids.Alpha() + sharedDatabaseId := acc.TestClient().Ids.RandomAccountObjectIdentifier() + sharedDatabaseName := sharedDatabaseId.Name() + shareId := acc.TestClient().Ids.RandomAccountObjectIdentifier() + shareName := shareId.Name() roleName := acc.TestClient().Ids.Alpha() secondaryAccountName := acc.SecondaryTestClient().Context.CurrentAccount(t) configVariables := config.Variables{ @@ -1103,7 +1104,7 @@ func TestAcc_GrantPrivilegesToRole_ImportedPrivileges(t *testing.T) { CheckDestroy: acc.CheckAccountRolePrivilegesRevoked(t), Steps: []resource.TestStep{ { - PreConfig: func() { createSharedDatabaseOnSecondaryAccount(t, sharedDatabaseName, shareName) }, + PreConfig: func() { createSharedDatabaseOnSecondaryAccount(t, sharedDatabaseId, shareId) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToRole/ImportedPrivileges"), ConfigVariables: configVariables, ConfigPlanChecks: resource.ConfigPlanChecks{ @@ -1128,12 +1129,9 @@ func TestAcc_GrantPrivilegesToRole_ImportedPrivileges(t *testing.T) { } func TestAcc_GrantPrivilegesToRole_MultiplePartsInRoleName(t *testing.T) { - nameBytes := []byte(acc.TestClient().Ids.Alpha()) - nameBytes[3] = '.' - nameBytes[6] = '.' - name := string(nameBytes) + roleId := acc.TestClient().Ids.RandomAccountObjectIdentifierContaining(".") configVariables := config.Variables{ - "name": config.StringVariable(name), + "name": config.StringVariable(roleId.Name()), "privileges": config.ListVariable( config.StringVariable(string(sdk.GlobalPrivilegeCreateDatabase)), config.StringVariable(string(sdk.GlobalPrivilegeCreateRole)), @@ -1152,13 +1150,13 @@ func TestAcc_GrantPrivilegesToRole_MultiplePartsInRoleName(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, name) + _, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToRole/OnAccount"), ConfigVariables: configVariables, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "role_name", name), + resource.TestCheckResourceAttr(resourceName, "role_name", roleId.Name()), ), }, }, diff --git a/pkg/resources/grant_privileges_to_share_acceptance_test.go b/pkg/resources/grant_privileges_to_share_acceptance_test.go index deae3d84aa..5ae2e86528 100644 --- a/pkg/resources/grant_privileges_to_share_acceptance_test.go +++ b/pkg/resources/grant_privileges_to_share_acceptance_test.go @@ -518,7 +518,8 @@ func TestAcc_GrantPrivilegesToShare_NoOnOption(t *testing.T) { // proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2621 doesn't apply to this resource func TestAcc_GrantPrivilegesToShare_RemoveShareOutsideTerraform(t *testing.T) { databaseName := acc.TestClient().Ids.Alpha() - shareName := acc.TestClient().Ids.Alpha() + shareId := acc.TestClient().Ids.RandomAccountObjectIdentifier() + shareName := shareId.Name() configVariables := config.Variables{ "to_share": config.StringVariable(shareName), @@ -538,7 +539,7 @@ func TestAcc_GrantPrivilegesToShare_RemoveShareOutsideTerraform(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, shareCleanup = acc.TestClient().Share.CreateShareWithName(t, shareName) + _, shareCleanup = acc.TestClient().Share.CreateShareWithIdentifier(t, shareId) t.Cleanup(shareCleanup) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantPrivilegesToShare/OnCustomShare"), diff --git a/pkg/resources/schema_acceptance_test.go b/pkg/resources/schema_acceptance_test.go index 8538e6821a..dc77b363bd 100644 --- a/pkg/resources/schema_acceptance_test.go +++ b/pkg/resources/schema_acceptance_test.go @@ -346,7 +346,8 @@ func TestAcc_Schema_RemoveDatabaseOutsideOfTerraform(t *testing.T) { } func TestAcc_Schema_RemoveSchemaOutsideOfTerraform(t *testing.T) { - databaseName := acc.TestClient().Ids.Alpha() + databaseId := acc.TestClient().Ids.RandomAccountObjectIdentifier() + databaseName := databaseId.Name() schemaName := acc.TestClient().Ids.Alpha() configVariables := map[string]config.Variable{ "schema_name": config.StringVariable(schemaName), @@ -365,7 +366,7 @@ func TestAcc_Schema_RemoveSchemaOutsideOfTerraform(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { - _, cleanupDatabase = acc.TestClient().Database.CreateDatabaseWithName(t, databaseName) + _, cleanupDatabase = acc.TestClient().Database.CreateDatabaseWithIdentifier(t, databaseId) t.Cleanup(cleanupDatabase) }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_Schema_RemoveOutsideOfTerraform"), diff --git a/pkg/resources/view_acceptance_test.go b/pkg/resources/view_acceptance_test.go index a2a4baa8d6..6d6cd20003 100644 --- a/pkg/resources/view_acceptance_test.go +++ b/pkg/resources/view_acceptance_test.go @@ -422,7 +422,7 @@ func TestAcc_View_Issue2640(t *testing.T) { viewName := viewId.Name() part1 := "SELECT ROLE_NAME, ROLE_OWNER FROM INFORMATION_SCHEMA.APPLICABLE_ROLES" part2 := "SELECT ROLE_OWNER, ROLE_NAME FROM INFORMATION_SCHEMA.APPLICABLE_ROLES" - roleName := acc.TestClient().Ids.Alpha() + roleId := acc.TestClient().Ids.RandomAccountObjectIdentifier() resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, @@ -444,7 +444,7 @@ func TestAcc_View_Issue2640(t *testing.T) { // try to import secure view without being its owner (proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2640) { PreConfig: func() { - role, roleCleanup := acc.TestClient().Role.CreateRoleWithName(t, roleName) + role, roleCleanup := acc.TestClient().Role.CreateRoleWithIdentifier(t, roleId) t.Cleanup(roleCleanup) acc.TestClient().Role.GrantOwnershipOnSchemaObject(t, role.ID(), viewId, sdk.ObjectTypeView, sdk.Revoke) }, diff --git a/pkg/sdk/alerts_test.go b/pkg/sdk/alerts_test.go index a7183eae2f..80ee4970cc 100644 --- a/pkg/sdk/alerts_test.go +++ b/pkg/sdk/alerts_test.go @@ -10,7 +10,7 @@ func TestAlertCreate(t *testing.T) { id := randomSchemaObjectIdentifier() t.Run("with complete options", func(t *testing.T) { - newComment := random.String() + newComment := random.Comment() warehouse := AccountObjectIdentifier{"warehouse"} existsCondition := "SELECT 1" condition := AlertCondition{[]string{existsCondition}} @@ -41,7 +41,7 @@ func TestAlertAlter(t *testing.T) { }) t.Run("fail when 2 alter actions specified", func(t *testing.T) { - newComment := random.String() + newComment := random.Comment() opts := &AlterAlertOptions{ name: id, Action: &AlertActionResume, @@ -71,7 +71,7 @@ func TestAlertAlter(t *testing.T) { }) t.Run("with set", func(t *testing.T) { - newComment := random.String() + newComment := random.Comment() opts := &AlterAlertOptions{ name: id, Set: &AlertSet{ diff --git a/pkg/sdk/applications_gen_test.go b/pkg/sdk/applications_gen_test.go index 96ecbb1888..ed2ae926ea 100644 --- a/pkg/sdk/applications_gen_test.go +++ b/pkg/sdk/applications_gen_test.go @@ -2,8 +2,6 @@ package sdk import ( "testing" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestApplications_Create(t *testing.T) { @@ -47,7 +45,7 @@ func TestApplications_Create(t *testing.T) { }) t.Run("all options", func(t *testing.T) { - tid := NewSchemaObjectIdentifier(random.StringN(4), random.StringN(4), random.StringN(4)) + tid := randomSchemaObjectIdentifier() opts := defaultOpts() opts.Comment = String("test") diff --git a/pkg/sdk/database_role_test.go b/pkg/sdk/database_role_test.go index 695a060ab0..9bd95efe37 100644 --- a/pkg/sdk/database_role_test.go +++ b/pkg/sdk/database_role_test.go @@ -2,8 +2,6 @@ package sdk import ( "testing" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestDatabaseRoleCreate(t *testing.T) { @@ -100,7 +98,7 @@ func TestDatabaseRoleAlter(t *testing.T) { }) t.Run("validation: new name from different db", func(t *testing.T) { - newId := NewDatabaseObjectIdentifier(id.DatabaseName()+random.StringN(1), random.StringN(12)) + newId := randomDatabaseObjectIdentifier() opts := defaultOpts() opts.Rename = &DatabaseRoleRename{ @@ -118,7 +116,7 @@ func TestDatabaseRoleAlter(t *testing.T) { }) t.Run("rename", func(t *testing.T) { - newId := NewDatabaseObjectIdentifier(id.DatabaseName(), random.StringN(12)) + newId := randomDatabaseObjectIdentifierInDatabase(id.DatabaseId()) opts := defaultOpts() opts.Rename = &DatabaseRoleRename{ diff --git a/pkg/sdk/event_tables_gen_test.go b/pkg/sdk/event_tables_gen_test.go index d2a68e6269..6f795f557e 100644 --- a/pkg/sdk/event_tables_gen_test.go +++ b/pkg/sdk/event_tables_gen_test.go @@ -2,8 +2,6 @@ package sdk import ( "testing" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestEventTables_Create(t *testing.T) { @@ -36,12 +34,12 @@ func TestEventTables_Create(t *testing.T) { opts.DefaultDdlCollation = String("en_US") opts.CopyGrants = Bool(true) opts.Comment = String("test") - pn := NewSchemaObjectIdentifier(random.StringN(4), random.StringN(4), random.StringN(4)) + pn := randomSchemaObjectIdentifier() opts.RowAccessPolicy = &TableRowAccessPolicy{ Name: pn, On: []string{"c1", "c2"}, } - tn := NewSchemaObjectIdentifier(random.StringN(4), random.StringN(4), random.StringN(4)) + tn := randomSchemaObjectIdentifier() opts.Tag = []TagAssociation{ { Name: tn, @@ -155,7 +153,7 @@ func TestEventTables_Alter(t *testing.T) { t.Run("alter: rename to", func(t *testing.T) { opts := defaultOpts() - target := NewSchemaObjectIdentifier(id.DatabaseName(), id.SchemaName(), random.StringN(12)) + target := randomSchemaObjectIdentifier() opts.RenameTo = &target assertOptsValidAndSQLEquals(t, opts, `ALTER TABLE IF NOT EXISTS %s RENAME TO %s`, id.FullyQualifiedName(), target.FullyQualifiedName()) }) diff --git a/pkg/sdk/functions_gen_test.go b/pkg/sdk/functions_gen_test.go index 327943d8da..13b7bff262 100644 --- a/pkg/sdk/functions_gen_test.go +++ b/pkg/sdk/functions_gen_test.go @@ -2,8 +2,6 @@ package sdk import ( "testing" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestFunctions_CreateForJava(t *testing.T) { @@ -503,7 +501,7 @@ func TestFunctions_Alter(t *testing.T) { t.Run("alter: rename to", func(t *testing.T) { opts := defaultOpts() - target := NewSchemaObjectIdentifier(id.DatabaseName(), id.SchemaName(), random.StringN(12)) + target := randomSchemaObjectIdentifierInSchema(id.SchemaId()) opts.RenameTo = &target assertOptsValidAndSQLEquals(t, opts, `ALTER FUNCTION IF EXISTS %s (VARCHAR, NUMBER) RENAME TO %s`, id.FullyQualifiedName(), opts.RenameTo.FullyQualifiedName()) }) diff --git a/pkg/sdk/masking_policy_test.go b/pkg/sdk/masking_policy_test.go index 5971a396e9..926163a409 100644 --- a/pkg/sdk/masking_policy_test.go +++ b/pkg/sdk/masking_policy_test.go @@ -58,7 +58,7 @@ func TestMaskingPolicyCreate(t *testing.T) { }) t.Run("with complete options", func(t *testing.T) { - comment := random.String() + comment := random.Comment() opts := &CreateMaskingPolicyOptions{ OrReplace: Bool(true), @@ -92,7 +92,7 @@ func TestMaskingPolicyAlter(t *testing.T) { }) t.Run("with set", func(t *testing.T) { - newComment := random.String() + newComment := random.Comment() opts := &AlterMaskingPolicyOptions{ name: id, Set: &MaskingPolicySet{ @@ -113,7 +113,7 @@ func TestMaskingPolicyAlter(t *testing.T) { }) t.Run("rename", func(t *testing.T) { - newID := NewSchemaObjectIdentifier(id.databaseName, id.schemaName, random.UUID()) + newID := randomSchemaObjectIdentifierInSchema(id.SchemaId()) opts := &AlterMaskingPolicyOptions{ name: id, NewName: &newID, diff --git a/pkg/sdk/password_policy_test.go b/pkg/sdk/password_policy_test.go index 084fdbee79..447b53a432 100644 --- a/pkg/sdk/password_policy_test.go +++ b/pkg/sdk/password_policy_test.go @@ -2,8 +2,6 @@ package sdk import ( "testing" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestPasswordPolicyCreate(t *testing.T) { @@ -108,7 +106,7 @@ func TestPasswordPolicyAlter(t *testing.T) { }) t.Run("rename", func(t *testing.T) { - newID := NewSchemaObjectIdentifier(id.databaseName, id.schemaName, random.UUID()) + newID := randomSchemaObjectIdentifierInSchema(id.SchemaId()) opts := &AlterPasswordPolicyOptions{ name: id, NewName: &newID, diff --git a/pkg/sdk/procedures_gen_test.go b/pkg/sdk/procedures_gen_test.go index bbd7e85a07..bef49aff9f 100644 --- a/pkg/sdk/procedures_gen_test.go +++ b/pkg/sdk/procedures_gen_test.go @@ -2,8 +2,6 @@ package sdk import ( "testing" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestProcedures_CreateForJava(t *testing.T) { @@ -467,7 +465,7 @@ func TestProcedures_Alter(t *testing.T) { t.Run("alter: rename to", func(t *testing.T) { opts := defaultOpts() - target := NewSchemaObjectIdentifier(id.DatabaseName(), id.SchemaName(), random.StringN(12)) + target := randomSchemaObjectIdentifierInSchema(id.SchemaId()) opts.RenameTo = &target assertOptsValidAndSQLEquals(t, opts, `ALTER PROCEDURE IF EXISTS %s (VARCHAR, NUMBER) RENAME TO %s`, id.FullyQualifiedName(), opts.RenameTo.FullyQualifiedName()) }) diff --git a/pkg/sdk/random_test.go b/pkg/sdk/random_test.go index 6ec2646ded..406d1bc57f 100644 --- a/pkg/sdk/random_test.go +++ b/pkg/sdk/random_test.go @@ -4,10 +4,19 @@ import ( "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) +var ( + invalidAccountObjectIdentifier = NewAccountObjectIdentifier(random.StringN(256)) + invalidSchemaObjectIdentifier = NewSchemaObjectIdentifier(random.StringN(255), random.StringN(255), random.StringN(255)) +) + func randomSchemaObjectIdentifier() SchemaObjectIdentifier { return NewSchemaObjectIdentifier(random.StringN(12), random.StringN(12), random.StringN(12)) } +func randomSchemaObjectIdentifierInSchema(schemaId DatabaseObjectIdentifier) SchemaObjectIdentifier { + return NewSchemaObjectIdentifierInSchema(schemaId, random.StringN(12)) +} + func randomExternalObjectIdentifier() ExternalObjectIdentifier { return NewExternalObjectIdentifier(NewAccountIdentifierFromAccountLocator(random.StringN(12)), randomAccountObjectIdentifier()) } @@ -16,6 +25,10 @@ func randomDatabaseObjectIdentifier() DatabaseObjectIdentifier { return NewDatabaseObjectIdentifier(random.StringN(12), random.StringN(12)) } +func randomDatabaseObjectIdentifierInDatabase(databaseId AccountObjectIdentifier) DatabaseObjectIdentifier { + return NewDatabaseObjectIdentifier(databaseId.Name(), random.StringN(12)) +} + func randomAccountObjectIdentifier() AccountObjectIdentifier { return NewAccountObjectIdentifier(random.StringN(12)) } diff --git a/pkg/sdk/sequences_gen_test.go b/pkg/sdk/sequences_gen_test.go index 3c16339b6c..310757e3c3 100644 --- a/pkg/sdk/sequences_gen_test.go +++ b/pkg/sdk/sequences_gen_test.go @@ -2,8 +2,6 @@ package sdk import ( "testing" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestSequences_Create(t *testing.T) { @@ -79,7 +77,7 @@ func TestSequences_Alter(t *testing.T) { t.Run("alter: rename to", func(t *testing.T) { opts := defaultOpts() - target := NewSchemaObjectIdentifier(id.DatabaseName(), id.SchemaName(), random.StringN(12)) + target := randomSchemaObjectIdentifierInSchema(id.SchemaId()) opts.RenameTo = &target assertOptsValidAndSQLEquals(t, opts, `ALTER SEQUENCE IF EXISTS %s RENAME TO %s`, id.FullyQualifiedName(), opts.RenameTo.FullyQualifiedName()) }) diff --git a/pkg/sdk/tables_test.go b/pkg/sdk/tables_test.go index fa621e40ad..380c6e8a32 100644 --- a/pkg/sdk/tables_test.go +++ b/pkg/sdk/tables_test.go @@ -371,8 +371,8 @@ func TestTableCreate(t *testing.T) { }) t.Run("with complete options", func(t *testing.T) { - columnComment := random.String() - tableComment := random.String() + columnComment := random.Comment() + tableComment := random.Comment() collation := "de" columnName := "FIRST_COLUMN" columnType, err := ToDataType("VARCHAR") @@ -893,7 +893,7 @@ func TestTableAlter(t *testing.T) { }) t.Run("rename", func(t *testing.T) { - newID := NewSchemaObjectIdentifier(id.databaseName, id.schemaName, random.UUID()) + newID := randomSchemaObjectIdentifierInSchema(id.SchemaId()) opts := &alterTableOptions{ name: id, NewName: &newID, @@ -902,7 +902,7 @@ func TestTableAlter(t *testing.T) { }) t.Run("swap with", func(t *testing.T) { - targetTableId := NewSchemaObjectIdentifier(id.databaseName, id.schemaName, random.UUID()) + targetTableId := randomSchemaObjectIdentifierInSchema(id.SchemaId()) opts := &alterTableOptions{ name: id, SwapWith: &targetTableId, @@ -1315,7 +1315,7 @@ func TestTableAlter(t *testing.T) { }) t.Run("set: with complete options", func(t *testing.T) { - comment := random.String() + comment := random.Comment() opts := &alterTableOptions{ name: id, Set: &TableSet{ diff --git a/pkg/sdk/tags_test.go b/pkg/sdk/tags_test.go index 179bf16b12..42866b00fb 100644 --- a/pkg/sdk/tags_test.go +++ b/pkg/sdk/tags_test.go @@ -3,8 +3,6 @@ package sdk import ( "fmt" "testing" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" ) func TestTagCreate(t *testing.T) { @@ -199,7 +197,7 @@ func TestTagAlter(t *testing.T) { t.Run("alter with rename to", func(t *testing.T) { opts := defaultOpts() - opts.Rename = &TagRename{Name: NewSchemaObjectIdentifierInSchema(id.SchemaId(), random.StringN(12))} + opts.Rename = &TagRename{Name: randomSchemaObjectIdentifierInSchema(id.SchemaId())} assertOptsValidAndSQLEquals(t, opts, `ALTER TAG %s RENAME TO %s`, id.FullyQualifiedName(), opts.Rename.Name.FullyQualifiedName()) }) @@ -290,7 +288,7 @@ func TestTagAlter(t *testing.T) { }) t.Run("validation: new name from different db", func(t *testing.T) { - newId := NewSchemaObjectIdentifier(id.DatabaseName()+random.StringN(1), random.StringN(12), random.StringN(12)) + newId := randomSchemaObjectIdentifier() opts := defaultOpts() opts.Rename = &TagRename{ diff --git a/pkg/sdk/testint/accounts_integration_test.go b/pkg/sdk/testint/accounts_integration_test.go index e0af25a74e..df1674de30 100644 --- a/pkg/sdk/testint/accounts_integration_test.go +++ b/pkg/sdk/testint/accounts_integration_test.go @@ -57,7 +57,7 @@ func TestInt_AccountCreate(t *testing.T) { opts := &sdk.CreateAccountOptions{ AdminName: "someadmin", - AdminPassword: sdk.String(random.StringN(12)), + AdminPassword: sdk.String(random.Password()), FirstName: sdk.String("Ad"), LastName: sdk.String("Min"), Email: "admin@example.com", diff --git a/pkg/sdk/testint/alerts_integration_test.go b/pkg/sdk/testint/alerts_integration_test.go index 143a988e12..afaeb8a82f 100644 --- a/pkg/sdk/testint/alerts_integration_test.go +++ b/pkg/sdk/testint/alerts_integration_test.go @@ -84,12 +84,12 @@ func TestInt_AlertCreate(t *testing.T) { ctx := testContext(t) t.Run("test complete case", func(t *testing.T) { - name := random.String() + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := id.Name() schedule := "USING CRON * * * * TUE,THU UTC" condition := "SELECT 1" action := "SELECT 1" comment := random.Comment() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.Alerts.Create(ctx, id, testWarehouse(t).ID(), schedule, condition, action, &sdk.CreateAlertOptions{ OrReplace: sdk.Bool(true), IfNotExists: sdk.Bool(false), @@ -120,12 +120,12 @@ func TestInt_AlertCreate(t *testing.T) { }) t.Run("test if_not_exists", func(t *testing.T) { - name := random.String() + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := id.Name() schedule := "USING CRON * * * * TUE,THU UTC" condition := "SELECT 1" action := "SELECT 1" comment := random.Comment() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.Alerts.Create(ctx, id, testWarehouse(t).ID(), schedule, condition, action, &sdk.CreateAlertOptions{ OrReplace: sdk.Bool(false), IfNotExists: sdk.Bool(true), @@ -156,11 +156,11 @@ func TestInt_AlertCreate(t *testing.T) { }) t.Run("test no options", func(t *testing.T) { - name := random.String() + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := id.Name() schedule := "USING CRON * * * * TUE,THU UTC" condition := "SELECT 1" action := "SELECT 1" - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.Alerts.Create(ctx, id, testWarehouse(t).ID(), schedule, condition, action, nil) require.NoError(t, err) alertDetails, err := client.Alerts.Describe(ctx, id) @@ -186,7 +186,8 @@ func TestInt_AlertCreate(t *testing.T) { }) t.Run("test multiline action", func(t *testing.T) { - name := random.String() + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := id.Name() schedule := "USING CRON * * * * TUE,THU UTC" condition := "SELECT 1" action := ` @@ -198,7 +199,6 @@ func TestInt_AlertCreate(t *testing.T) { 2 end ` - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.Alerts.Create(ctx, id, testWarehouse(t).ID(), schedule, condition, action, nil) require.NoError(t, err) alertDetails, err := client.Alerts.Describe(ctx, id) @@ -384,7 +384,7 @@ func TestInt_AlertsShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest, warehouseTest := testDb(t), testSchema(t), testWarehouse(t) + warehouseTest := testWarehouse(t) cleanupAlertHandle := func(t *testing.T, id sdk.SchemaObjectIdentifier) func() { t.Helper() return func() { @@ -409,9 +409,8 @@ func TestInt_AlertsShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createAlertHandle(t, id1) createAlertHandle(t, id2) @@ -426,11 +425,10 @@ func TestInt_AlertsShowByID(t *testing.T) { }) t.Run("show by id: check fields", func(t *testing.T) { - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - createAlertHandle(t, id1) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() + createAlertHandle(t, id) - alert, err := client.Alerts.ShowByID(ctx, id1) + alert, err := client.Alerts.ShowByID(ctx, id) require.NoError(t, err) assert.Equal(t, "ROLE", alert.OwnerRoleType) }) diff --git a/pkg/sdk/testint/application_packages_integration_test.go b/pkg/sdk/testint/application_packages_integration_test.go index b2d80cfdf9..94f3ff0773 100644 --- a/pkg/sdk/testint/application_packages_integration_test.go +++ b/pkg/sdk/testint/application_packages_integration_test.go @@ -80,7 +80,7 @@ func TestInt_ApplicationPackages(t *testing.T) { t.Run("create application package", func(t *testing.T) { id := testClientHelper().Ids.RandomAccountObjectIdentifier() - comment := random.StringN(4) + comment := random.Comment() request := sdk.NewCreateApplicationPackageRequest(id). WithComment(&comment). WithTag([]sdk.TagAssociation{ diff --git a/pkg/sdk/testint/applications_integration_test.go b/pkg/sdk/testint/applications_integration_test.go index a2b9f2eac4..8a1b68283b 100644 --- a/pkg/sdk/testint/applications_integration_test.go +++ b/pkg/sdk/testint/applications_integration_test.go @@ -113,7 +113,7 @@ func TestInt_Applications(t *testing.T) { _, applicationPackage := createApplicationPackageHandle(t, version, patch, true) id := testClientHelper().Ids.RandomAccountObjectIdentifier() - comment := random.StringN(4) + comment := random.Comment() request := sdk.NewCreateApplicationRequest(id, applicationPackage.ID()). WithComment(&comment). WithTag([]sdk.TagAssociation{ @@ -143,7 +143,7 @@ func TestInt_Applications(t *testing.T) { id := testClientHelper().Ids.RandomAccountObjectIdentifier() vr := sdk.NewApplicationVersionRequest().WithVersionAndPatch(sdk.NewVersionAndPatchRequest(version, &patch)) - comment := random.StringN(4) + comment := random.Comment() request := sdk.NewCreateApplicationRequest(id, applicationPackage.ID()). WithDebugMode(sdk.Bool(true)). WithComment(&comment). @@ -161,7 +161,7 @@ func TestInt_Applications(t *testing.T) { id := testClientHelper().Ids.RandomAccountObjectIdentifier() vr := sdk.NewApplicationVersionRequest().WithVersionDirectory(sdk.String("@" + stage.ID().FullyQualifiedName())) - comment := random.StringN(4) + comment := random.Comment() request := sdk.NewCreateApplicationRequest(id, applicationPackage.ID()). WithDebugMode(sdk.Bool(true)). WithComment(&comment). @@ -193,7 +193,7 @@ func TestInt_Applications(t *testing.T) { _, e, _ := createApplicationHandle(t, version, patch, false, true, false) id := e.ID() - comment, mode := random.StringN(4), true + comment, mode := random.Comment(), true set := sdk.NewApplicationSetRequest(). WithComment(&comment). WithDebugMode(&mode) diff --git a/pkg/sdk/testint/database_role_integration_test.go b/pkg/sdk/testint/database_role_integration_test.go index 0f34fda4a3..12774c96ee 100644 --- a/pkg/sdk/testint/database_role_integration_test.go +++ b/pkg/sdk/testint/database_role_integration_test.go @@ -14,10 +14,10 @@ func TestInt_DatabaseRoles(t *testing.T) { client := testClient(t) ctx := testContext(t) - assertDatabaseRole := func(t *testing.T, databaseRole *sdk.DatabaseRole, expectedName string, expectedComment string) { + assertDatabaseRole := func(t *testing.T, databaseRole *sdk.DatabaseRole, expectedId sdk.DatabaseObjectIdentifier, expectedComment string) { t.Helper() assert.NotEmpty(t, databaseRole.CreatedOn) - assert.Equal(t, expectedName, databaseRole.Name) + assert.Equal(t, expectedId.Name(), databaseRole.Name) assert.Equal(t, "ACCOUNTADMIN", databaseRole.Owner) assert.Equal(t, expectedComment, databaseRole.Comment) assert.Equal(t, 0, databaseRole.GrantedToRoles) @@ -34,8 +34,7 @@ func TestInt_DatabaseRoles(t *testing.T) { createDatabaseRole := func(t *testing.T) *sdk.DatabaseRole { t.Helper() - name := random.String() - id := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, name) + id := testClientHelper().Ids.RandomDatabaseObjectIdentifier() err := client.DatabaseRoles.Create(ctx, sdk.NewCreateDatabaseRoleRequest(id)) require.NoError(t, err) @@ -48,8 +47,7 @@ func TestInt_DatabaseRoles(t *testing.T) { } t.Run("create database_role: complete case", func(t *testing.T) { - name := random.String() - id := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, name) + id := testClientHelper().Ids.RandomDatabaseObjectIdentifier() comment := random.Comment() request := sdk.NewCreateDatabaseRoleRequest(id).WithComment(&comment).WithIfNotExists(true) @@ -60,12 +58,11 @@ func TestInt_DatabaseRoles(t *testing.T) { databaseRole, err := client.DatabaseRoles.ShowByID(ctx, id) require.NoError(t, err) - assertDatabaseRole(t, databaseRole, name, comment) + assertDatabaseRole(t, databaseRole, id, comment) }) t.Run("create database_role: no optionals", func(t *testing.T) { - name := random.String() - id := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, name) + id := testClientHelper().Ids.RandomDatabaseObjectIdentifier() err := client.DatabaseRoles.Create(ctx, sdk.NewCreateDatabaseRoleRequest(id)) require.NoError(t, err) @@ -74,12 +71,11 @@ func TestInt_DatabaseRoles(t *testing.T) { databaseRole, err := client.DatabaseRoles.ShowByID(ctx, id) require.NoError(t, err) - assertDatabaseRole(t, databaseRole, name, "") + assertDatabaseRole(t, databaseRole, id, "") }) t.Run("drop database_role: existing", func(t *testing.T) { - name := random.String() - id := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, name) + id := testClientHelper().Ids.RandomDatabaseObjectIdentifier() err := client.DatabaseRoles.Create(ctx, sdk.NewCreateDatabaseRoleRequest(id)) require.NoError(t, err) @@ -99,8 +95,7 @@ func TestInt_DatabaseRoles(t *testing.T) { }) t.Run("alter database_role: set value and unset value", func(t *testing.T) { - name := random.String() - id := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, name) + id := testClientHelper().Ids.RandomDatabaseObjectIdentifier() err := client.DatabaseRoles.Create(ctx, sdk.NewCreateDatabaseRoleRequest(id)) require.NoError(t, err) @@ -126,14 +121,12 @@ func TestInt_DatabaseRoles(t *testing.T) { }) t.Run("alter database_role: rename", func(t *testing.T) { - name := random.String() - id := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, name) + id := testClientHelper().Ids.RandomDatabaseObjectIdentifier() err := client.DatabaseRoles.Create(ctx, sdk.NewCreateDatabaseRoleRequest(id)) require.NoError(t, err) - newName := random.String() - newId := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, newName) + newId := testClientHelper().Ids.RandomDatabaseObjectIdentifier() alterRequest := sdk.NewAlterDatabaseRoleRequest(id).WithRename(newId) err = client.DatabaseRoles.Alter(ctx, alterRequest) @@ -150,22 +143,20 @@ func TestInt_DatabaseRoles(t *testing.T) { databaseRole, err := client.DatabaseRoles.ShowByID(ctx, newId) require.NoError(t, err) - assertDatabaseRole(t, databaseRole, newName, "") + assertDatabaseRole(t, databaseRole, newId, "") }) t.Run("alter database_role: rename to other database", func(t *testing.T) { secondDatabase, secondDatabaseCleanup := testClientHelper().Database.CreateDatabase(t) t.Cleanup(secondDatabaseCleanup) - name := random.String() - id := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, name) + id := testClientHelper().Ids.RandomDatabaseObjectIdentifier() err := client.DatabaseRoles.Create(ctx, sdk.NewCreateDatabaseRoleRequest(id)) require.NoError(t, err) t.Cleanup(cleanupDatabaseRoleProvider(id)) - newName := random.String() - newId := sdk.NewDatabaseObjectIdentifier(secondDatabase.Name, newName) + newId := testClientHelper().Ids.RandomDatabaseObjectIdentifierInDatabase(secondDatabase.ID()) alterRequest := sdk.NewAlterDatabaseRoleRequest(id).WithRename(newId) err = client.DatabaseRoles.Alter(ctx, alterRequest) diff --git a/pkg/sdk/testint/dynamic_table_integration_test.go b/pkg/sdk/testint/dynamic_table_integration_test.go index 3de0817d7a..3facd1a081 100644 --- a/pkg/sdk/testint/dynamic_table_integration_test.go +++ b/pkg/sdk/testint/dynamic_table_integration_test.go @@ -50,24 +50,24 @@ func TestInt_DynamicTableCreateAndDrop(t *testing.T) { }) t.Run("test complete with target lag", func(t *testing.T) { - name := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() targetLag := sdk.TargetLag{ Downstream: sdk.Bool(true), } query := "select id from " + tableTest.ID().FullyQualifiedName() comment := random.Comment() - err := client.DynamicTables.Create(ctx, sdk.NewCreateDynamicTableRequest(name, testWarehouse(t).ID(), targetLag, query).WithOrReplace(true).WithComment(&comment)) + err := client.DynamicTables.Create(ctx, sdk.NewCreateDynamicTableRequest(id, testWarehouse(t).ID(), targetLag, query).WithOrReplace(true).WithComment(&comment)) require.NoError(t, err) t.Cleanup(func() { - err = client.DynamicTables.Drop(ctx, sdk.NewDropDynamicTableRequest(name)) + err = client.DynamicTables.Drop(ctx, sdk.NewDropDynamicTableRequest(id)) require.NoError(t, err) }) - entities, err := client.DynamicTables.Show(ctx, sdk.NewShowDynamicTableRequest().WithLike(&sdk.Like{Pattern: sdk.String(name.Name())})) + entities, err := client.DynamicTables.Show(ctx, sdk.NewShowDynamicTableRequest().WithLike(&sdk.Like{Pattern: sdk.String(id.Name())})) require.NoError(t, err) require.Equal(t, 1, len(entities)) entity := entities[0] - require.Equal(t, name.Name(), entity.Name) + require.Equal(t, id.Name(), entity.Name) require.Equal(t, testWarehouse(t).ID().Name(), entity.Warehouse) require.Equal(t, "DOWNSTREAM", entity.TargetLag) require.Equal(t, sdk.DynamicTableRefreshModeIncremental, entity.RefreshMode) @@ -76,7 +76,7 @@ func TestInt_DynamicTableCreateAndDrop(t *testing.T) { }) t.Run("test complete with refresh mode and initialize", func(t *testing.T) { - name := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() targetLag := sdk.TargetLag{ MaximumDuration: sdk.String("2 minutes"), } @@ -84,18 +84,18 @@ func TestInt_DynamicTableCreateAndDrop(t *testing.T) { comment := random.Comment() refreshMode := sdk.DynamicTableRefreshModeFull initialize := sdk.DynamicTableInitializeOnSchedule - err := client.DynamicTables.Create(ctx, sdk.NewCreateDynamicTableRequest(name, testWarehouse(t).ID(), targetLag, query).WithOrReplace(true).WithInitialize(initialize).WithRefreshMode(refreshMode).WithComment(&comment)) + err := client.DynamicTables.Create(ctx, sdk.NewCreateDynamicTableRequest(id, testWarehouse(t).ID(), targetLag, query).WithOrReplace(true).WithInitialize(initialize).WithRefreshMode(refreshMode).WithComment(&comment)) require.NoError(t, err) t.Cleanup(func() { - err = client.DynamicTables.Drop(ctx, sdk.NewDropDynamicTableRequest(name)) + err = client.DynamicTables.Drop(ctx, sdk.NewDropDynamicTableRequest(id)) require.NoError(t, err) }) - entities, err := client.DynamicTables.Show(ctx, sdk.NewShowDynamicTableRequest().WithLike(&sdk.Like{Pattern: sdk.String(name.Name())})) + entities, err := client.DynamicTables.Show(ctx, sdk.NewShowDynamicTableRequest().WithLike(&sdk.Like{Pattern: sdk.String(id.Name())})) require.NoError(t, err) require.Equal(t, 1, len(entities)) entity := entities[0] - require.Equal(t, name.Name(), entity.Name) + require.Equal(t, id.Name(), entity.Name) require.Equal(t, testWarehouse(t).ID().Name(), entity.Warehouse) require.Equal(t, *targetLag.MaximumDuration, entity.TargetLag) require.Equal(t, sdk.DynamicTableRefreshModeFull, entity.RefreshMode) @@ -200,7 +200,7 @@ func TestInt_DynamicTablesShowByID(t *testing.T) { client := testClient(t) ctx := context.Background() - warehouseTest, databaseTest, schemaTest := testWarehouse(t), testDb(t), testSchema(t) + warehouseTest := testWarehouse(t) cleanupDynamicTableHandle := func(t *testing.T, id sdk.SchemaObjectIdentifier) func() { t.Helper() @@ -231,9 +231,8 @@ func TestInt_DynamicTablesShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createDynamicTableHandle(t, id1) createDynamicTableHandle(t, id2) diff --git a/pkg/sdk/testint/event_tables_integration_test.go b/pkg/sdk/testint/event_tables_integration_test.go index cc5eef4cae..3db615c31c 100644 --- a/pkg/sdk/testint/event_tables_integration_test.go +++ b/pkg/sdk/testint/event_tables_integration_test.go @@ -15,7 +15,6 @@ func TestInt_EventTables(t *testing.T) { client := testClient(t) ctx := context.Background() - databaseTest, schemaTest := testDb(t), testSchema(t) tagTest, tagCleaup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleaup) @@ -38,7 +37,7 @@ func TestInt_EventTables(t *testing.T) { createEventTableHandle := func(t *testing.T) *sdk.EventTable { t.Helper() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.StringN(4)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.EventTables.Create(ctx, sdk.NewCreateEventTableRequest(id)) require.NoError(t, err) t.Cleanup(cleanupTableHandle(t, id)) @@ -49,8 +48,7 @@ func TestInt_EventTables(t *testing.T) { } t.Run("create event tables: all options", func(t *testing.T) { - name := random.StringN(4) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() request := sdk.NewCreateEventTableRequest(id). WithChangeTracking(sdk.Bool(true)). @@ -107,9 +105,8 @@ func TestInt_EventTables(t *testing.T) { t.Run("describe event table", func(t *testing.T) { dt := createEventTableHandle(t) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, dt.Name) - details, err := client.EventTables.Describe(ctx, id) + details, err := client.EventTables.Describe(ctx, dt.ID()) require.NoError(t, err) assert.Equal(t, "TIMESTAMP", details.Name) assert.NotEmpty(t, details.Kind) @@ -117,7 +114,7 @@ func TestInt_EventTables(t *testing.T) { t.Run("alter event table: set and unset comment", func(t *testing.T) { dt := createEventTableHandle(t) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, dt.Name) + id := dt.ID() comment := random.Comment() set := sdk.NewEventTableSetRequest().WithComment(&comment) @@ -139,7 +136,7 @@ func TestInt_EventTables(t *testing.T) { t.Run("alter event table: set and unset change tacking", func(t *testing.T) { dt := createEventTableHandle(t) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, dt.Name) + id := dt.ID() set := sdk.NewEventTableSetRequest().WithChangeTracking(sdk.Bool(true)) err := client.EventTables.Alter(ctx, sdk.NewAlterEventTableRequest(id).WithSet(set)) @@ -152,7 +149,7 @@ func TestInt_EventTables(t *testing.T) { t.Run("alter event table: set and unset tag", func(t *testing.T) { dt := createEventTableHandle(t) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, dt.Name) + id := dt.ID() set := []sdk.TagAssociation{ { @@ -169,13 +166,12 @@ func TestInt_EventTables(t *testing.T) { }) t.Run("alter event table: rename", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.EventTables.Create(ctx, sdk.NewCreateEventTableRequest(id)) require.NoError(t, err) - nid := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.String()) + nid := testClientHelper().Ids.RandomSchemaObjectIdentifier() err = client.EventTables.Alter(ctx, sdk.NewAlterEventTableRequest(id).WithRenameTo(&nid)) if err != nil { t.Cleanup(cleanupTableHandle(t, id)) @@ -193,7 +189,7 @@ func TestInt_EventTables(t *testing.T) { t.Run("alter event table: clustering action with drop", func(t *testing.T) { dt := createEventTableHandle(t) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, dt.Name) + id := dt.ID() action := sdk.NewEventTableClusteringActionRequest().WithDropClusteringKey(sdk.Bool(true)) err := client.EventTables.Alter(ctx, sdk.NewAlterEventTableRequest(id).WithClusteringAction(action)) @@ -202,7 +198,7 @@ func TestInt_EventTables(t *testing.T) { t.Run("alter event table: search optimization action", func(t *testing.T) { dt := createEventTableHandle(t) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, dt.Name) + id := dt.ID() action := sdk.NewEventTableSearchOptimizationActionRequest().WithAdd(sdk.NewSearchOptimizationRequest().WithOn([]string{"SUBSTRING(*)"})) err := client.EventTables.Alter(ctx, sdk.NewAlterEventTableRequest(id).WithSearchOptimizationAction(action)) @@ -280,8 +276,6 @@ func TestInt_EventTableShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupEventTableHandle := func(t *testing.T, id sdk.SchemaObjectIdentifier) func() { t.Helper() return func() { @@ -302,9 +296,8 @@ func TestInt_EventTableShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createEventTableHandle(t, id1) createEventTableHandle(t, id2) diff --git a/pkg/sdk/testint/external_functions_integration_test.go b/pkg/sdk/testint/external_functions_integration_test.go index dd9e537b8e..a36b76fb93 100644 --- a/pkg/sdk/testint/external_functions_integration_test.go +++ b/pkg/sdk/testint/external_functions_integration_test.go @@ -5,7 +5,6 @@ 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/stretchr/testify/require" ) @@ -30,7 +29,7 @@ func TestInt_ExternalFunctions(t *testing.T) { createExternalFunction := func(t *testing.T) *sdk.ExternalFunction { t.Helper() - id := sdk.NewSchemaObjectIdentifierWithArguments(databaseTest.Name, schemaTest.Name, random.StringN(4), defaultDataTypes) + id := testClientHelper().Ids.RandomSchemaObjectIdentifierWithArguments(defaultDataTypes) argument := sdk.NewExternalFunctionArgumentRequest("x", defaultDataTypes[0]) as := "https://xyz.execute-api.us-west-2.amazonaws.com/production/remote_echo" request := sdk.NewCreateExternalFunctionRequest(id, sdk.DataTypeVariant, sdk.Pointer(integration.ID()), as). @@ -79,7 +78,7 @@ func TestInt_ExternalFunctions(t *testing.T) { } t.Run("create external function", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifierWithArguments(databaseTest.Name, schemaTest.Name, random.StringN(4), defaultDataTypes) + id := testClientHelper().Ids.RandomSchemaObjectIdentifierWithArguments(defaultDataTypes) argument := sdk.NewExternalFunctionArgumentRequest("x", sdk.DataTypeVARCHAR) headers := []sdk.ExternalFunctionHeaderRequest{ { @@ -113,7 +112,7 @@ func TestInt_ExternalFunctions(t *testing.T) { }) t.Run("create external function without arguments", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifierWithArguments(databaseTest.Name, schemaTest.Name, random.StringN(4), nil) + id := testClientHelper().Ids.RandomSchemaObjectIdentifierWithArguments(nil) as := "https://xyz.execute-api.us-west-2.amazonaws.com/production/remote_echo" request := sdk.NewCreateExternalFunctionRequest(id, sdk.DataTypeVariant, sdk.Pointer(integration.ID()), as) err := client.ExternalFunctions.Create(ctx, request) @@ -125,6 +124,7 @@ func TestInt_ExternalFunctions(t *testing.T) { t.Run("alter external function: set api integration", func(t *testing.T) { e := createExternalFunction(t) + e.ID() id := sdk.NewSchemaObjectIdentifierWithArguments(databaseTest.Name, schemaTest.Name, e.Name, defaultDataTypes) set := sdk.NewExternalFunctionSetRequest(). WithApiIntegration(sdk.Pointer(integration.ID())) @@ -225,7 +225,7 @@ func TestInt_ExternalFunctions(t *testing.T) { e1 := createExternalFunction(t) - es, err := client.ExternalFunctions.Show(ctx, sdk.NewShowExternalFunctionRequest().WithIn(&sdk.In{Schema: sdk.NewDatabaseObjectIdentifier(databaseTest.Name, schemaTest.Name)})) + es, err := client.ExternalFunctions.Show(ctx, sdk.NewShowExternalFunctionRequest().WithIn(&sdk.In{Schema: e1.ID().SchemaId()})) require.NoError(t, err) require.Contains(t, es, *e1) @@ -242,7 +242,7 @@ func TestInt_ExternalFunctions(t *testing.T) { }) t.Run("show external function: no matches", func(t *testing.T) { - es, err := client.ExternalFunctions.Show(ctx, sdk.NewShowExternalFunctionRequest().WithLike(&sdk.Like{Pattern: sdk.String(random.String())})) + es, err := client.ExternalFunctions.Show(ctx, sdk.NewShowExternalFunctionRequest().WithLike(&sdk.Like{Pattern: sdk.String("non-existing-id-pattern")})) require.NoError(t, err) require.Equal(t, 0, len(es)) }) @@ -261,7 +261,7 @@ func TestInt_ExternalFunctions(t *testing.T) { t.Run("describe external function", func(t *testing.T) { e := createExternalFunction(t) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, e.Name) + id := e.ID() request := sdk.NewDescribeExternalFunctionRequest(id, []sdk.DataType{sdk.DataTypeVARCHAR}) details, err := client.ExternalFunctions.Describe(ctx, request) diff --git a/pkg/sdk/testint/external_tables_integration_test.go b/pkg/sdk/testint/external_tables_integration_test.go index 50bff014ea..62e832eba8 100644 --- a/pkg/sdk/testint/external_tables_integration_test.go +++ b/pkg/sdk/testint/external_tables_integration_test.go @@ -5,7 +5,6 @@ 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/stretchr/testify/assert" @@ -61,8 +60,8 @@ func TestInt_ExternalTables(t *testing.T) { } t.Run("Create: minimal", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.Create(ctx, minimalCreateExternalTableReq(name)) require.NoError(t, err) @@ -72,8 +71,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Create: with raw file format", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.Create(ctx, sdk.NewCreateExternalTableRequest(sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name), stageLocation).WithRawFileFormat("TYPE = JSON")) require.NoError(t, err) @@ -83,8 +82,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Create: complete", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.Create( ctx, sdk.NewCreateExternalTableRequest( @@ -116,8 +115,7 @@ func TestInt_ExternalTables(t *testing.T) { err := client.Sessions.UseWarehouse(ctx, testWarehouse(t).ID()) require.NoError(t, err) - name := random.AlphanumericN(32) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() query := fmt.Sprintf(`SELECT ARRAY_AGG(OBJECT_CONSTRUCT(*)) WITHIN GROUP (ORDER BY order_id) FROM TABLE (INFER_SCHEMA(location => '%s', FILE_FORMAT=>'%s', ignore_case => true))`, stageLocation, fileFormat.ID().FullyQualifiedName()) err = client.ExternalTables.CreateUsingTemplate( ctx, @@ -135,8 +133,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Create with manual partitioning: complete", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.CreateWithManualPartitioning(ctx, createExternalTableWithManualPartitioningReq(name)) require.NoError(t, err) @@ -146,8 +144,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Create delta lake: complete", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.CreateDeltaLake( ctx, sdk.NewCreateDeltaLakeExternalTableRequest( @@ -172,8 +170,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Alter: refresh", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.Create(ctx, minimalCreateExternalTableReq(name)) require.NoError(t, err) @@ -187,8 +185,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Alter: add files", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.Create( ctx, minimalCreateExternalTableReq(name). @@ -206,8 +204,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Alter: remove files", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.Create( ctx, minimalCreateExternalTableReq(name). @@ -233,8 +231,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Alter: set auto refresh", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.Create(ctx, minimalCreateExternalTableReq(name)) require.NoError(t, err) @@ -293,8 +291,8 @@ func TestInt_ExternalTables(t *testing.T) { // }) t.Run("Alter: add partitions", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.CreateWithManualPartitioning(ctx, createExternalTableWithManualPartitioningReq(name)) require.NoError(t, err) @@ -309,8 +307,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Alter: drop partitions", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.CreateWithManualPartitioning(ctx, createExternalTableWithManualPartitioningReq(name)) require.NoError(t, err) @@ -334,8 +332,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Drop", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.Create(ctx, minimalCreateExternalTableReq(name)) require.NoError(t, err) @@ -352,8 +350,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Show", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.Create(ctx, minimalCreateExternalTableReq(name)) require.NoError(t, err) @@ -372,8 +370,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Describe: columns", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() req := minimalCreateExternalTableReq(name) err := client.ExternalTables.Create(ctx, req) require.NoError(t, err) @@ -398,8 +396,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Describe: stage", func(t *testing.T) { - name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + externalTableID := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := externalTableID.Name() err := client.ExternalTables.Create(ctx, minimalCreateExternalTableReq(name)) require.NoError(t, err) @@ -420,8 +418,7 @@ func TestInt_ExternalTablesShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - stage := sdk.NewSchemaObjectIdentifier(TestDatabaseName, TestSchemaName, random.AlphaN(6)) + stage := testClientHelper().Ids.RandomSchemaObjectIdentifier() _, stageCleanup := testClientHelper().Stage.CreateStageWithURL(t, stage) t.Cleanup(stageCleanup) @@ -450,9 +447,8 @@ func TestInt_ExternalTablesShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createExternalTableHandle(t, id1) createExternalTableHandle(t, id2) diff --git a/pkg/sdk/testint/file_format_integration_test.go b/pkg/sdk/testint/file_format_integration_test.go index 0cb08ec7c6..8044c4cabf 100644 --- a/pkg/sdk/testint/file_format_integration_test.go +++ b/pkg/sdk/testint/file_format_integration_test.go @@ -5,7 +5,6 @@ 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/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -16,7 +15,7 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) { ctx := testContext(t) t.Run("CSV", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.FileFormats.Create(ctx, id, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeCSV, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ @@ -106,7 +105,7 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) { // Check that field_optionally_enclosed_by can take the value NONE t.Run("CSV", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.FileFormats.Create(ctx, id, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeCSV, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ @@ -125,7 +124,7 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) { assert.Equal(t, "NONE", *result.Options.CSVFieldOptionallyEnclosedBy) }) t.Run("JSON", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.FileFormats.Create(ctx, id, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeJSON, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ @@ -196,7 +195,7 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) { assert.Equal(t, true, *describeResult.Options.JSONSkipByteOrderMark) }) t.Run("AVRO", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.FileFormats.Create(ctx, id, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeAvro, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ @@ -237,7 +236,7 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) { assert.Equal(t, []sdk.NullString{{S: "a"}, {S: "b"}}, *describeResult.Options.AvroNullIf) }) t.Run("ORC", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.FileFormats.Create(ctx, id, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeORC, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ @@ -275,7 +274,7 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) { assert.Equal(t, []sdk.NullString{{S: "a"}, {S: "b"}}, *describeResult.Options.ORCNullIf) }) t.Run("PARQUET", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.FileFormats.Create(ctx, id, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeParquet, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ @@ -319,7 +318,7 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) { assert.Equal(t, []sdk.NullString{{S: "a"}, {S: "b"}}, *describeResult.Options.ParquetNullIf) }) t.Run("XML", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.FileFormats.Create(ctx, id, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeXML, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ @@ -378,7 +377,7 @@ func TestInt_FileFormatsAlter(t *testing.T) { fileFormat, fileFormatCleanup := testClientHelper().FileFormat.CreateFileFormat(t) t.Cleanup(fileFormatCleanup) oldId := fileFormat.ID() - newId := sdk.NewSchemaObjectIdentifier(oldId.DatabaseName(), oldId.SchemaName(), random.String()) + newId := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.FileFormats.Alter(ctx, oldId, &sdk.AlterFileFormatOptions{ Rename: &sdk.AlterFileFormatRenameOptions{ @@ -531,8 +530,6 @@ func TestInt_FileFormatsShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupFileFormatHandle := func(t *testing.T, id sdk.SchemaObjectIdentifier) func() { t.Helper() return func() { @@ -556,9 +553,8 @@ func TestInt_FileFormatsShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createFileFormatHandle(t, id1) createFileFormatHandle(t, id2) diff --git a/pkg/sdk/testint/functions_integration_test.go b/pkg/sdk/testint/functions_integration_test.go index 595349d3ca..205689be40 100644 --- a/pkg/sdk/testint/functions_integration_test.go +++ b/pkg/sdk/testint/functions_integration_test.go @@ -7,7 +7,6 @@ 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/stretchr/testify/assert" @@ -24,8 +23,6 @@ func TestInt_CreateFunctions(t *testing.T) { client := testClient(t) ctx := context.Background() - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupFunctionHandle := func(id sdk.SchemaObjectIdentifier, dts []sdk.DataType) func() { return func() { err := client.Functions.Drop(ctx, sdk.NewDropFunctionRequest(id, dts)) @@ -38,7 +35,7 @@ func TestInt_CreateFunctions(t *testing.T) { t.Run("create function for Java", func(t *testing.T) { name := "echo_varchar" - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.NewSchemaObjectIdentifier(name) definition := ` class TestFunc { @@ -68,7 +65,7 @@ func TestInt_CreateFunctions(t *testing.T) { t.Run("create function for Javascript", func(t *testing.T) { name := "js_factorial" - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.NewSchemaObjectIdentifier(name) definition := ` if (D <= 0) { @@ -99,8 +96,7 @@ func TestInt_CreateFunctions(t *testing.T) { }) t.Run("create function for Python", func(t *testing.T) { - name := random.StringN(8) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() definition := ` def dump(i): @@ -124,7 +120,7 @@ def dump(i): t.Run("create function for Scala", func(t *testing.T) { name := "echo_varchar" - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.NewSchemaObjectIdentifier(name) definition := ` class Echo { @@ -150,8 +146,7 @@ def dump(i): }) t.Run("create function for SQL", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() definition := "3.141592654::FLOAT" @@ -173,8 +168,7 @@ def dump(i): }) t.Run("create function for SQL with no arguments", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() definition := "3.141592654::FLOAT" @@ -198,7 +192,6 @@ func TestInt_OtherFunctions(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) tagTest, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) @@ -243,7 +236,7 @@ func TestInt_OtherFunctions(t *testing.T) { createFunctionForSQLHandle := func(t *testing.T, cleanup bool, withArguments bool) *sdk.Function { t.Helper() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.StringN(4)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() definition := "3.141592654::FLOAT" @@ -276,8 +269,8 @@ func TestInt_OtherFunctions(t *testing.T) { t.Run("alter function: rename", func(t *testing.T) { f := createFunctionForSQLHandle(t, false, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) - nid := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.StringN(3)) + id := f.ID() + nid := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithRenameTo(&nid)) if err != nil { t.Cleanup(cleanupFunctionHandle(id, []sdk.DataType{sdk.DataTypeFloat})) @@ -297,7 +290,7 @@ func TestInt_OtherFunctions(t *testing.T) { t.Run("alter function: set log level", func(t *testing.T) { f := createFunctionForSQLHandle(t, true, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithSetLogLevel(sdk.String("DEBUG"))) require.NoError(t, err) assertFunction(t, id, false, true) @@ -306,7 +299,7 @@ func TestInt_OtherFunctions(t *testing.T) { t.Run("alter function: unset log level", func(t *testing.T) { f := createFunctionForSQLHandle(t, true, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithUnsetLogLevel(sdk.Bool(true))) require.NoError(t, err) assertFunction(t, id, false, true) @@ -315,7 +308,7 @@ func TestInt_OtherFunctions(t *testing.T) { t.Run("alter function: set trace level", func(t *testing.T) { f := createFunctionForSQLHandle(t, true, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithSetTraceLevel(sdk.String("ALWAYS"))) require.NoError(t, err) assertFunction(t, id, false, true) @@ -324,7 +317,7 @@ func TestInt_OtherFunctions(t *testing.T) { t.Run("alter function: unset trace level", func(t *testing.T) { f := createFunctionForSQLHandle(t, true, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithUnsetTraceLevel(sdk.Bool(true))) require.NoError(t, err) assertFunction(t, id, false, true) @@ -333,7 +326,7 @@ func TestInt_OtherFunctions(t *testing.T) { t.Run("alter function: set comment", func(t *testing.T) { f := createFunctionForSQLHandle(t, true, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithSetComment(sdk.String("test comment"))) require.NoError(t, err) assertFunction(t, id, false, true) @@ -342,7 +335,7 @@ func TestInt_OtherFunctions(t *testing.T) { t.Run("alter function: unset comment", func(t *testing.T) { f := createFunctionForSQLHandle(t, true, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithUnsetComment(sdk.Bool(true))) require.NoError(t, err) assertFunction(t, id, false, true) @@ -351,7 +344,7 @@ func TestInt_OtherFunctions(t *testing.T) { t.Run("alter function: set secure", func(t *testing.T) { f := createFunctionForSQLHandle(t, true, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithSetSecure(sdk.Bool(true))) require.NoError(t, err) assertFunction(t, id, true, true) @@ -359,7 +352,7 @@ func TestInt_OtherFunctions(t *testing.T) { t.Run("alter function: set secure with no arguments", func(t *testing.T) { f := createFunctionForSQLHandle(t, true, false) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Functions.Alter(ctx, sdk.NewAlterFunctionRequest(id, nil).WithSetSecure(sdk.Bool(true))) require.NoError(t, err) assertFunction(t, id, true, false) @@ -368,7 +361,7 @@ func TestInt_OtherFunctions(t *testing.T) { t.Run("alter function: unset secure", func(t *testing.T) { f := createFunctionForSQLHandle(t, true, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithUnsetSecure(sdk.Bool(true))) require.NoError(t, err) assertFunction(t, id, false, true) @@ -377,7 +370,7 @@ func TestInt_OtherFunctions(t *testing.T) { t.Run("alter function: set and unset tags", func(t *testing.T) { f := createFunctionForSQLHandle(t, true, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() setTags := []sdk.TagAssociation{ { Name: tagTest.ID(), @@ -420,14 +413,14 @@ func TestInt_OtherFunctions(t *testing.T) { }) t.Run("show function for SQL: no matches", func(t *testing.T) { - functions, err := client.Functions.Show(ctx, sdk.NewShowFunctionRequest().WithLike(&sdk.Like{Pattern: sdk.String(random.String())})) + functions, err := client.Functions.Show(ctx, sdk.NewShowFunctionRequest().WithLike(&sdk.Like{Pattern: sdk.String("non-existing-id-pattern")})) require.NoError(t, err) require.Equal(t, 0, len(functions)) }) t.Run("describe function for SQL", func(t *testing.T) { f := createFunctionForSQLHandle(t, true, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() request := sdk.NewDescribeFunctionRequest(id, []sdk.DataType{sdk.DataTypeFloat}) details, err := client.Functions.Describe(ctx, request) @@ -444,7 +437,7 @@ func TestInt_OtherFunctions(t *testing.T) { t.Run("describe function for SQL: no arguments", func(t *testing.T) { f := createFunctionForSQLHandle(t, true, false) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() request := sdk.NewDescribeFunctionRequest(id, nil) details, err := client.Functions.Describe(ctx, request) @@ -464,8 +457,6 @@ func TestInt_FunctionsShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupFunctionHandle := func(id sdk.SchemaObjectIdentifier, dts []sdk.DataType) func() { return func() { err := client.Functions.Drop(ctx, sdk.NewDropFunctionRequest(id, dts)) @@ -495,9 +486,8 @@ func TestInt_FunctionsShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createFunctionForSQLHandle(t, id1) createFunctionForSQLHandle(t, id2) diff --git a/pkg/sdk/testint/grants_integration_test.go b/pkg/sdk/testint/grants_integration_test.go index 118a265514..cdf84c8402 100644 --- a/pkg/sdk/testint/grants_integration_test.go +++ b/pkg/sdk/testint/grants_integration_test.go @@ -1785,12 +1785,9 @@ func TestInt_ShowGrants(t *testing.T) { }) t.Run("handles unquoted granted object names", func(t *testing.T) { - columns := []sdk.TableColumnRequest{ - *sdk.NewTableColumnRequest("id", sdk.DataTypeNumber), - } // This name is returned as unquoted from Snowflake name := "G6TM2" - table, tableCleanup := testClientHelper().Table.CreateTableWithColumns(t, testClientHelper().Ids.SchemaId(), name, columns) + table, tableCleanup := testClientHelper().Table.CreateTableWithName(t, name) t.Cleanup(tableCleanup) role, roleCleanup := testClientHelper().Role.CreateRole(t) diff --git a/pkg/sdk/testint/managed_accounts_gen_integration_test.go b/pkg/sdk/testint/managed_accounts_gen_integration_test.go index 176524b58f..a6c6e2f5af 100644 --- a/pkg/sdk/testint/managed_accounts_gen_integration_test.go +++ b/pkg/sdk/testint/managed_accounts_gen_integration_test.go @@ -43,10 +43,8 @@ func TestInt_ManagedAccounts(t *testing.T) { // 090348 (42602): Account name or alias is invalid: (...) can only contain capital letters, numbers, and underscores id := testClientHelper().Ids.RandomAccountObjectIdentifier() - // 090088 (22000): ADMIN_NAME can only contain letters, numbers and underscores. - // 090089 (22000): ADMIN_NAME must start with a letter. - adminName := random.AlphaN(1) + random.AlphanumericN(12) - adminPassword := random.String() + adminName := random.AdminName() + adminPassword := random.Password() params := sdk.NewCreateManagedAccountParamsRequest(adminName, adminPassword) return sdk.NewCreateManagedAccountRequest(id, *params) diff --git a/pkg/sdk/testint/masking_policy_integration_test.go b/pkg/sdk/testint/masking_policy_integration_test.go index 480ab1b4de..82d608964c 100644 --- a/pkg/sdk/testint/masking_policy_integration_test.go +++ b/pkg/sdk/testint/masking_policy_integration_test.go @@ -87,8 +87,8 @@ func TestInt_MaskingPolicyCreate(t *testing.T) { ctx := testContext(t) t.Run("test complete case", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := id.Name() signature := []sdk.TableColumnSignature{ { Name: "col1", @@ -132,8 +132,8 @@ func TestInt_MaskingPolicyCreate(t *testing.T) { }) t.Run("test if_not_exists", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := id.Name() signature := []sdk.TableColumnSignature{ { Name: "col1", @@ -176,8 +176,8 @@ func TestInt_MaskingPolicyCreate(t *testing.T) { }) t.Run("test no options", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := id.Name() signature := []sdk.TableColumnSignature{ { Name: "col1", @@ -210,8 +210,8 @@ func TestInt_MaskingPolicyCreate(t *testing.T) { }) t.Run("test multiline expression", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() + name := id.Name() signature := []sdk.TableColumnSignature{ { Name: "val", @@ -312,8 +312,7 @@ func TestInt_MaskingPolicyAlter(t *testing.T) { maskingPolicy, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicy(t) oldID := maskingPolicy.ID() t.Cleanup(maskingPolicyCleanup) - newName := random.String() - newID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, newName) + newID := testClientHelper().Ids.RandomSchemaObjectIdentifier() alterOptions := &sdk.AlterMaskingPolicyOptions{ NewName: &newID, } @@ -321,8 +320,8 @@ func TestInt_MaskingPolicyAlter(t *testing.T) { require.NoError(t, err) maskingPolicyDetails, err := client.MaskingPolicies.Describe(ctx, newID) require.NoError(t, err) - assert.Equal(t, newName, maskingPolicyDetails.Name) - // rename back to original name so it can be cleaned up + assert.Equal(t, newID.Name(), maskingPolicyDetails.Name) + // rename back to original name, so it can be cleaned up alterOptions = &sdk.AlterMaskingPolicyOptions{ NewName: &oldID, } @@ -390,8 +389,6 @@ func TestInt_MaskingPoliciesShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupMaskingPolicyHandle := func(t *testing.T, id sdk.SchemaObjectIdentifier) func() { t.Helper() return func() { @@ -408,7 +405,7 @@ func TestInt_MaskingPoliciesShowByID(t *testing.T) { signature := []sdk.TableColumnSignature{ { - Name: random.String(), + Name: testClientHelper().Ids.Alpha(), Type: sdk.DataTypeVARCHAR, }, } @@ -436,9 +433,8 @@ func TestInt_MaskingPoliciesShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createMaskingPolicyHandle(t, id1) createMaskingPolicyHandle(t, id2) @@ -453,8 +449,7 @@ func TestInt_MaskingPoliciesShowByID(t *testing.T) { }) t.Run("show by id: check fields", func(t *testing.T) { - name := random.AlphaN(4) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() createMaskingPolicyHandle(t, id) diff --git a/pkg/sdk/testint/materialized_views_gen_integration_test.go b/pkg/sdk/testint/materialized_views_gen_integration_test.go index 3bda131a53..4e1e30fd3a 100644 --- a/pkg/sdk/testint/materialized_views_gen_integration_test.go +++ b/pkg/sdk/testint/materialized_views_gen_integration_test.go @@ -5,7 +5,6 @@ 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/stretchr/testify/assert" @@ -79,9 +78,7 @@ func TestInt_MaterializedViews(t *testing.T) { createMaterializedViewBasicRequest := func(t *testing.T) *sdk.CreateMaterializedViewRequest { t.Helper() - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) - + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() return sdk.NewCreateMaterializedViewRequest(id, sql) } @@ -176,8 +173,7 @@ func TestInt_MaterializedViews(t *testing.T) { err := client.MaterializedViews.Create(ctx, createRequest) require.NoError(t, err) - newName := random.String() - newId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, newName) + newId := testClientHelper().Ids.RandomSchemaObjectIdentifier() alterRequest := sdk.NewAlterMaterializedViewRequest(id).WithRenameTo(&newId) err = client.MaterializedViews.Alter(ctx, alterRequest) @@ -415,7 +411,6 @@ func TestInt_MaterializedViewsShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) table, tableCleanup := testClientHelper().Table.CreateTable(t) t.Cleanup(tableCleanup) @@ -443,9 +438,8 @@ func TestInt_MaterializedViewsShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createMaterializedViewHandle(t, id1) createMaterializedViewHandle(t, id2) diff --git a/pkg/sdk/testint/network_policies_gen_integration_test.go b/pkg/sdk/testint/network_policies_gen_integration_test.go index 5faf288b82..aa2969afd6 100644 --- a/pkg/sdk/testint/network_policies_gen_integration_test.go +++ b/pkg/sdk/testint/network_policies_gen_integration_test.go @@ -4,7 +4,6 @@ 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/stretchr/testify/assert" @@ -19,11 +18,10 @@ func TestInt_NetworkPolicies(t *testing.T) { blockedIP := sdk.NewIPRequest("125.0.0.1") blockedIP2 := sdk.NewIPRequest("124.0.0.1") - databaseTest, schemaTest := testDb(t), testSchema(t) createNetworkRuleHandle := func(t *testing.T, client *sdk.Client) sdk.SchemaObjectIdentifier { t.Helper() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.AlphaN(4)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.NetworkRules.Create(ctx, sdk.NewCreateNetworkRuleRequest(id, sdk.NetworkRuleTypeIpv4, []sdk.NetworkRuleValue{}, sdk.NetworkRuleModeIngress)) require.NoError(t, err) t.Cleanup(func() { diff --git a/pkg/sdk/testint/network_rule_gen_integration_test.go b/pkg/sdk/testint/network_rule_gen_integration_test.go index 2be850150c..939208d142 100644 --- a/pkg/sdk/testint/network_rule_gen_integration_test.go +++ b/pkg/sdk/testint/network_rule_gen_integration_test.go @@ -4,7 +4,6 @@ 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/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -27,7 +26,7 @@ func TestInt_NetworkRules(t *testing.T) { } t.Run("Create", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(TestDatabaseName, TestSchemaName, random.AlphaN(20)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.NetworkRules.Create(ctx, sdk.NewCreateNetworkRuleRequest(id, sdk.NetworkRuleTypeIpv4, []sdk.NetworkRuleValue{}, sdk.NetworkRuleModeIngress)) require.NoError(t, err) @@ -41,7 +40,7 @@ func TestInt_NetworkRules(t *testing.T) { }) t.Run("Alter: set and unset", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(TestDatabaseName, TestSchemaName, random.AlphaN(20)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.NetworkRules.Create(ctx, sdk.NewCreateNetworkRuleRequest(id, sdk.NetworkRuleTypeIpv4, []sdk.NetworkRuleValue{}, sdk.NetworkRuleModeIngress)) require.NoError(t, err) @@ -69,7 +68,7 @@ func TestInt_NetworkRules(t *testing.T) { }) t.Run("Drop", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(TestDatabaseName, TestSchemaName, random.AlphaN(20)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.NetworkRules.Create(ctx, sdk.NewCreateNetworkRuleRequest(id, sdk.NetworkRuleTypeIpv4, []sdk.NetworkRuleValue{}, sdk.NetworkRuleModeIngress)) require.NoError(t, err) @@ -84,7 +83,7 @@ func TestInt_NetworkRules(t *testing.T) { }) t.Run("Show", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(TestDatabaseName, TestSchemaName, random.AlphaN(20)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.NetworkRules.Create(ctx, sdk.NewCreateNetworkRuleRequest(id, sdk.NetworkRuleTypeIpv4, []sdk.NetworkRuleValue{}, sdk.NetworkRuleModeIngress).WithComment(sdk.String("some comment"))) require.NoError(t, err) @@ -114,7 +113,7 @@ func TestInt_NetworkRules(t *testing.T) { }) t.Run("Describe", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(TestDatabaseName, TestSchemaName, random.AlphaN(20)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.NetworkRules.Create(ctx, sdk.NewCreateNetworkRuleRequest(id, sdk.NetworkRuleTypeIpv4, []sdk.NetworkRuleValue{}, sdk.NetworkRuleModeIngress).WithComment(sdk.String("some comment"))) require.NoError(t, err) @@ -141,8 +140,6 @@ func TestInt_NetworkRulesShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupNetworkRuleHandle := func(t *testing.T, id sdk.SchemaObjectIdentifier) func() { t.Helper() return func() { @@ -167,9 +164,8 @@ func TestInt_NetworkRulesShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createNetworkRuleHandle(t, id1) createNetworkRuleHandle(t, id2) diff --git a/pkg/sdk/testint/password_policy_integration_test.go b/pkg/sdk/testint/password_policy_integration_test.go index 893688d96d..b8cbdc56ea 100644 --- a/pkg/sdk/testint/password_policy_integration_test.go +++ b/pkg/sdk/testint/password_policy_integration_test.go @@ -4,7 +4,6 @@ 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/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -84,8 +83,7 @@ func TestInt_PasswordPolicyCreate(t *testing.T) { ctx := testContext(t) t.Run("test complete", func(t *testing.T) { - name := random.UUID() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.PasswordPolicies.Create(ctx, id, &sdk.CreatePasswordPolicyOptions{ OrReplace: sdk.Bool(true), PasswordMinLength: sdk.Int(10), @@ -104,7 +102,7 @@ func TestInt_PasswordPolicyCreate(t *testing.T) { require.NoError(t, err) passwordPolicyDetails, err := client.PasswordPolicies.Describe(ctx, id) require.NoError(t, err) - assert.Equal(t, name, passwordPolicyDetails.Name.Value) + assert.Equal(t, id.Name(), passwordPolicyDetails.Name.Value) assert.Equal(t, 10, *passwordPolicyDetails.PasswordMinLength.Value) assert.Equal(t, 20, *passwordPolicyDetails.PasswordMaxLength.Value) assert.Equal(t, 1, *passwordPolicyDetails.PasswordMinUpperCaseChars.Value) @@ -120,8 +118,7 @@ func TestInt_PasswordPolicyCreate(t *testing.T) { }) t.Run("test if_not_exists", func(t *testing.T) { - name := random.UUID() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.PasswordPolicies.Create(ctx, id, &sdk.CreatePasswordPolicyOptions{ OrReplace: sdk.Bool(false), IfNotExists: sdk.Bool(true), @@ -133,7 +130,7 @@ func TestInt_PasswordPolicyCreate(t *testing.T) { require.NoError(t, err) passwordPolicyDetails, err := client.PasswordPolicies.Describe(ctx, id) require.NoError(t, err) - assert.Equal(t, name, passwordPolicyDetails.Name.Value) + assert.Equal(t, id.Name(), passwordPolicyDetails.Name.Value) assert.Equal(t, "test comment", passwordPolicyDetails.Comment.Value) assert.Equal(t, 10, *passwordPolicyDetails.PasswordMinLength.Value) assert.Equal(t, 20, *passwordPolicyDetails.PasswordMaxLength.Value) @@ -141,13 +138,12 @@ func TestInt_PasswordPolicyCreate(t *testing.T) { }) t.Run("test no options", func(t *testing.T) { - name := random.UUID() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.PasswordPolicies.Create(ctx, id, nil) require.NoError(t, err) passwordPolicyDetails, err := client.PasswordPolicies.Describe(ctx, id) require.NoError(t, err) - assert.Equal(t, name, passwordPolicyDetails.Name.Value) + assert.Equal(t, id.Name(), passwordPolicyDetails.Name.Value) assert.Equal(t, "", passwordPolicyDetails.Comment.Value) assert.Equal(t, *passwordPolicyDetails.PasswordMinLength.Value, *passwordPolicyDetails.PasswordMinLength.DefaultValue) assert.Equal(t, *passwordPolicyDetails.PasswordMaxLength.Value, *passwordPolicyDetails.PasswordMaxLength.DefaultValue) @@ -210,8 +206,7 @@ func TestInt_PasswordPolicyAlter(t *testing.T) { passwordPolicy, passwordPolicyCleanup := testClientHelper().PasswordPolicy.CreatePasswordPolicy(t) oldID := passwordPolicy.ID() t.Cleanup(passwordPolicyCleanup) - newName := random.UUID() - newID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, newName) + newID := testClientHelper().Ids.RandomSchemaObjectIdentifier() alterOptions := &sdk.AlterPasswordPolicyOptions{ NewName: &newID, } @@ -219,8 +214,8 @@ func TestInt_PasswordPolicyAlter(t *testing.T) { require.NoError(t, err) passwordPolicyDetails, err := client.PasswordPolicies.Describe(ctx, newID) require.NoError(t, err) - // rename back to original name so it can be cleaned up - assert.Equal(t, newName, passwordPolicyDetails.Name.Value) + // rename back to original name, so it can be cleaned up + assert.Equal(t, newID.Name(), passwordPolicyDetails.Name.Value) alterOptions = &sdk.AlterPasswordPolicyOptions{ NewName: &oldID, } @@ -316,8 +311,6 @@ func TestInt_PasswordPoliciesShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupPasswordPolicyHandle := func(t *testing.T, id sdk.SchemaObjectIdentifier) func() { t.Helper() return func() { @@ -341,9 +334,8 @@ func TestInt_PasswordPoliciesShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createPasswordPolicyHandle(t, id1) createPasswordPolicyHandle(t, id2) @@ -358,8 +350,7 @@ func TestInt_PasswordPoliciesShowByID(t *testing.T) { }) t.Run("show by id: check fields", func(t *testing.T) { - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() createPasswordPolicyHandle(t, id1) diff --git a/pkg/sdk/testint/pipes_integration_test.go b/pkg/sdk/testint/pipes_integration_test.go index 622e95b0e1..9e30eb6e18 100644 --- a/pkg/sdk/testint/pipes_integration_test.go +++ b/pkg/sdk/testint/pipes_integration_test.go @@ -37,7 +37,7 @@ func TestInt_CreatePipeWithStrangeSchemaName(t *testing.T) { t.Run("if we have special characters in db or schema name, create pipe succeeds", func(t *testing.T) { err := itc.client.Pipes.Create( itc.ctx, - sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, random.AlphanumericN(20)), + testClientHelper().Ids.RandomSchemaObjectIdentifierInSchema(schema.ID()), createPipeCopyStatement(t, table, stage), &sdk.CreatePipeOptions{}, ) @@ -55,7 +55,7 @@ func TestInt_CreatePipeWithStrangeSchemaName(t *testing.T) { err := itc.client.Pipes.Create( itc.ctx, - sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, random.AlphanumericN(20)), + testClientHelper().Ids.RandomSchemaObjectIdentifierInSchema(schema.ID()), createCopyStatementWithoutQualifiersForStage(t, table, stage), &sdk.CreatePipeOptions{}, ) @@ -174,8 +174,7 @@ func TestInt_PipeCreate(t *testing.T) { // TODO: test error integration, aws sns topic and integration when we have them in project t.Run("test complete case", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() comment := random.Comment() err := itc.client.Pipes.Create(itc.ctx, id, copyStatement, &sdk.CreatePipeOptions{ @@ -189,12 +188,11 @@ func TestInt_PipeCreate(t *testing.T) { pipe, err := itc.client.Pipes.Describe(itc.ctx, id) require.NoError(t, err) - assertPipe(t, pipe, name, comment) + assertPipe(t, pipe, id.Name(), comment) }) t.Run("test if not exists and or replace are incompatible", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := itc.client.Pipes.Create(itc.ctx, id, copyStatement, &sdk.CreatePipeOptions{ OrReplace: sdk.Bool(true), @@ -204,8 +202,7 @@ func TestInt_PipeCreate(t *testing.T) { }) t.Run("test no options", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := itc.client.Pipes.Create(itc.ctx, id, copyStatement, nil) require.NoError(t, err) @@ -213,7 +210,7 @@ func TestInt_PipeCreate(t *testing.T) { pipe, err := itc.client.Pipes.Describe(itc.ctx, id) require.NoError(t, err) - assertPipe(t, pipe, name, "") + assertPipe(t, pipe, id.Name(), "") }) } @@ -346,7 +343,6 @@ func TestInt_PipesShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) table, tableCleanup := testClientHelper().Table.CreateTable(t) t.Cleanup(tableCleanup) stage, stageCleanup := testClientHelper().Stage.CreateStage(t) @@ -376,9 +372,8 @@ func TestInt_PipesShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createPipeHandle(t, id1) createPipeHandle(t, id2) diff --git a/pkg/sdk/testint/policy_references_integration_test.go b/pkg/sdk/testint/policy_references_integration_test.go index 247ca252a8..c1d0d8bc2e 100644 --- a/pkg/sdk/testint/policy_references_integration_test.go +++ b/pkg/sdk/testint/policy_references_integration_test.go @@ -3,7 +3,6 @@ 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/stretchr/testify/require" ) @@ -12,12 +11,12 @@ func TestInt_PolicyReferences(t *testing.T) { client := testClient(t) ctx := testContext(t) - passwordPolicyName := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) - err := client.PasswordPolicies.Create(ctx, passwordPolicyName, &sdk.CreatePasswordPolicyOptions{}) + passwordPolicyId := testClientHelper().Ids.RandomSchemaObjectIdentifier() + err := client.PasswordPolicies.Create(ctx, passwordPolicyId, &sdk.CreatePasswordPolicyOptions{}) require.NoError(t, err) t.Cleanup(func() { - err := client.PasswordPolicies.Drop(ctx, passwordPolicyName, &sdk.DropPasswordPolicyOptions{IfExists: sdk.Bool(true)}) + err := client.PasswordPolicies.Drop(ctx, passwordPolicyId, &sdk.DropPasswordPolicyOptions{IfExists: sdk.Bool(true)}) require.NoError(t, err) }) @@ -27,7 +26,7 @@ func TestInt_PolicyReferences(t *testing.T) { err = client.Users.Alter(ctx, user.ID(), &sdk.AlterUserOptions{ Set: &sdk.UserSet{ - PasswordPolicy: &passwordPolicyName, + PasswordPolicy: &passwordPolicyId, }, }) require.NoError(t, err) @@ -35,7 +34,7 @@ func TestInt_PolicyReferences(t *testing.T) { policyReferences, err := client.PolicyReferences.GetForEntity(ctx, sdk.NewGetForEntityPolicyReferenceRequest(user.ID(), sdk.PolicyEntityDomainUser)) require.NoError(t, err) require.Equal(t, 1, len(policyReferences)) - require.Equal(t, passwordPolicyName.Name(), policyReferences[0].PolicyName) + require.Equal(t, passwordPolicyId.Name(), policyReferences[0].PolicyName) require.Equal(t, "PASSWORD_POLICY", policyReferences[0].PolicyKind) }) diff --git a/pkg/sdk/testint/procedures_integration_test.go b/pkg/sdk/testint/procedures_integration_test.go index 8d9f361874..7cd641794d 100644 --- a/pkg/sdk/testint/procedures_integration_test.go +++ b/pkg/sdk/testint/procedures_integration_test.go @@ -5,7 +5,6 @@ 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/stretchr/testify/assert" @@ -19,8 +18,6 @@ func TestInt_CreateProcedures(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupProcedureHandle := func(id sdk.SchemaObjectIdentifier, ats []sdk.DataType) func() { return func() { err := client.Procedures.Drop(ctx, sdk.NewDropProcedureRequest(id, ats)) @@ -34,7 +31,7 @@ func TestInt_CreateProcedures(t *testing.T) { t.Run("create procedure for Java: returns result data type", func(t *testing.T) { // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-java#reading-a-dynamically-specified-file-with-inputstream name := "file_reader_java_proc_snowflakefile" - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.NewSchemaObjectIdentifier(name) definition := ` import java.io.InputStream; @@ -69,7 +66,7 @@ func TestInt_CreateProcedures(t *testing.T) { t.Run("create procedure for Java: returns table", func(t *testing.T) { // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-java#specifying-return-column-names-and-types name := "filter_by_role" - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.NewSchemaObjectIdentifier(name) definition := ` import com.snowflake.snowpark_java.*; @@ -104,7 +101,7 @@ func TestInt_CreateProcedures(t *testing.T) { t.Run("create procedure for Javascript", func(t *testing.T) { // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-javascript#basic-examples name := "stproc1" - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.NewSchemaObjectIdentifier(name) definition := ` var sql_command = "INSERT INTO stproc_test_table1 (num_col1) VALUES (" + FLOAT_PARAM1 + ")"; @@ -134,7 +131,7 @@ func TestInt_CreateProcedures(t *testing.T) { t.Run("create procedure for Javascript: no arguments", func(t *testing.T) { // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-javascript#basic-examples name := "sp_pi" - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.NewSchemaObjectIdentifier(name) definition := `return 3.1415926;` request := sdk.NewCreateForJavaScriptProcedureRequest(id, sdk.DataTypeFloat, definition).WithNotNull(sdk.Bool(true)).WithOrReplace(sdk.Bool(true)) @@ -150,7 +147,7 @@ func TestInt_CreateProcedures(t *testing.T) { t.Run("create procedure for Scala: returns result data type", func(t *testing.T) { // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-scala#reading-a-dynamically-specified-file-with-snowflakefile name := "file_reader_scala_proc_snowflakefile" - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.NewSchemaObjectIdentifier(name) definition := ` import java.io.InputStream @@ -183,7 +180,7 @@ func TestInt_CreateProcedures(t *testing.T) { t.Run("create procedure for Scala: returns table", func(t *testing.T) { // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-scala#specifying-return-column-names-and-types name := "filter_by_role" - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.NewSchemaObjectIdentifier(name) definition := ` import com.snowflake.snowpark.functions._ @@ -219,7 +216,7 @@ func TestInt_CreateProcedures(t *testing.T) { t.Run("create procedure for Python: returns result data type", func(t *testing.T) { // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-python#running-concurrent-tasks-with-worker-processes name := "joblib_multiprocessing_proc" - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.NewSchemaObjectIdentifier(name) definition := ` import joblib @@ -251,7 +248,7 @@ def joblib_multiprocessing(session, i): t.Run("create procedure for Python: returns table", func(t *testing.T) { // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-python#specifying-return-column-names-and-types name := "filterByRole" - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.NewSchemaObjectIdentifier(name) definition := ` from snowflake.snowpark.functions import col @@ -282,7 +279,7 @@ def filter_by_role(session, table_name, role): t.Run("create procedure for SQL: returns result data type", func(t *testing.T) { // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-snowflake-scripting name := "output_message" - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.NewSchemaObjectIdentifier(name) definition := ` BEGIN @@ -313,7 +310,7 @@ def filter_by_role(session, table_name, role): t.Run("create procedure for SQL: returns table", func(t *testing.T) { name := "find_invoice_by_id" - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.NewSchemaObjectIdentifier(name) definition := ` DECLARE @@ -345,7 +342,6 @@ func TestInt_OtherProcedureFunctions(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) tagTest, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) @@ -387,7 +383,7 @@ func TestInt_OtherProcedureFunctions(t *testing.T) { BEGIN RETURN message; END;` - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() dt := sdk.NewProcedureReturnsResultDataTypeRequest(sdk.DataTypeVARCHAR) returns := sdk.NewProcedureSQLReturnsRequest().WithResultDataType(dt).WithNotNull(sdk.Bool(true)) argument := sdk.NewProcedureArgumentRequest("message", sdk.DataTypeVARCHAR) @@ -413,8 +409,8 @@ func TestInt_OtherProcedureFunctions(t *testing.T) { t.Run("alter procedure: rename", func(t *testing.T) { f := createProcedureForSQLHandle(t, false) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) - nid := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.String()) + id := f.ID() + nid := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.Procedures.Alter(ctx, defaultAlterRequest(id).WithRenameTo(&nid)) if err != nil { t.Cleanup(cleanupProcedureHandle(id, []sdk.DataType{sdk.DataTypeVARCHAR})) @@ -434,7 +430,7 @@ func TestInt_OtherProcedureFunctions(t *testing.T) { t.Run("alter procedure: set log level", func(t *testing.T) { f := createProcedureForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Procedures.Alter(ctx, defaultAlterRequest(id).WithSetLogLevel(sdk.String("DEBUG"))) require.NoError(t, err) assertProcedure(t, id, true) @@ -443,7 +439,7 @@ func TestInt_OtherProcedureFunctions(t *testing.T) { t.Run("alter procedure: set trace level", func(t *testing.T) { f := createProcedureForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Procedures.Alter(ctx, defaultAlterRequest(id).WithSetTraceLevel(sdk.String("ALWAYS"))) require.NoError(t, err) assertProcedure(t, id, true) @@ -452,7 +448,7 @@ func TestInt_OtherProcedureFunctions(t *testing.T) { t.Run("alter procedure: set comment", func(t *testing.T) { f := createProcedureForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Procedures.Alter(ctx, defaultAlterRequest(id).WithSetComment(sdk.String("comment"))) require.NoError(t, err) assertProcedure(t, id, true) @@ -461,7 +457,7 @@ func TestInt_OtherProcedureFunctions(t *testing.T) { t.Run("alter procedure: unset comment", func(t *testing.T) { f := createProcedureForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Procedures.Alter(ctx, defaultAlterRequest(id).WithUnsetComment(sdk.Bool(true))) require.NoError(t, err) assertProcedure(t, id, true) @@ -470,7 +466,7 @@ func TestInt_OtherProcedureFunctions(t *testing.T) { t.Run("alter procedure: set execute as", func(t *testing.T) { f := createProcedureForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() err := client.Procedures.Alter(ctx, defaultAlterRequest(id).WithExecuteAs(sdk.ExecuteAsPointer(sdk.ExecuteAsOwner))) require.NoError(t, err) assertProcedure(t, id, true) @@ -479,7 +475,7 @@ func TestInt_OtherProcedureFunctions(t *testing.T) { t.Run("alter procedure: set and unset tags", func(t *testing.T) { f := createProcedureForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() setTags := []sdk.TagAssociation{ { Name: tagTest.ID(), @@ -523,14 +519,14 @@ func TestInt_OtherProcedureFunctions(t *testing.T) { }) t.Run("show procedure for SQL: no matches", func(t *testing.T) { - procedures, err := client.Procedures.Show(ctx, sdk.NewShowProcedureRequest().WithLike(&sdk.Like{Pattern: sdk.String(random.String())})) + procedures, err := client.Procedures.Show(ctx, sdk.NewShowProcedureRequest().WithLike(&sdk.Like{Pattern: sdk.String("non-existing-id-pattern")})) require.NoError(t, err) require.Equal(t, 0, len(procedures)) }) t.Run("describe function for SQL", func(t *testing.T) { f := createProcedureForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + id := f.ID() request := sdk.NewDescribeProcedureRequest(id, []sdk.DataType{sdk.DataTypeString}) details, err := client.Procedures.Describe(ctx, request) @@ -550,7 +546,7 @@ func TestInt_OtherProcedureFunctions(t *testing.T) { BEGIN RETURN message; END;` - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() dt := sdk.NewProcedureReturnsResultDataTypeRequest(sdk.DataTypeVARCHAR) returns := sdk.NewProcedureSQLReturnsRequest().WithResultDataType(dt).WithNotNull(sdk.Bool(true)) argument := sdk.NewProcedureArgumentRequest("message", sdk.DataTypeVARCHAR) @@ -605,7 +601,7 @@ func TestInt_CallProcedure(t *testing.T) { BEGIN RETURN message; END;` - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.StringN(4)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() dt := sdk.NewProcedureReturnsResultDataTypeRequest(sdk.DataTypeVARCHAR) returns := sdk.NewProcedureSQLReturnsRequest().WithResultDataType(dt).WithNotNull(sdk.Bool(true)) argument := sdk.NewProcedureArgumentRequest("message", sdk.DataTypeVARCHAR) @@ -984,7 +980,6 @@ func TestInt_ProceduresShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) cleanupProcedureHandle := func(id sdk.SchemaObjectIdentifier, dts []sdk.DataType) func() { return func() { err := client.Procedures.Drop(ctx, sdk.NewDropProcedureRequest(id, dts)) @@ -1017,9 +1012,8 @@ func TestInt_ProceduresShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createProcedureForSQLHandle(t, id1) createProcedureForSQLHandle(t, id2) diff --git a/pkg/sdk/testint/replication_functions_integration_test.go b/pkg/sdk/testint/replication_functions_integration_test.go index 6f1c3cba80..d9a2a05d05 100644 --- a/pkg/sdk/testint/replication_functions_integration_test.go +++ b/pkg/sdk/testint/replication_functions_integration_test.go @@ -3,7 +3,6 @@ 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/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -26,11 +25,9 @@ func TestInt_ShowReplicationDatabases(t *testing.T) { accountId := testClientHelper().Ids.AccountIdentifierWithLocator() secondaryAccountId := secondaryTestClientHelper().Ids.AccountIdentifierWithLocator() - db1Name := random.AlphaN(10) - db2Name := random.AlphaN(10) - db, dbCleanup := testClientHelper().Database.CreateDatabaseWithName(t, db1Name) + db, dbCleanup := testClientHelper().Database.CreateDatabase(t) t.Cleanup(dbCleanup) - db2, dbCleanup2 := testClientHelper().Database.CreateDatabaseWithName(t, db2Name) + db2, dbCleanup2 := testClientHelper().Database.CreateDatabase(t) t.Cleanup(dbCleanup2) err := client.Databases.AlterReplication(ctx, db.ID(), &sdk.AlterDatabaseReplicationOptions{EnableReplication: &sdk.EnableReplication{ToAccounts: []sdk.AccountIdentifier{secondaryAccountId}}}) 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 a0874c75cb..f08e3aedee 100644 --- a/pkg/sdk/testint/row_access_policies_gen_integration_test.go +++ b/pkg/sdk/testint/row_access_policies_gen_integration_test.go @@ -49,8 +49,7 @@ func TestInt_RowAccessPolicies(t *testing.T) { createRowAccessPolicyRequest := func(t *testing.T, args []sdk.CreateRowAccessPolicyArgsRequest, body string) *sdk.CreateRowAccessPolicyRequest { t.Helper() - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() return sdk.NewCreateRowAccessPolicyRequest(id, args, body) } @@ -131,8 +130,7 @@ func TestInt_RowAccessPolicies(t *testing.T) { err := client.RowAccessPolicies.Create(ctx, createRequest) require.NoError(t, err) - newName := random.String() - newId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, newName) + newId := testClientHelper().Ids.RandomSchemaObjectIdentifier() alterRequest := sdk.NewAlterRowAccessPolicyRequest(id).WithRenameTo(&newId) err = client.RowAccessPolicies.Alter(ctx, alterRequest) @@ -318,7 +316,6 @@ func TestInt_RowAccessPoliciesShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) cleanupRowAccessPolicyHandle := func(id sdk.SchemaObjectIdentifier) func() { return func() { err := client.RowAccessPolicies.Drop(ctx, sdk.NewDropRowAccessPolicyRequest(id)) @@ -342,9 +339,8 @@ func TestInt_RowAccessPoliciesShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createRowAccessPolicyHandle(t, id1) createRowAccessPolicyHandle(t, id2) diff --git a/pkg/sdk/testint/schemas_integration_test.go b/pkg/sdk/testint/schemas_integration_test.go index bb1e810ff2..4ab3379351 100644 --- a/pkg/sdk/testint/schemas_integration_test.go +++ b/pkg/sdk/testint/schemas_integration_test.go @@ -83,7 +83,7 @@ func TestInt_SchemasCreate(t *testing.T) { tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) - schemaID := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, testClientHelper().Ids.RandomAccountObjectIdentifier().Name()) + schemaID := testClientHelper().Ids.RandomDatabaseObjectIdentifier() tagValue := random.String() err := client.Schemas.Create(ctx, schemaID, &sdk.CreateSchemaOptions{ Tag: []sdk.TagAssociation{ @@ -116,7 +116,7 @@ func TestInt_SchemasAlter(t *testing.T) { err := client.Sessions.UseSchema(ctx, testSchema(t).ID()) require.NoError(t, err) }) - newID := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, random.String()) + newID := testClientHelper().Ids.RandomDatabaseObjectIdentifier() err := client.Schemas.Alter(ctx, schema.ID(), &sdk.AlterSchemaOptions{ NewName: newID, }) @@ -178,7 +178,7 @@ func TestInt_SchemasAlter(t *testing.T) { }) t.Run("unset", func(t *testing.T) { - schemaID := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, random.String()) + schemaID := testClientHelper().Ids.RandomDatabaseObjectIdentifier() comment := random.Comment() err := client.Schemas.Create(ctx, schemaID, &sdk.CreateSchemaOptions{ Comment: sdk.String(comment), @@ -203,7 +203,7 @@ func TestInt_SchemasAlter(t *testing.T) { }) t.Run("set tags", func(t *testing.T) { - schemaID := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, random.String()) + schemaID := testClientHelper().Ids.RandomDatabaseObjectIdentifier() err := client.Schemas.Create(ctx, schemaID, nil) require.NoError(t, err) t.Cleanup(func() { @@ -237,7 +237,7 @@ func TestInt_SchemasAlter(t *testing.T) { tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) - schemaID := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, testClientHelper().Ids.RandomAccountObjectIdentifier().Name()) + schemaID := testClientHelper().Ids.RandomDatabaseObjectIdentifier() tagValue := random.String() err := client.Schemas.Create(ctx, schemaID, &sdk.CreateSchemaOptions{ Tag: []sdk.TagAssociation{ diff --git a/pkg/sdk/testint/sequences_integration_test.go b/pkg/sdk/testint/sequences_integration_test.go index 33140ece7f..c09c6208a2 100644 --- a/pkg/sdk/testint/sequences_integration_test.go +++ b/pkg/sdk/testint/sequences_integration_test.go @@ -19,8 +19,6 @@ func TestInt_Sequences(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupSequenceHandle := func(t *testing.T, id sdk.SchemaObjectIdentifier) func() { t.Helper() return func() { @@ -35,7 +33,7 @@ func TestInt_Sequences(t *testing.T) { createSequenceHandle := func(t *testing.T) *sdk.Sequence { t.Helper() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.StringN(4)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() sr := sdk.NewCreateSequenceRequest(id).WithStart(sdk.Int(1)).WithIncrement(sdk.Int(1)) err := client.Sequences.Create(ctx, sr) require.NoError(t, err) @@ -64,10 +62,9 @@ func TestInt_Sequences(t *testing.T) { } t.Run("create sequence", func(t *testing.T) { - name := random.StringN(4) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() - comment := random.StringN(4) + comment := random.Comment() request := sdk.NewCreateSequenceRequest(id). WithStart(sdk.Int(1)). WithIncrement(sdk.Int(1)). @@ -110,7 +107,7 @@ func TestInt_Sequences(t *testing.T) { t.Run("describe sequence", func(t *testing.T) { e := createSequenceHandle(t) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, e.Name) + id := e.ID() details, err := client.Sequences.Describe(ctx, id) require.NoError(t, err) @@ -128,9 +125,9 @@ func TestInt_Sequences(t *testing.T) { t.Run("alter sequence: set options", func(t *testing.T) { e := createSequenceHandle(t) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, e.Name) + id := e.ID() - comment := random.StringN(4) + comment := random.Comment() set := sdk.NewSequenceSetRequest().WithComment(&comment).WithValuesBehavior(sdk.ValuesBehaviorPointer(sdk.ValuesBehaviorNoOrder)) err := client.Sequences.Alter(ctx, sdk.NewAlterSequenceRequest(id).WithSet(set)) require.NoError(t, err) @@ -140,7 +137,7 @@ func TestInt_Sequences(t *testing.T) { t.Run("alter sequence: set increment", func(t *testing.T) { e := createSequenceHandle(t) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, e.Name) + id := e.ID() increment := 2 err := client.Sequences.Alter(ctx, sdk.NewAlterSequenceRequest(id).WithSetIncrement(&increment)) @@ -149,12 +146,11 @@ func TestInt_Sequences(t *testing.T) { }) t.Run("alter sequence: rename", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.Sequences.Create(ctx, sdk.NewCreateSequenceRequest(id)) require.NoError(t, err) - nid := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.String()) + nid := testClientHelper().Ids.RandomSchemaObjectIdentifier() err = client.Sequences.Alter(ctx, sdk.NewAlterSequenceRequest(id).WithRenameTo(&nid)) if err != nil { t.Cleanup(cleanupSequenceHandle(t, id)) @@ -174,8 +170,6 @@ func TestInt_SequencesShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupSequenceHandle := func(t *testing.T, id sdk.SchemaObjectIdentifier) func() { t.Helper() return func() { @@ -200,9 +194,8 @@ func TestInt_SequencesShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createSequenceHandle(t, id1) createSequenceHandle(t, id2) diff --git a/pkg/sdk/testint/session_policies_gen_integration_test.go b/pkg/sdk/testint/session_policies_gen_integration_test.go index 45cb386eb9..130c2aa747 100644 --- a/pkg/sdk/testint/session_policies_gen_integration_test.go +++ b/pkg/sdk/testint/session_policies_gen_integration_test.go @@ -49,8 +49,7 @@ func TestInt_SessionPolicies(t *testing.T) { createSessionPolicy := func(t *testing.T) *sdk.SessionPolicy { t.Helper() - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.SessionPolicies.Create(ctx, sdk.NewCreateSessionPolicyRequest(id)) require.NoError(t, err) @@ -63,8 +62,7 @@ func TestInt_SessionPolicies(t *testing.T) { } t.Run("create session_policy: complete case", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() comment := random.Comment() request := sdk.NewCreateSessionPolicyRequest(id). @@ -84,8 +82,7 @@ func TestInt_SessionPolicies(t *testing.T) { }) t.Run("create session_policy: no optionals", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() request := sdk.NewCreateSessionPolicyRequest(id) @@ -100,8 +97,7 @@ func TestInt_SessionPolicies(t *testing.T) { }) t.Run("drop session_policy: existing", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.SessionPolicies.Create(ctx, sdk.NewCreateSessionPolicyRequest(id)) require.NoError(t, err) @@ -121,8 +117,7 @@ func TestInt_SessionPolicies(t *testing.T) { }) t.Run("alter session_policy: set value and unset value", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.SessionPolicies.Create(ctx, sdk.NewCreateSessionPolicyRequest(id)) require.NoError(t, err) @@ -151,8 +146,7 @@ func TestInt_SessionPolicies(t *testing.T) { tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.SessionPolicies.Create(ctx, sdk.NewCreateSessionPolicyRequest(id)) require.NoError(t, err) @@ -188,14 +182,12 @@ func TestInt_SessionPolicies(t *testing.T) { }) t.Run("alter session_policy: rename", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.SessionPolicies.Create(ctx, sdk.NewCreateSessionPolicyRequest(id)) require.NoError(t, err) - newName := random.String() - newId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, newName) + newId := testClientHelper().Ids.RandomSchemaObjectIdentifier() alterRequest := sdk.NewAlterSessionPolicyRequest(id).WithRenameTo(&newId) err = client.SessionPolicies.Alter(ctx, alterRequest) diff --git a/pkg/sdk/testint/stages_gen_integration_test.go b/pkg/sdk/testint/stages_gen_integration_test.go index 32f4eb1fc4..dd70aa4429 100644 --- a/pkg/sdk/testint/stages_gen_integration_test.go +++ b/pkg/sdk/testint/stages_gen_integration_test.go @@ -5,7 +5,6 @@ import ( "fmt" "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/ids" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testenvs" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" @@ -91,7 +90,7 @@ func TestInt_Stages(t *testing.T) { } t.Run("CreateInternal", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.Stages.CreateInternal(ctx, sdk.NewCreateInternalStageRequest(id). WithFileFormat(sdk.NewStageFileFormatRequest().WithType(&sdk.FileFormatTypeJSON)). @@ -105,7 +104,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("CreateInternal - temporary", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.Stages.CreateInternal(ctx, sdk.NewCreateInternalStageRequest(id). WithTemporary(sdk.Bool(true)). @@ -120,7 +119,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("CreateOnS3 - IAM User", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() s3Req := sdk.NewExternalS3StageParamsRequest(awsBucketUrl). WithCredentials(sdk.NewExternalStageS3CredentialsRequest(). @@ -139,7 +138,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("CreateOnS3 - temporary - Storage Integration", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() s3Req := sdk.NewExternalS3StageParamsRequest(awsBucketUrl). WithStorageIntegration(sdk.Pointer(ids.PrecreatedS3StorageIntegration)) @@ -157,7 +156,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("CreateOnGCS", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.Stages.CreateOnGCS(ctx, sdk.NewCreateOnGCSStageRequest(id). WithFileFormat(sdk.NewStageFileFormatRequest().WithType(&sdk.FileFormatTypeJSON)). @@ -173,7 +172,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("CreateOnAzure - Storage Integration", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.Stages.CreateOnAzure(ctx, sdk.NewCreateOnAzureStageRequest(id). WithFileFormat(sdk.NewStageFileFormatRequest().WithType(&sdk.FileFormatTypeJSON)). @@ -189,7 +188,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("CreateOnAzure - Shared Access Signature", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.Stages.CreateOnAzure(ctx, sdk.NewCreateOnAzureStageRequest(id). WithFileFormat(sdk.NewStageFileFormatRequest().WithType(&sdk.FileFormatTypeJSON)). @@ -209,8 +208,8 @@ func TestInt_Stages(t *testing.T) { }) t.Run("Alter - rename", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) - newId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() + newId := testClientHelper().Ids.RandomSchemaObjectIdentifier() renamed := false err := client.Stages.CreateInternal(ctx, sdk.NewCreateInternalStageRequest(id)) @@ -237,7 +236,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("Alter - set unset tags", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() tag, cleanupTag := testClientHelper().Tag.CreateTag(t) t.Cleanup(cleanupTag) @@ -273,7 +272,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("AlterInternalStage", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.Stages.CreateInternal(ctx, sdk.NewCreateInternalStageRequest(id). WithCopyOptions(sdk.NewStageCopyOptionsRequest().WithSizeLimit(sdk.Int(100))). @@ -336,7 +335,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("AlterExternalS3Stage", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() createBasicS3Stage(t, id) err := client.Stages.AlterExternalS3Stage(ctx, sdk.NewAlterExternalS3StageStageRequest(id). @@ -356,7 +355,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("AlterExternalGCSStage", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() createBasicGcsStage(t, id) err := client.Stages.AlterExternalGCSStage(ctx, sdk.NewAlterExternalGCSStageStageRequest(id). @@ -371,7 +370,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("AlterExternalAzureStage", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() createBasicAzureStage(t, id) err := client.Stages.AlterExternalAzureStage(ctx, sdk.NewAlterExternalAzureStageStageRequest(id). @@ -386,7 +385,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("AlterDirectoryTable", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() createBasicS3Stage(t, id) stageProperties, err := client.Stages.Describe(ctx, id) @@ -419,7 +418,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("Drop", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.Stages.CreateInternal(ctx, sdk.NewCreateInternalStageRequest(id)) require.NoError(t, err) @@ -437,7 +436,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("Describe internal", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.Stages.CreateInternal(ctx, sdk.NewCreateInternalStageRequest(id)) require.NoError(t, err) @@ -466,7 +465,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("Describe external s3", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() createBasicS3Stage(t, id) stageProperties, err := client.Stages.Describe(ctx, id) @@ -489,7 +488,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("Describe external gcs", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() createBasicGcsStage(t, id) stageProperties, err := client.Stages.Describe(ctx, id) @@ -505,7 +504,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("Describe external azure", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() createBasicAzureStage(t, id) stageProperties, err := client.Stages.Describe(ctx, id) @@ -528,7 +527,7 @@ func TestInt_Stages(t *testing.T) { }) t.Run("Show internal", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.Stages.CreateInternal(ctx, sdk.NewCreateInternalStageRequest(id). WithDirectoryTableOptions(sdk.NewInternalDirectoryTableOptionsRequest().WithEnable(sdk.Bool(true))). @@ -562,8 +561,6 @@ func TestInt_StagesShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupStageHandle := func(id sdk.SchemaObjectIdentifier) func() { return func() { err := client.Stages.Drop(ctx, sdk.NewDropStageRequest(id)) @@ -585,9 +582,8 @@ func TestInt_StagesShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createStageHandle(t, id1) createStageHandle(t, id2) diff --git a/pkg/sdk/testint/streamlits_integration_test.go b/pkg/sdk/testint/streamlits_integration_test.go index bdfcf990dc..45d2119789 100644 --- a/pkg/sdk/testint/streamlits_integration_test.go +++ b/pkg/sdk/testint/streamlits_integration_test.go @@ -15,8 +15,6 @@ func TestInt_Streamlits(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupStreamlitHandle := func(id sdk.SchemaObjectIdentifier) func() { return func() { err := client.Streamlits.Drop(ctx, sdk.NewDropStreamlitRequest(id).WithIfExists(sdk.Bool(true))) @@ -27,7 +25,7 @@ func TestInt_Streamlits(t *testing.T) { createStreamlitHandle := func(t *testing.T, stage *sdk.Stage, mainFile string) *sdk.Streamlit { t.Helper() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.StringN(4)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() request := sdk.NewCreateStreamlitRequest(id, stage.Location(), mainFile) err := client.Streamlits.Create(ctx, request) require.NoError(t, err) @@ -60,8 +58,8 @@ func TestInt_Streamlits(t *testing.T) { stage, cleanupStage := testClientHelper().Stage.CreateStage(t) t.Cleanup(cleanupStage) - comment := random.StringN(4) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.StringN(4)) + comment := random.Comment() + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() mainFile := "manifest.yml" request := sdk.NewCreateStreamlitRequest(id, stage.Location(), mainFile).WithComment(&comment) err := client.Streamlits.Create(ctx, request) @@ -79,8 +77,8 @@ func TestInt_Streamlits(t *testing.T) { role, roleCleanup := testClientHelper().Role.CreateRole(t) t.Cleanup(roleCleanup) - comment := random.StringN(4) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.StringN(4)) + comment := random.Comment() + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() mainFile := "manifest.yml" request := sdk.NewCreateStreamlitRequest(id, stage.Location(), mainFile).WithComment(&comment) err := client.Streamlits.Create(ctx, request) @@ -147,8 +145,8 @@ func TestInt_Streamlits(t *testing.T) { databaseRoleId := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, databaseRole.Name) - comment := random.StringN(4) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.StringN(4)) + comment := random.Comment() + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() mainFile := "manifest.yml" request := sdk.NewCreateStreamlitRequest(id, stage.Location(), mainFile).WithComment(&comment) err := client.Streamlits.Create(ctx, request) @@ -210,8 +208,8 @@ func TestInt_Streamlits(t *testing.T) { manifest := "manifest.yml" e := createStreamlitHandle(t, stage, manifest) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, e.Name) - comment := random.StringN(4) + id := e.ID() + comment := random.Comment() set := sdk.NewStreamlitSetRequest(sdk.String(stage.Location()), &manifest).WithComment(&comment) err := client.Streamlits.Alter(ctx, sdk.NewAlterStreamlitRequest(id).WithSet(set)) require.NoError(t, err) @@ -222,16 +220,13 @@ func TestInt_Streamlits(t *testing.T) { stage, cleanupStage := testClientHelper().Stage.CreateStage(t) t.Cleanup(cleanupStage) e := createStreamlitHandle(t, stage, "manifest.yml") + id := e.ID() + t.Cleanup(cleanupStreamlitHandle(id)) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, e.Name) - nid := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.StringN(3)) + nid := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.Streamlits.Alter(ctx, sdk.NewAlterStreamlitRequest(id).WithRenameTo(&nid)) - if err != nil { - t.Cleanup(cleanupStreamlitHandle(id)) - } else { - t.Cleanup(cleanupStreamlitHandle(nid)) - } require.NoError(t, err) + t.Cleanup(cleanupStreamlitHandle(nid)) _, err = client.Streamlits.ShowByID(ctx, id) require.ErrorIs(t, err, collections.ErrObjectNotFound) @@ -279,7 +274,7 @@ func TestInt_Streamlits(t *testing.T) { mainFile := "manifest.yml" e := createStreamlitHandle(t, stage, mainFile) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, e.Name) + id := e.ID() detail, err := client.Streamlits.Describe(ctx, id) require.NoError(t, err) @@ -296,7 +291,6 @@ func TestInt_StreamlitsShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) cleanupStreamlitHandle := func(t *testing.T, id sdk.SchemaObjectIdentifier) func() { t.Helper() return func() { @@ -321,9 +315,8 @@ func TestInt_StreamlitsShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) stage, cleanupStage := testClientHelper().Stage.CreateStage(t) t.Cleanup(cleanupStage) diff --git a/pkg/sdk/testint/streams_gen_integration_test.go b/pkg/sdk/testint/streams_gen_integration_test.go index ce6c4f96b6..6d8d33db0a 100644 --- a/pkg/sdk/testint/streams_gen_integration_test.go +++ b/pkg/sdk/testint/streams_gen_integration_test.go @@ -5,7 +5,6 @@ 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/stretchr/testify/assert" @@ -35,7 +34,7 @@ func TestInt_Streams(t *testing.T) { table, cleanupTable := testClientHelper().Table.CreateTableInSchema(t, schema.ID()) t.Cleanup(cleanupTable) - id := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() req := sdk.NewCreateStreamOnTableRequest(id, table.ID()).WithComment(sdk.String("some comment")) err := client.Streams.CreateOnTable(ctx, req) require.NoError(t, err) @@ -47,18 +46,17 @@ func TestInt_Streams(t *testing.T) { s, err := client.Streams.ShowByID(ctx, id) require.NoError(t, err) - assert.Equal(t, table.ID().FullyQualifiedName(), *s.TableName) + assert.Equal(t, table.ID().FullyQualifiedName(), sdk.NewSchemaObjectIdentifierFromFullyQualifiedName(*s.TableName).FullyQualifiedName()) assertStream(t, s, id, "Table", "DEFAULT") }) t.Run("CreateOnExternalTable", func(t *testing.T) { - stageName := random.AlphaN(10) - stageID := sdk.NewSchemaObjectIdentifier(TestDatabaseName, TestSchemaName, stageName) + stageID := testClientHelper().Ids.RandomSchemaObjectIdentifier() stageLocation := fmt.Sprintf("@%s", stageID.FullyQualifiedName()) _, stageCleanup := testClientHelper().Stage.CreateStageWithURL(t, stageID) t.Cleanup(stageCleanup) - externalTableId := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + externalTableId := testClientHelper().Ids.RandomSchemaObjectIdentifier() err := client.ExternalTables.Create(ctx, sdk.NewCreateExternalTableRequest(externalTableId, stageLocation).WithFileFormat(*sdk.NewExternalTableFileFormatRequest().WithFileFormatType(sdk.ExternalTableFileFormatTypeJSON))) require.NoError(t, err) t.Cleanup(func() { @@ -66,7 +64,7 @@ func TestInt_Streams(t *testing.T) { require.NoError(t, err) }) - id := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() req := sdk.NewCreateStreamOnExternalTableRequest(id, externalTableId).WithInsertOnly(sdk.Bool(true)).WithComment(sdk.String("some comment")) err = client.Streams.CreateOnExternalTable(ctx, req) require.NoError(t, err) @@ -78,7 +76,7 @@ func TestInt_Streams(t *testing.T) { s, err := client.Streams.ShowByID(ctx, id) require.NoError(t, err) - assert.Equal(t, externalTableId.FullyQualifiedName(), *s.TableName) + assert.Equal(t, externalTableId.FullyQualifiedName(), sdk.NewSchemaObjectIdentifierFromFullyQualifiedName(*s.TableName).FullyQualifiedName()) assertStream(t, s, id, "External Table", "INSERT_ONLY") }) @@ -87,7 +85,7 @@ func TestInt_Streams(t *testing.T) { stageId := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, stage.Name) t.Cleanup(cleanupStage) - id := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() req := sdk.NewCreateStreamOnDirectoryTableRequest(id, stageId).WithComment(sdk.String("some comment")) err := client.Streams.CreateOnDirectoryTable(ctx, req) require.NoError(t, err) @@ -110,7 +108,7 @@ func TestInt_Streams(t *testing.T) { view, cleanupView := testClientHelper().View.CreateView(t, fmt.Sprintf("SELECT id FROM %s", tableId.FullyQualifiedName())) t.Cleanup(cleanupView) - id := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() req := sdk.NewCreateStreamOnViewRequest(id, view.ID()).WithComment(sdk.String("some comment")) err := client.Streams.CreateOnView(ctx, req) require.NoError(t, err) @@ -129,7 +127,7 @@ func TestInt_Streams(t *testing.T) { table, cleanupTable := testClientHelper().Table.CreateTableInSchema(t, schema.ID()) t.Cleanup(cleanupTable) - id := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() req := sdk.NewCreateStreamOnTableRequest(id, table.ID()).WithComment(sdk.String("some comment")) err := client.Streams.CreateOnTable(ctx, req) require.NoError(t, err) @@ -138,7 +136,7 @@ func TestInt_Streams(t *testing.T) { require.NoError(t, err) }) - cloneId := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + cloneId := testClientHelper().Ids.RandomSchemaObjectIdentifier() err = client.Streams.Clone(ctx, sdk.NewCloneStreamRequest(cloneId, id)) require.NoError(t, err) t.Cleanup(func() { @@ -150,14 +148,14 @@ func TestInt_Streams(t *testing.T) { require.NoError(t, err) assertStream(t, s, cloneId, "Table", "DEFAULT") - assert.Equal(t, table.ID().FullyQualifiedName(), *s.TableName) + assert.Equal(t, table.ID().FullyQualifiedName(), sdk.NewSchemaObjectIdentifierFromFullyQualifiedName(*s.TableName).FullyQualifiedName()) }) t.Run("Alter tags", func(t *testing.T) { table, cleanupTable := testClientHelper().Table.CreateTableInSchema(t, schema.ID()) t.Cleanup(cleanupTable) - id := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() req := sdk.NewCreateStreamOnTableRequest(id, table.ID()) err := client.Streams.CreateOnTable(ctx, req) require.NoError(t, err) @@ -198,7 +196,7 @@ func TestInt_Streams(t *testing.T) { table, cleanupTable := testClientHelper().Table.CreateTableInSchema(t, schema.ID()) t.Cleanup(cleanupTable) - id := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() req := sdk.NewCreateStreamOnTableRequest(id, table.ID()) err := client.Streams.CreateOnTable(ctx, req) require.NoError(t, err) @@ -233,7 +231,7 @@ func TestInt_Streams(t *testing.T) { table, cleanupTable := testClientHelper().Table.CreateTableInSchema(t, schema.ID()) t.Cleanup(cleanupTable) - id := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() req := sdk.NewCreateStreamOnTableRequest(id, table.ID()).WithComment(sdk.String("some comment")) err := client.Streams.CreateOnTable(ctx, req) require.NoError(t, err) @@ -252,7 +250,7 @@ func TestInt_Streams(t *testing.T) { table, cleanupTable := testClientHelper().Table.CreateTableInSchema(t, schema.ID()) t.Cleanup(cleanupTable) - id := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() req := sdk.NewCreateStreamOnTableRequest(id, table.ID()).WithComment(sdk.String("some comment")) err := client.Streams.CreateOnTable(ctx, req) require.NoError(t, err) @@ -281,7 +279,7 @@ func TestInt_Streams(t *testing.T) { table, cleanupTable := testClientHelper().Table.CreateTableInSchema(t, schema.ID()) t.Cleanup(cleanupTable) - id := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() req := sdk.NewCreateStreamOnTableRequest(id, table.ID()).WithComment(sdk.String("some comment")) err := client.Streams.CreateOnTable(ctx, req) require.NoError(t, err) @@ -315,7 +313,7 @@ func TestInt_Streams(t *testing.T) { table, cleanupTable := testClientHelper().Table.CreateTableInSchema(t, schema.ID()) t.Cleanup(cleanupTable) - id := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() req := sdk.NewCreateStreamOnTableRequest(id, table.ID()).WithComment(sdk.String("some comment")) err := client.Streams.CreateOnTable(ctx, req) require.NoError(t, err) @@ -324,7 +322,7 @@ func TestInt_Streams(t *testing.T) { require.NoError(t, err) }) - id2 := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + id2 := testClientHelper().Ids.RandomSchemaObjectIdentifier() req2 := sdk.NewCreateStreamOnTableRequest(id2, table.ID()).WithComment(sdk.String("some comment")) err = client.Streams.CreateOnTable(ctx, req2) require.NoError(t, err) @@ -353,7 +351,7 @@ func TestInt_Streams(t *testing.T) { idPrefix := "stream_show_" - id := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, idPrefix+random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifierWithPrefix(idPrefix) req := sdk.NewCreateStreamOnTableRequest(id, table.ID()).WithComment(sdk.String("some comment")) err := client.Streams.CreateOnTable(ctx, req) require.NoError(t, err) @@ -362,7 +360,7 @@ func TestInt_Streams(t *testing.T) { require.NoError(t, err) }) - id2 := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, idPrefix+random.AlphanumericN(32)) + id2 := testClientHelper().Ids.RandomSchemaObjectIdentifierWithPrefix(idPrefix) req2 := sdk.NewCreateStreamOnTableRequest(id2, table.ID()).WithComment(sdk.String("some comment")) err = client.Streams.CreateOnTable(ctx, req2) require.NoError(t, err) @@ -397,7 +395,7 @@ func TestInt_Streams(t *testing.T) { table, cleanupTable := testClientHelper().Table.CreateTableInSchema(t, schema.ID()) t.Cleanup(cleanupTable) - id := sdk.NewSchemaObjectIdentifier(db.Name, schema.Name, random.AlphanumericN(32)) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() req := sdk.NewCreateStreamOnTableRequest(id, table.ID()).WithComment(sdk.String("some comment")) err := client.Streams.CreateOnTable(ctx, req) require.NoError(t, err) @@ -415,7 +413,7 @@ func TestInt_Streams(t *testing.T) { assert.Equal(t, schema.Name, s.SchemaName) assert.Nil(t, s.TableOn) assert.Equal(t, "some comment", *s.Comment) - assert.Equal(t, table.ID().FullyQualifiedName(), *s.TableName) + assert.Equal(t, table.ID().FullyQualifiedName(), sdk.NewSchemaObjectIdentifierFromFullyQualifiedName(*s.TableName).FullyQualifiedName()) assert.Equal(t, "Table", *s.SourceType) assert.Equal(t, "DEFAULT", *s.Mode) }) @@ -425,7 +423,6 @@ func TestInt_StreamsShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) table, cleanupTable := testClientHelper().Table.CreateTable(t) t.Cleanup(cleanupTable) @@ -451,9 +448,8 @@ func TestInt_StreamsShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createStreamHandle(t, id1) createStreamHandle(t, id2) diff --git a/pkg/sdk/testint/tables_integration_test.go b/pkg/sdk/testint/tables_integration_test.go index 3a732c3f92..f2c4aa35b3 100644 --- a/pkg/sdk/testint/tables_integration_test.go +++ b/pkg/sdk/testint/tables_integration_test.go @@ -26,9 +26,6 @@ func TestInt_Table(t *testing.T) { client := testClient(t) ctx := testContext(t) - database := testDb(t) - schema := testSchema(t) - cleanupTableProvider := func(id sdk.SchemaObjectIdentifier) func() { return func() { err := client.Tables.Drop(ctx, sdk.NewDropTableRequest(id)) @@ -78,8 +75,7 @@ func TestInt_Table(t *testing.T) { } t.Run("create table: no optionals", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("FIRST_COLUMN", sdk.DataTypeNumber).WithDefaultValue(sdk.NewColumnDefaultValueRequest().WithIdentity(sdk.NewColumnIdentityRequest(1, 1))), *sdk.NewTableColumnRequest("SECOND_COLUMN", sdk.DataTypeNumber).WithDefaultValue(sdk.NewColumnDefaultValueRequest().WithIdentity(sdk.NewColumnIdentityRequest(1, 1))), @@ -100,25 +96,24 @@ func TestInt_Table(t *testing.T) { t.Cleanup(maskingPolicyCleanup) table2, table2Cleanup := testClientHelper().Table.CreateTable(t) t.Cleanup(table2Cleanup) - name := random.String() - comment := random.String() + comment := random.Comment() columnTags := []sdk.TagAssociation{ { - Name: sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, tag1.Name), + Name: tag1.ID(), Value: "v1", }, { - Name: sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, tag2.Name), + Name: tag2.ID(), Value: "v2", }, } - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_3", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR). WithDefaultValue(sdk.NewColumnDefaultValueRequest().WithExpression(sdk.String("'default'"))). - WithMaskingPolicy(sdk.NewColumnMaskingPolicyRequest(sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, maskingPolicy.Name)).WithUsing([]string{"COLUMN_1", "COLUMN_3"})). + WithMaskingPolicy(sdk.NewColumnMaskingPolicyRequest(maskingPolicy.ID()).WithUsing([]string{"COLUMN_1", "COLUMN_3"})). WithTags(columnTags). WithNotNull(sdk.Bool(true)), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeNumber).WithDefaultValue(sdk.NewColumnDefaultValueRequest().WithIdentity(sdk.NewColumnIdentityRequest(1, 1))), @@ -126,7 +121,7 @@ func TestInt_Table(t *testing.T) { outOfLineConstraint := sdk.NewOutOfLineConstraintRequest(sdk.ColumnConstraintTypeForeignKey). WithName(sdk.String("OUT_OF_LINE_CONSTRAINT")). WithColumns([]string{"COLUMN_1"}). - WithForeignKey(sdk.NewOutOfLineForeignKeyRequest(sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, table2.Name), []string{"id"}). + WithForeignKey(sdk.NewOutOfLineForeignKeyRequest(table2.ID(), []string{"id"}). WithMatch(sdk.Pointer(sdk.FullMatchType)). WithOn(sdk.NewForeignKeyOnAction(). WithOnDelete(sdk.Pointer(sdk.ForeignKeySetNullAction)).WithOnUpdate(sdk.Pointer(sdk.ForeignKeyRestrictAction)))) @@ -181,11 +176,10 @@ func TestInt_Table(t *testing.T) { *sdk.NewTableAsSelectColumnRequest("COLUMN_2"). WithType_(sdk.Pointer(sdk.DataTypeVARCHAR)). WithCopyGrants(sdk.Bool(true)). - WithOrReplace(sdk.Bool(true)).WithMaskingPolicyName(sdk.Pointer(sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, maskingPolicy.Name))), + WithOrReplace(sdk.Bool(true)).WithMaskingPolicyName(sdk.Pointer(maskingPolicy.ID())), } - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() query := "SELECT 1, 2, 3" request := sdk.NewCreateTableAsSelectRequest(id, columns, query) @@ -225,8 +219,7 @@ func TestInt_Table(t *testing.T) { err = os.Remove(f.Name()) require.NoError(t, err) - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() query := fmt.Sprintf(`SELECT ARRAY_AGG(OBJECT_CONSTRUCT(*)) WITHIN GROUP (ORDER BY order_id) FROM TABLE (INFER_SCHEMA(location => '@%s', FILE_FORMAT=>'%s', ignore_case => true))`, stage.ID().FullyQualifiedName(), fileFormat.ID().FullyQualifiedName()) request := sdk.NewCreateTableUsingTemplateRequest(id, query) @@ -252,12 +245,10 @@ func TestInt_Table(t *testing.T) { *sdk.NewTableColumnRequest("col2", "VARCHAR"), *sdk.NewTableColumnRequest("col3", "BOOLEAN"), } - sourceTableName := random.StringRange(8, 28) - sourceTable, sourceTableCleanup := testClientHelper().Table.CreateTableWithColumns(t, schema.ID(), sourceTableName, columns) + sourceTable, sourceTableCleanup := testClientHelper().Table.CreateTableWithColumns(t, columns) t.Cleanup(sourceTableCleanup) - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() request := sdk.NewCreateTableLikeRequest(id, sourceTable.ID()).WithCopyGrants(sdk.Bool(true)) err := client.Tables.CreateLike(ctx, request) @@ -285,12 +276,10 @@ func TestInt_Table(t *testing.T) { *sdk.NewTableColumnRequest("col2", "VARCHAR"), *sdk.NewTableColumnRequest("col3", "BOOLEAN"), } - sourceTableName := random.StringRange(8, 28) - sourceTable, sourceTableCleanup := testClientHelper().Table.CreateTableWithColumns(t, schema.ID(), sourceTableName, columns) + sourceTable, sourceTableCleanup := testClientHelper().Table.CreateTableWithColumns(t, columns) t.Cleanup(sourceTableCleanup) - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() request := sdk.NewCreateTableCloneRequest(id, sourceTable.ID()). WithCopyGrants(sdk.Bool(true)).WithClonePoint(sdk.NewClonePointRequest(). WithAt(*sdk.NewTimeTravelRequest().WithOffset(sdk.Pointer(0))). @@ -320,10 +309,8 @@ func TestInt_Table(t *testing.T) { }) t.Run("alter table: rename", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) - newName := random.String() - newId := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, newName) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() + newId := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_3", sdk.DataTypeVARCHAR), @@ -350,14 +337,12 @@ func TestInt_Table(t *testing.T) { }) t.Run("alter table: swap with", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), } - secondTableName := random.String() - secondTableId := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, secondTableName) + secondTableId := testClientHelper().Ids.RandomSchemaObjectIdentifier() secondTableColumns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), } @@ -386,8 +371,7 @@ func TestInt_Table(t *testing.T) { }) t.Run("alter table: cluster by", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -413,8 +397,7 @@ func TestInt_Table(t *testing.T) { }) t.Run("alter table: resume recluster", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -439,8 +422,7 @@ func TestInt_Table(t *testing.T) { }) t.Run("alter table: drop clustering key", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -464,8 +446,7 @@ func TestInt_Table(t *testing.T) { }) t.Run("alter table: add a column", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -497,8 +478,7 @@ func TestInt_Table(t *testing.T) { }) t.Run("alter table: rename column", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -531,8 +511,7 @@ func TestInt_Table(t *testing.T) { maskingPolicy, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicyIdentity(t, sdk.DataTypeVARCHAR) t.Cleanup(maskingPolicyCleanup) - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR).WithMaskingPolicy(sdk.NewColumnMaskingPolicyRequest(maskingPolicy.ID())), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -561,8 +540,7 @@ func TestInt_Table(t *testing.T) { }) t.Run("alter table: set and unset tags", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -574,11 +552,11 @@ func TestInt_Table(t *testing.T) { columnTags := []sdk.TagAssociationRequest{ { - Name: sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, tag1.Name), + Name: tag1.ID(), Value: "v1", }, { - Name: sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, tag2.Name), + Name: tag2.ID(), Value: "v2", }, } @@ -614,8 +592,7 @@ func TestInt_Table(t *testing.T) { }) t.Run("alter table: drop columns", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -645,14 +622,12 @@ func TestInt_Table(t *testing.T) { // TODO [SNOW-1007542]: check added constraints // Add method similar to getTableColumnsFor based on https://docs.snowflake.com/en/sql-reference/info-schema/table_constraints. t.Run("alter constraint: add", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), } - secondTableName := random.String() - secondTableId := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, secondTableName) + secondTableId := testClientHelper().Ids.RandomSchemaObjectIdentifier() secondTableColumns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_3", sdk.DataTypeVARCHAR).WithInlineConstraint(sdk.NewColumnInlineConstraintRequest("pkey", sdk.ColumnConstraintTypePrimaryKey)), } @@ -668,14 +643,13 @@ func TestInt_Table(t *testing.T) { alterRequest := sdk.NewAlterTableRequest(id). WithConstraintAction(sdk.NewTableConstraintActionRequest(). WithAdd(sdk.NewOutOfLineConstraintRequest(sdk.ColumnConstraintTypeForeignKey).WithName(sdk.String("OUT_OF_LINE_CONSTRAINT")).WithColumns([]string{"COLUMN_1"}). - WithForeignKey(sdk.NewOutOfLineForeignKeyRequest(sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, secondTableName), []string{"COLUMN_3"})))) + WithForeignKey(sdk.NewOutOfLineForeignKeyRequest(secondTableId, []string{"COLUMN_3"})))) err = client.Tables.Alter(ctx, alterRequest) require.NoError(t, err) }) t.Run("add constraint: not null", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), } @@ -695,8 +669,7 @@ func TestInt_Table(t *testing.T) { // TODO [SNOW-1007542]: check renamed constraint t.Run("alter constraint: rename", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -720,8 +693,7 @@ func TestInt_Table(t *testing.T) { // TODO [SNOW-1007542]: check altered constraint t.Run("alter constraint: alter", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -741,8 +713,7 @@ func TestInt_Table(t *testing.T) { // TODO [SNOW-1007542]: check dropped constraint t.Run("alter constraint: drop constraint with name", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -761,8 +732,7 @@ func TestInt_Table(t *testing.T) { }) t.Run("alter constraint: drop primary key without constraint name", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), } @@ -779,8 +749,7 @@ func TestInt_Table(t *testing.T) { }) t.Run("external table: add column", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -813,8 +782,7 @@ func TestInt_Table(t *testing.T) { }) t.Run("external table: rename", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -842,8 +810,7 @@ func TestInt_Table(t *testing.T) { }) t.Run("external table: drop", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -870,8 +837,7 @@ func TestInt_Table(t *testing.T) { // TODO [SNOW-1007542]: check search optimization - after adding https://docs.snowflake.com/en/sql-reference/sql/desc-search-optimization t.Run("add search optimization", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -890,9 +856,8 @@ func TestInt_Table(t *testing.T) { // TODO [SNOW-1007542]: try to check more sets (ddl collation, max data extension time in days, etc.) t.Run("set: with complete options", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) - comment := random.String() + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() + comment := random.Comment() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("COLUMN_1", sdk.DataTypeVARCHAR), *sdk.NewTableColumnRequest("COLUMN_2", sdk.DataTypeVARCHAR), @@ -993,8 +958,6 @@ func TestInt_TablesShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupTableHandle := func(id sdk.SchemaObjectIdentifier) func() { return func() { err := client.Tables.Drop(ctx, sdk.NewDropTableRequest(id)) @@ -1019,9 +982,8 @@ func TestInt_TablesShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createTableHandle(t, id1) createTableHandle(t, id2) @@ -1036,8 +998,7 @@ func TestInt_TablesShowByID(t *testing.T) { }) t.Run("show by id: check schema evolution record", func(t *testing.T) { - name := random.AlphaN(4) - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() columns := []sdk.TableColumnRequest{ *sdk.NewTableColumnRequest("c1", sdk.DataTypeNumber).WithDefaultValue(sdk.NewColumnDefaultValueRequest().WithIdentity(sdk.NewColumnIdentityRequest(1, 1))), @@ -1056,7 +1017,7 @@ func TestInt_TablesShowByID(t *testing.T) { nil) require.NoError(t, err) - stage, stageCleanup := testClientHelper().Stage.CreateStageInSchema(t, sdk.NewDatabaseObjectIdentifier(testDb(t).Name, schemaTest.Name)) + stage, stageCleanup := testClientHelper().Stage.CreateStage(t) t.Cleanup(stageCleanup) testClientHelper().Stage.PutOnStage(t, stage.ID(), "schema_evolution_record.json") diff --git a/pkg/sdk/testint/tags_integration_test.go b/pkg/sdk/testint/tags_integration_test.go index 8c3704f9e1..eb4911222c 100644 --- a/pkg/sdk/testint/tags_integration_test.go +++ b/pkg/sdk/testint/tags_integration_test.go @@ -16,9 +16,7 @@ func TestInt_Tags(t *testing.T) { client := testClient(t) ctx := context.Background() - databaseTest, databaseCleanup := testClientHelper().Database.CreateDatabase(t) - t.Cleanup(databaseCleanup) - schemaTest, schemaCleanup := testClientHelper().Schema.CreateSchemaInDatabase(t, databaseTest.ID()) + schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) assertTagHandle := func(t *testing.T, tag *sdk.Tag, expectedName string, expectedComment string, expectedAllowedValues []string) { @@ -42,7 +40,7 @@ func TestInt_Tags(t *testing.T) { createTagHandle := func(t *testing.T) *sdk.Tag { t.Helper() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifierInSchema(schema.ID()) err := client.Tags.Create(ctx, sdk.NewCreateTagRequest(id)) require.NoError(t, err) t.Cleanup(cleanupTagHandle(id)) @@ -53,8 +51,7 @@ func TestInt_Tags(t *testing.T) { } t.Run("create tag: comment", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifierInSchema(schema.ID()) comment := random.Comment() request := sdk.NewCreateTagRequest(id).WithComment(&comment) @@ -64,12 +61,11 @@ func TestInt_Tags(t *testing.T) { tag, err := client.Tags.ShowByID(ctx, id) require.NoError(t, err) - assertTagHandle(t, tag, name, comment, nil) + assertTagHandle(t, tag, id.Name(), comment, nil) }) t.Run("create tag: allowed values", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifierInSchema(schema.ID()) values := []string{"value1", "value2"} request := sdk.NewCreateTagRequest(id).WithAllowedValues(values) @@ -79,12 +75,11 @@ func TestInt_Tags(t *testing.T) { tag, err := client.Tags.ShowByID(ctx, id) require.NoError(t, err) - assertTagHandle(t, tag, name, "", values) + assertTagHandle(t, tag, id.Name(), "", values) }) t.Run("create tag: comment and allowed values", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifierInSchema(schema.ID()) comment := random.Comment() values := []string{"value1", "value2"} @@ -98,19 +93,18 @@ func TestInt_Tags(t *testing.T) { tag, err := client.Tags.ShowByID(ctx, id) require.NoError(t, err) - assertTagHandle(t, tag, name, comment, values) + assertTagHandle(t, tag, id.Name(), comment, values) }) t.Run("create tag: no optionals", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifierInSchema(schema.ID()) err := client.Tags.Create(ctx, sdk.NewCreateTagRequest(id)) require.NoError(t, err) t.Cleanup(cleanupTagHandle(id)) tag, err := client.Tags.ShowByID(ctx, id) require.NoError(t, err) - assertTagHandle(t, tag, name, "", nil) + assertTagHandle(t, tag, id.Name(), "", nil) }) t.Run("drop tag: existing", func(t *testing.T) { @@ -124,8 +118,7 @@ func TestInt_Tags(t *testing.T) { }) t.Run("drop tag: non-existing", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifierInSchema(schema.ID()) err := client.Tags.Drop(ctx, sdk.NewDropTagRequest(id)) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) @@ -170,7 +163,7 @@ func TestInt_Tags(t *testing.T) { }) t.Run("alter tag: set and unset masking policies", func(t *testing.T) { - policyTest, policyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicyInSchema(t, schemaTest.ID()) + policyTest, policyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicy(t) t.Cleanup(policyCleanup) tag := createTagHandle(t) @@ -210,7 +203,7 @@ func TestInt_Tags(t *testing.T) { tag := createTagHandle(t) id := tag.ID() - nid := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.String()) + nid := testClientHelper().Ids.RandomSchemaObjectIdentifierInSchema(schema.ID()) err := client.Tags.Alter(ctx, sdk.NewAlterTagRequest(id).WithRename(nid)) if err != nil { t.Cleanup(cleanupTagHandle(id)) @@ -283,8 +276,6 @@ func TestInt_TagsShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupTagHandle := func(id sdk.SchemaObjectIdentifier) func() { return func() { err := client.Tags.Drop(ctx, sdk.NewDropTagRequest(id)) @@ -306,9 +297,8 @@ func TestInt_TagsShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createTagHandle(t, id1) createTagHandle(t, id2) diff --git a/pkg/sdk/testint/tasks_gen_integration_test.go b/pkg/sdk/testint/tasks_gen_integration_test.go index adb751b14d..35ecb5a6a8 100644 --- a/pkg/sdk/testint/tasks_gen_integration_test.go +++ b/pkg/sdk/testint/tasks_gen_integration_test.go @@ -4,7 +4,6 @@ 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/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -107,8 +106,7 @@ func TestInt_Tasks(t *testing.T) { createTaskBasicRequest := func(t *testing.T) *sdk.CreateTaskRequest { t.Helper() - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() return sdk.NewCreateTaskRequest(id, sql) } @@ -171,8 +169,7 @@ func TestInt_Tasks(t *testing.T) { }) t.Run("create task: with after", func(t *testing.T) { - otherName := random.String() - otherId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, otherName) + otherId := testClientHelper().Ids.RandomSchemaObjectIdentifier() request := sdk.NewCreateTaskRequest(otherId, sql).WithSchedule(sdk.String("10 MINUTE")) @@ -187,24 +184,21 @@ func TestInt_Tasks(t *testing.T) { }) t.Run("create dag of tasks", func(t *testing.T) { - rootName := random.String() - rootId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, rootName) + rootId := testClientHelper().Ids.RandomSchemaObjectIdentifier() request := sdk.NewCreateTaskRequest(rootId, sql).WithSchedule(sdk.String("10 MINUTE")) root := createTaskWithRequest(t, request) require.Empty(t, root.Predecessors) - t1Name := random.String() - t1Id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, t1Name) + t1Id := testClientHelper().Ids.RandomSchemaObjectIdentifier() request = sdk.NewCreateTaskRequest(t1Id, sql).WithAfter([]sdk.SchemaObjectIdentifier{rootId}) t1 := createTaskWithRequest(t, request) require.Equal(t, []sdk.SchemaObjectIdentifier{rootId}, t1.Predecessors) - t2Name := random.String() - t2Id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, t2Name) + t2Id := testClientHelper().Ids.RandomSchemaObjectIdentifier() request = sdk.NewCreateTaskRequest(t2Id, sql).WithAfter([]sdk.SchemaObjectIdentifier{t1Id, rootId}) t2 := createTaskWithRequest(t, request) @@ -213,8 +207,7 @@ func TestInt_Tasks(t *testing.T) { require.Contains(t, t2.Predecessors, t1Id) require.Len(t, t2.Predecessors, 2) - t3Name := random.String() - t3Id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, t3Name) + t3Id := testClientHelper().Ids.RandomSchemaObjectIdentifier() request = sdk.NewCreateTaskRequest(t3Id, sql).WithAfter([]sdk.SchemaObjectIdentifier{t2Id, t1Id}) t3 := createTaskWithRequest(t, request) @@ -271,24 +264,21 @@ func TestInt_Tasks(t *testing.T) { }) t.Run("create dag of tasks - multiple roots", func(t *testing.T) { - root1Name := random.String() - root1Id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, root1Name) + root1Id := testClientHelper().Ids.RandomSchemaObjectIdentifier() request := sdk.NewCreateTaskRequest(root1Id, sql).WithSchedule(sdk.String("10 MINUTE")) root1 := createTaskWithRequest(t, request) require.Empty(t, root1.Predecessors) - root2Name := random.String() - root2Id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, root2Name) + root2Id := testClientHelper().Ids.RandomSchemaObjectIdentifier() request = sdk.NewCreateTaskRequest(root2Id, sql).WithSchedule(sdk.String("10 MINUTE")) root2 := createTaskWithRequest(t, request) require.Empty(t, root2.Predecessors) - t1Name := random.String() - t1Id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, t1Name) + t1Id := testClientHelper().Ids.RandomSchemaObjectIdentifier() request = sdk.NewCreateTaskRequest(t1Id, sql).WithAfter([]sdk.SchemaObjectIdentifier{root1Id, root2Id}) t1 := createTaskWithRequest(t, request) @@ -350,8 +340,7 @@ func TestInt_Tasks(t *testing.T) { t.Run("clone task: default", func(t *testing.T) { sourceTask := createTask(t) - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() request := sdk.NewCloneTaskRequest(id, sourceTask.ID()) @@ -595,10 +584,10 @@ func TestInt_Tasks(t *testing.T) { }) t.Run("temporarily suspend root tasks", func(t *testing.T) { - rootTaskId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + rootTaskId := testClientHelper().Ids.RandomSchemaObjectIdentifier() rootTask := createTaskWithRequest(t, sdk.NewCreateTaskRequest(rootTaskId, sql).WithSchedule(sdk.String("60 minutes"))) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() task := createTaskWithRequest(t, sdk.NewCreateTaskRequest(id, sql).WithAfter([]sdk.SchemaObjectIdentifier{rootTask.ID()})) require.NoError(t, client.Tasks.Alter(ctx, sdk.NewAlterTaskRequest(rootTask.ID()).WithResume(sdk.Bool(true)))) @@ -622,13 +611,13 @@ func TestInt_Tasks(t *testing.T) { }) t.Run("resume root tasks within a graph containing more than one root task", func(t *testing.T) { - rootTaskId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + rootTaskId := testClientHelper().Ids.RandomSchemaObjectIdentifier() rootTask := createTaskWithRequest(t, sdk.NewCreateTaskRequest(rootTaskId, sql).WithSchedule(sdk.String("60 minutes"))) - secondRootTaskId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + secondRootTaskId := testClientHelper().Ids.RandomSchemaObjectIdentifier() secondRootTask := createTaskWithRequest(t, sdk.NewCreateTaskRequest(secondRootTaskId, sql).WithSchedule(sdk.String("60 minutes"))) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() _ = createTaskWithRequest(t, sdk.NewCreateTaskRequest(id, sql).WithAfter([]sdk.SchemaObjectIdentifier{rootTask.ID(), secondRootTask.ID()})) require.ErrorContains(t, client.Tasks.Alter(ctx, sdk.NewAlterTaskRequest(rootTask.ID()).WithResume(sdk.Bool(true))), "The graph has more than one root task (one without predecessors)") @@ -636,13 +625,13 @@ func TestInt_Tasks(t *testing.T) { }) t.Run("suspend root tasks temporarily with three sequentially connected tasks - last in DAG", func(t *testing.T) { - rootTaskId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + rootTaskId := testClientHelper().Ids.RandomSchemaObjectIdentifier() rootTask := createTaskWithRequest(t, sdk.NewCreateTaskRequest(rootTaskId, sql).WithSchedule(sdk.String("60 minutes"))) - middleTaskId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + middleTaskId := testClientHelper().Ids.RandomSchemaObjectIdentifier() middleTask := createTaskWithRequest(t, sdk.NewCreateTaskRequest(middleTaskId, sql).WithAfter([]sdk.SchemaObjectIdentifier{rootTask.ID()})) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() task := createTaskWithRequest(t, sdk.NewCreateTaskRequest(id, sql).WithAfter([]sdk.SchemaObjectIdentifier{middleTask.ID()})) require.NoError(t, client.Tasks.Alter(ctx, sdk.NewAlterTaskRequest(middleTask.ID()).WithResume(sdk.Bool(true)))) @@ -680,13 +669,13 @@ func TestInt_Tasks(t *testing.T) { }) t.Run("suspend root tasks temporarily with three sequentially connected tasks - middle in DAG", func(t *testing.T) { - rootTaskId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + rootTaskId := testClientHelper().Ids.RandomSchemaObjectIdentifier() rootTask := createTaskWithRequest(t, sdk.NewCreateTaskRequest(rootTaskId, sql).WithSchedule(sdk.String("60 minutes"))) - middleTaskId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + middleTaskId := testClientHelper().Ids.RandomSchemaObjectIdentifier() middleTask := createTaskWithRequest(t, sdk.NewCreateTaskRequest(middleTaskId, sql).WithAfter([]sdk.SchemaObjectIdentifier{rootTask.ID()})) - childTaskId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) + childTaskId := testClientHelper().Ids.RandomSchemaObjectIdentifier() childTask := createTaskWithRequest(t, sdk.NewCreateTaskRequest(childTaskId, sql).WithAfter([]sdk.SchemaObjectIdentifier{middleTask.ID()})) require.NoError(t, client.Tasks.Alter(ctx, sdk.NewAlterTaskRequest(childTask.ID()).WithResume(sdk.Bool(true)))) @@ -730,8 +719,6 @@ func TestInt_TasksShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupTaskHandle := func(id sdk.SchemaObjectIdentifier) func() { return func() { err := client.Tasks.Drop(ctx, sdk.NewDropTaskRequest(id)) @@ -754,9 +741,8 @@ func TestInt_TasksShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createTaskHandle(t, id1) createTaskHandle(t, id2) diff --git a/pkg/sdk/testint/users_integration_test.go b/pkg/sdk/testint/users_integration_test.go index dcebb58d8c..291380d64e 100644 --- a/pkg/sdk/testint/users_integration_test.go +++ b/pkg/sdk/testint/users_integration_test.go @@ -14,10 +14,12 @@ func TestInt_UsersShow(t *testing.T) { client := testClient(t) ctx := testContext(t) - userTest, userCleanup := testClientHelper().User.CreateUserWithName(t, "USER_FOO") + randomPrefix := random.AlphaN(6) + + userTest, userCleanup := testClientHelper().User.CreateUserWithPrefix(t, randomPrefix+"_") t.Cleanup(userCleanup) - userTest2, user2Cleanup := testClientHelper().User.CreateUserWithName(t, "USER_BAR") + userTest2, user2Cleanup := testClientHelper().User.CreateUserWithPrefix(t, randomPrefix) t.Cleanup(user2Cleanup) t.Run("with like options", func(t *testing.T) { @@ -34,7 +36,7 @@ func TestInt_UsersShow(t *testing.T) { t.Run("with starts with options", func(t *testing.T) { showOptions := &sdk.ShowUserOptions{ - StartsWith: sdk.String("USER"), + StartsWith: sdk.String(randomPrefix), } users, err := client.Users.Show(ctx, showOptions) require.NoError(t, err) @@ -42,11 +44,12 @@ func TestInt_UsersShow(t *testing.T) { assert.Contains(t, users, *userTest2) assert.Equal(t, 2, len(users)) }) + t.Run("with starts with, limit and from options", func(t *testing.T) { showOptions := &sdk.ShowUserOptions{ Limit: sdk.Int(10), - From: sdk.String("USER_C"), - StartsWith: sdk.String("USER"), + From: sdk.String(randomPrefix + "_"), + StartsWith: sdk.String(randomPrefix), } users, err := client.Users.Show(ctx, showOptions) @@ -92,7 +95,7 @@ func TestInt_UserCreate(t *testing.T) { Value: tagValue, }, } - password := random.String() + password := random.Password() loginName := random.String() opts := &sdk.CreateUserOptions{ @@ -138,7 +141,7 @@ func TestInt_UserCreate(t *testing.T) { Value: tagValue, }, } - password := random.String() + password := random.Password() loginName := random.String() opts := &sdk.CreateUserOptions{ diff --git a/pkg/sdk/testint/views_gen_integration_test.go b/pkg/sdk/testint/views_gen_integration_test.go index 05170da964..f21c836cd0 100644 --- a/pkg/sdk/testint/views_gen_integration_test.go +++ b/pkg/sdk/testint/views_gen_integration_test.go @@ -5,7 +5,6 @@ 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/stretchr/testify/assert" @@ -91,8 +90,7 @@ func TestInt_Views(t *testing.T) { createViewBasicRequest := func(t *testing.T) *sdk.CreateViewRequest { t.Helper() - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() return sdk.NewCreateViewRequest(id, sql) } @@ -126,8 +124,7 @@ func TestInt_Views(t *testing.T) { // source https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2085 t.Run("create view: no table reference", func(t *testing.T) { - name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := testClientHelper().Ids.RandomSchemaObjectIdentifier() request := sdk.NewCreateViewRequest(id, "SELECT NULL AS TYPE") view := createViewWithRequest(t, request) @@ -199,8 +196,7 @@ func TestInt_Views(t *testing.T) { err := client.Views.Create(ctx, createRequest) require.NoError(t, err) - newName := random.String() - newId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, newName) + newId := testClientHelper().Ids.RandomSchemaObjectIdentifier() alterRequest := sdk.NewAlterViewRequest(id).WithRenameTo(&newId) err = client.Views.Alter(ctx, alterRequest) @@ -492,13 +488,12 @@ func TestInt_Views(t *testing.T) { // proves issue https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2506 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 := testClientHelper().Schema.CreateSchemaWithName(t, schemaName) + schemaId := testClientHelper().Ids.RandomDatabaseObjectIdentifierWithPrefix("aaaa") + schema, schemaCleanup := testClientHelper().Schema.CreateSchemaWithIdentifier(t, schemaId) t.Cleanup(schemaCleanup) - name := random.String() - id1 := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) - id2 := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) request1 := sdk.NewCreateViewRequest(id1, sql) request2 := sdk.NewCreateViewRequest(id2, sql) @@ -536,7 +531,6 @@ func TestInt_ViewsShowByID(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) table, tableCleanup := testClientHelper().Table.CreateTable(t) t.Cleanup(tableCleanup) @@ -564,9 +558,8 @@ func TestInt_ViewsShowByID(t *testing.T) { schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) t.Cleanup(schemaCleanup) - name := random.AlphaN(4) - id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - id2 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schema.Name, name) + id1 := testClientHelper().Ids.RandomSchemaObjectIdentifier() + id2 := testClientHelper().Ids.NewSchemaObjectIdentifierInSchema(id1.Name(), schema.ID()) createViewHandle(t, id1) createViewHandle(t, id2) diff --git a/pkg/sdk/users_test.go b/pkg/sdk/users_test.go index 75900b639c..dbc1659fd7 100644 --- a/pkg/sdk/users_test.go +++ b/pkg/sdk/users_test.go @@ -21,7 +21,7 @@ func TestUserCreate(t *testing.T) { Value: "v1", }, } - password := random.String() + password := random.Password() loginName := random.String() opts := &CreateUserOptions{ @@ -92,7 +92,7 @@ func TestUserAlter(t *testing.T) { }) t.Run("with setting properties and parameters", func(t *testing.T) { - password := random.String() + password := random.Password() objectProperties := UserObjectProperties{ Password: &password, DefaultSeconaryRoles: &SecondaryRoles{Roles: []SecondaryRole{{Value: "ALL"}}}, @@ -148,7 +148,7 @@ func TestUserAlter(t *testing.T) { }) t.Run("rename", func(t *testing.T) { - newID := NewAccountObjectIdentifier(random.String()) + newID := randomAccountObjectIdentifier() opts := &AlterUserOptions{ name: id, NewName: newID, diff --git a/pkg/sdk/validations_test.go b/pkg/sdk/validations_test.go index 6bd3a20f64..5ed4d4044c 100644 --- a/pkg/sdk/validations_test.go +++ b/pkg/sdk/validations_test.go @@ -3,7 +3,6 @@ package sdk import ( "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/stretchr/testify/assert" ) @@ -43,12 +42,12 @@ func TestValidObjectIdentifier(t *testing.T) { }) t.Run("over 255 characters", func(t *testing.T) { - ok := ValidObjectIdentifier(NewAccountObjectIdentifier(random.StringN(256))) + ok := ValidObjectIdentifier(invalidAccountObjectIdentifier) assert.Equal(t, ok, false) }) t.Run("with 255 charcters in each of db, schema and name", func(t *testing.T) { - ok := ValidObjectIdentifier(NewSchemaObjectIdentifier(random.StringN(255), random.StringN(255), random.StringN(255))) + ok := ValidObjectIdentifier(invalidSchemaObjectIdentifier) assert.Equal(t, ok, true) }) } diff --git a/v1-preparations/ESSENTIAL_GA_OBJECTS.MD b/v1-preparations/ESSENTIAL_GA_OBJECTS.MD index 68d9f51c69..c40eabcb0d 100644 --- a/v1-preparations/ESSENTIAL_GA_OBJECTS.MD +++ b/v1-preparations/ESSENTIAL_GA_OBJECTS.MD @@ -25,7 +25,7 @@ newer provider versions. We will address these while working on the given object | MASKING POLICY | ❌ | [#2236](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2236), [#2035](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2035), [#1799](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1799), [#1764](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1764), [#1656](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1656), [#1444](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1444), [#1422](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1422), [#1097](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1097) | | PROCEDURE | ❌ | [#2735](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2735), [#2623](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2623), [#2257](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2257), [#2146](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2146), [#1855](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1855), [#1695](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1695), [#1640](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1640), [#1195](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1195), [#1189](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1189), [#1178](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1178), [#1050](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1050) | | ROW ACCESS POLICY | ❌ | [#2053](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2053), [#1600](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1600), [#1151](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1151) | -| SCHEMA | ❌ | [#2211](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2211), [#1243](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1243), [#506](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/506) | +| SCHEMA | ❌ | [#2826](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2826), [#2211](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2211), [#1243](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1243), [#506](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/506) | | STAGE | ❌ | [#2818](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2818), [#2505](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2505), [#1911](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1911), [#1903](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1903), [#1795](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1795), [#1705](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1705), [#1544](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1544), [#1491](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1491), [#1087](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1087), [#265](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/265) | | STREAM | ❌ | [#2413](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2413), [#2201](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2201), [#1150](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1150) | | STREAMLIT | ❌ | [#1933](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/1933) |