From 1f165bf72e29d1a9135d2e5e8bf3f46a0ffdddb6 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Thu, 25 Apr 2024 09:37:01 +0200 Subject: [PATCH] chore: Cleanup helpers part 5 (#2744) Next batch of helper methods refactor: - if exists added to multiple SDK objects (including application package from the previous change) - if exists added to some resources in delete - some helpers were simplified - some tests were simplified (e.g. usage of the default schema) - helper methods for default ids introduced in test client - missing cleanups added - helpers: - pipe - tag - password policy - network policy - resource monitor - masking policy - alert - failover group - file format --- .../provider/resource_monitor_resource.go | 2 +- pkg/acceptance/helpers/alert_client.go | 58 ++++ .../helpers/application_package_client.go | 6 +- pkg/acceptance/helpers/database_client.go | 4 +- .../helpers/database_role_client.go | 4 +- .../helpers/dynamic_table_client.go | 2 +- .../helpers/failover_group_client.go | 58 ++++ pkg/acceptance/helpers/file_format_client.go | 56 ++++ .../helpers/masking_policy_client.go | 85 +++++ .../helpers/network_policy_client.go | 51 +++ .../helpers/password_policy_client.go | 65 ++++ pkg/acceptance/helpers/pipe_client.go | 54 ++++ .../helpers/resource_monitor_client.go | 71 ++++ pkg/acceptance/helpers/schema_client.go | 6 +- .../helpers/session_policy_client.go | 2 +- pkg/acceptance/helpers/stage_client.go | 4 +- pkg/acceptance/helpers/table_client.go | 2 +- pkg/acceptance/helpers/tag_client.go | 54 ++++ pkg/acceptance/helpers/test_client.go | 34 ++ pkg/acceptance/helpers/warehouse_client.go | 4 +- pkg/resources/alert.go | 2 +- pkg/resources/masking_policy.go | 2 +- pkg/resources/pipe.go | 2 +- pkg/resources/resource_monitor.go | 2 +- pkg/sdk/alerts.go | 23 +- pkg/sdk/alerts_test.go | 12 +- .../application_packages_dto_builders_gen.go | 5 + pkg/sdk/application_packages_dto_gen.go | 3 +- pkg/sdk/application_packages_gen.go | 1 + pkg/sdk/application_packages_impl_gen.go | 3 +- pkg/sdk/masking_policy.go | 11 +- pkg/sdk/masking_policy_test.go | 8 + pkg/sdk/pipes.go | 2 +- pkg/sdk/pipes_impl.go | 7 +- pkg/sdk/resource_monitors.go | 18 +- pkg/sdk/resource_monitors_test.go | 12 +- pkg/sdk/sweepers.go | 2 +- pkg/sdk/testint/accounts_integration_test.go | 8 +- pkg/sdk/testint/alerts_integration_test.go | 20 +- .../api_integrations_gen_integration_test.go | 2 +- .../application_packages_integration_test.go | 3 +- .../testint/applications_integration_test.go | 3 +- pkg/sdk/testint/databases_integration_test.go | 4 +- .../testint/event_tables_integration_test.go | 2 +- .../external_tables_integration_test.go | 6 +- .../failover_groups_integration_test.go | 41 ++- .../testint/file_format_integration_test.go | 18 +- pkg/sdk/testint/functions_integration_test.go | 2 +- pkg/sdk/testint/grants_integration_test.go | 44 ++- pkg/sdk/testint/helpers_test.go | 304 ------------------ .../masking_policy_integration_test.go | 25 +- ...materialized_views_gen_integration_test.go | 4 +- .../network_policies_gen_integration_test.go | 67 ++-- ...ation_integrations_gen_integration_test.go | 2 +- .../password_policy_integration_test.go | 20 +- pkg/sdk/testint/pipes_integration_test.go | 28 +- .../policy_references_integration_test.go | 4 +- .../testint/procedures_integration_test.go | 2 +- .../resource_monitors_integration_test.go | 29 +- pkg/sdk/testint/roles_integration_test.go | 6 +- ...ow_access_policies_gen_integration_test.go | 2 +- pkg/sdk/testint/schemas_integration_test.go | 2 +- .../session_policies_gen_integration_test.go | 2 +- pkg/sdk/testint/shares_integration_test.go | 4 +- .../testint/stages_gen_integration_test.go | 2 +- ...torage_integration_gen_integration_test.go | 2 +- .../testint/streams_gen_integration_test.go | 2 +- .../system_functions_integration_test.go | 10 +- pkg/sdk/testint/tables_integration_test.go | 38 +-- pkg/sdk/testint/tags_integration_test.go | 2 +- pkg/sdk/testint/tasks_gen_integration_test.go | 4 +- pkg/sdk/testint/users_integration_test.go | 2 +- pkg/sdk/testint/views_gen_integration_test.go | 8 +- .../testint/warehouses_integration_test.go | 8 +- 74 files changed, 870 insertions(+), 599 deletions(-) create mode 100644 pkg/acceptance/helpers/alert_client.go create mode 100644 pkg/acceptance/helpers/failover_group_client.go create mode 100644 pkg/acceptance/helpers/file_format_client.go create mode 100644 pkg/acceptance/helpers/masking_policy_client.go create mode 100644 pkg/acceptance/helpers/network_policy_client.go create mode 100644 pkg/acceptance/helpers/password_policy_client.go create mode 100644 pkg/acceptance/helpers/pipe_client.go create mode 100644 pkg/acceptance/helpers/resource_monitor_client.go create mode 100644 pkg/acceptance/helpers/tag_client.go diff --git a/framework/provider/resource_monitor_resource.go b/framework/provider/resource_monitor_resource.go index 588c509e19..a1a7d97fa6 100644 --- a/framework/provider/resource_monitor_resource.go +++ b/framework/provider/resource_monitor_resource.go @@ -791,7 +791,7 @@ func (r *ResourceMonitorResource) delete(ctx context.Context, data *resourceMoni diags := diag.Diagnostics{} id := sdk.NewAccountObjectIdentifierFromFullyQualifiedName(data.Id.ValueString()) - err := client.ResourceMonitors.Drop(ctx, id) + err := client.ResourceMonitors.Drop(ctx, id, &sdk.DropResourceMonitorOptions{IfExists: sdk.Bool(true)}) if dryRun { return data, client.TraceLogs(), diags } diff --git a/pkg/acceptance/helpers/alert_client.go b/pkg/acceptance/helpers/alert_client.go new file mode 100644 index 0000000000..c42e42d3b5 --- /dev/null +++ b/pkg/acceptance/helpers/alert_client.go @@ -0,0 +1,58 @@ +package helpers + +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" +) + +type AlertClient struct { + context *TestClientContext +} + +func NewAlertClient(context *TestClientContext) *AlertClient { + return &AlertClient{ + context: context, + } +} + +func (c *AlertClient) client() sdk.Alerts { + return c.context.client.Alerts +} + +func (c *AlertClient) CreateAlert(t *testing.T) (*sdk.Alert, func()) { + t.Helper() + schedule := "USING CRON * * * * * UTC" + condition := "SELECT 1" + action := "SELECT 1" + return c.CreateAlertWithOptions(t, schedule, condition, action, &sdk.CreateAlertOptions{}) +} + +func (c *AlertClient) CreateAlertWithOptions(t *testing.T, schedule string, condition string, action string, opts *sdk.CreateAlertOptions) (*sdk.Alert, func()) { + t.Helper() + ctx := context.Background() + + name := random.String() + id := c.context.newSchemaObjectIdentifier(name) + + err := c.client().Create(ctx, id, c.context.warehouseId(), schedule, condition, action, opts) + require.NoError(t, err) + + alert, err := c.client().ShowByID(ctx, id) + require.NoError(t, err) + + return alert, c.DropAlertFunc(t, id) +} + +func (c *AlertClient) DropAlertFunc(t *testing.T, id sdk.SchemaObjectIdentifier) func() { + t.Helper() + ctx := context.Background() + + return func() { + err := c.client().Drop(ctx, id, &sdk.DropAlertOptions{IfExists: sdk.Bool(true)}) + require.NoError(t, err) + } +} diff --git a/pkg/acceptance/helpers/application_package_client.go b/pkg/acceptance/helpers/application_package_client.go index 7db8219c07..f5970a53cd 100644 --- a/pkg/acceptance/helpers/application_package_client.go +++ b/pkg/acceptance/helpers/application_package_client.go @@ -6,7 +6,6 @@ import ( "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" ) @@ -43,9 +42,8 @@ func (c *ApplicationPackageClient) DropApplicationPackageFunc(t *testing.T, id s ctx := context.Background() return func() { - // no if exists supported based on the docs https://docs.snowflake.com/en/sql-reference/sql/drop-application-package#syntax - err := c.client().Drop(ctx, sdk.NewDropApplicationPackageRequest(id)) - assert.NoError(t, err) + err := c.client().Drop(ctx, sdk.NewDropApplicationPackageRequest(id).WithIfExists(sdk.Bool(true))) + require.NoError(t, err) } } diff --git a/pkg/acceptance/helpers/database_client.go b/pkg/acceptance/helpers/database_client.go index 6f1dbe9a65..4f56f70c90 100644 --- a/pkg/acceptance/helpers/database_client.go +++ b/pkg/acceptance/helpers/database_client.go @@ -50,7 +50,7 @@ func (c *DatabaseClient) DropDatabaseFunc(t *testing.T, id sdk.AccountObjectIden return func() { err := c.client().Drop(ctx, id, &sdk.DropDatabaseOptions{IfExists: sdk.Bool(true)}) require.NoError(t, err) - err = c.context.client.Sessions.UseSchema(ctx, sdk.NewDatabaseObjectIdentifier(c.context.database, c.context.schema)) + err = c.context.client.Sessions.UseSchema(ctx, c.context.schemaId()) require.NoError(t, err) } } @@ -79,7 +79,7 @@ func (c *DatabaseClient) CreateSecondaryDatabaseWithOptions(t *testing.T, id sdk // TODO [926148]: make this wait better with tests stabilization // waiting because sometimes dropping primary db right after dropping the secondary resulted in error time.Sleep(1 * time.Second) - err = c.context.client.Sessions.UseSchema(ctx, sdk.NewDatabaseObjectIdentifier(c.context.database, c.context.schema)) + err = c.context.client.Sessions.UseSchema(ctx, c.context.schemaId()) require.NoError(t, err) } } diff --git a/pkg/acceptance/helpers/database_role_client.go b/pkg/acceptance/helpers/database_role_client.go index 1953507a09..f3d5edc617 100644 --- a/pkg/acceptance/helpers/database_role_client.go +++ b/pkg/acceptance/helpers/database_role_client.go @@ -26,7 +26,7 @@ func (c *DatabaseRoleClient) client() sdk.DatabaseRoles { func (c *DatabaseRoleClient) CreateDatabaseRole(t *testing.T) (*sdk.DatabaseRole, func()) { t.Helper() - return c.CreateDatabaseRoleInDatabase(t, sdk.NewAccountObjectIdentifier(c.context.database)) + return c.CreateDatabaseRoleInDatabase(t, c.context.databaseId()) } func (c *DatabaseRoleClient) CreateDatabaseRoleInDatabase(t *testing.T, databaseId sdk.AccountObjectIdentifier) (*sdk.DatabaseRole, func()) { @@ -36,7 +36,7 @@ func (c *DatabaseRoleClient) CreateDatabaseRoleInDatabase(t *testing.T, database func (c *DatabaseRoleClient) CreateDatabaseRoleWithName(t *testing.T, name string) (*sdk.DatabaseRole, func()) { t.Helper() - return c.CreateDatabaseRoleInDatabaseWithName(t, sdk.NewAccountObjectIdentifier(c.context.database), name) + return c.CreateDatabaseRoleInDatabaseWithName(t, c.context.databaseId(), name) } func (c *DatabaseRoleClient) CreateDatabaseRoleInDatabaseWithName(t *testing.T, databaseId sdk.AccountObjectIdentifier, name string) (*sdk.DatabaseRole, func()) { diff --git a/pkg/acceptance/helpers/dynamic_table_client.go b/pkg/acceptance/helpers/dynamic_table_client.go index 12509c3de4..6286d24ae8 100644 --- a/pkg/acceptance/helpers/dynamic_table_client.go +++ b/pkg/acceptance/helpers/dynamic_table_client.go @@ -26,7 +26,7 @@ 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, sdk.NewDatabaseObjectIdentifier(c.context.database, c.context.schema), random.AlphaN(12), sdk.NewAccountObjectIdentifier(c.context.warehouse), tableId) + return c.CreateDynamicTableWithOptions(t, c.context.schemaId(), random.AlphaN(12), c.context.warehouseId(), tableId) } func (c *DynamicTableClient) CreateDynamicTableWithOptions(t *testing.T, schemaId sdk.DatabaseObjectIdentifier, name string, warehouseId sdk.AccountObjectIdentifier, tableId sdk.SchemaObjectIdentifier) (*sdk.DynamicTable, func()) { diff --git a/pkg/acceptance/helpers/failover_group_client.go b/pkg/acceptance/helpers/failover_group_client.go new file mode 100644 index 0000000000..b479ffeb36 --- /dev/null +++ b/pkg/acceptance/helpers/failover_group_client.go @@ -0,0 +1,58 @@ +package helpers + +import ( + "context" + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/stretchr/testify/require" +) + +type FailoverGroupClient struct { + context *TestClientContext +} + +func NewFailoverGroupClient(context *TestClientContext) *FailoverGroupClient { + return &FailoverGroupClient{ + context: context, + } +} + +func (c *FailoverGroupClient) client() sdk.FailoverGroups { + return c.context.client.FailoverGroups +} + +func (c *FailoverGroupClient) CreateFailoverGroup(t *testing.T) (*sdk.FailoverGroup, func()) { + t.Helper() + objectTypes := []sdk.PluralObjectType{sdk.PluralObjectTypeRoles} + currentAccount, err := c.context.client.ContextFunctions.CurrentAccount(context.Background()) + require.NoError(t, err) + accountID := sdk.NewAccountIdentifierFromAccountLocator(currentAccount) + allowedAccounts := []sdk.AccountIdentifier{accountID} + return c.CreateFailoverGroupWithOptions(t, objectTypes, allowedAccounts, nil) +} + +func (c *FailoverGroupClient) CreateFailoverGroupWithOptions(t *testing.T, objectTypes []sdk.PluralObjectType, allowedAccounts []sdk.AccountIdentifier, opts *sdk.CreateFailoverGroupOptions) (*sdk.FailoverGroup, func()) { + t.Helper() + ctx := context.Background() + + id := sdk.RandomAlphanumericAccountObjectIdentifier() + + err := c.client().Create(ctx, id, objectTypes, allowedAccounts, opts) + require.NoError(t, err) + + failoverGroup, err := c.client().ShowByID(ctx, id) + require.NoError(t, err) + + return failoverGroup, c.DropFailoverGroupFunc(t, id) +} + +func (c *FailoverGroupClient) DropFailoverGroupFunc(t *testing.T, id sdk.AccountObjectIdentifier) func() { + t.Helper() + ctx := context.Background() + + return func() { + err := c.client().Drop(ctx, id, &sdk.DropFailoverGroupOptions{IfExists: sdk.Bool(true)}) + require.NoError(t, err) + } +} diff --git a/pkg/acceptance/helpers/file_format_client.go b/pkg/acceptance/helpers/file_format_client.go new file mode 100644 index 0000000000..7cc663fd57 --- /dev/null +++ b/pkg/acceptance/helpers/file_format_client.go @@ -0,0 +1,56 @@ +package helpers + +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" +) + +type FileFormatClient struct { + context *TestClientContext +} + +func NewFileFormatClient(context *TestClientContext) *FileFormatClient { + return &FileFormatClient{ + context: context, + } +} + +func (c *FileFormatClient) client() sdk.FileFormats { + return c.context.client.FileFormats +} + +func (c *FileFormatClient) CreateFileFormat(t *testing.T) (*sdk.FileFormat, func()) { + t.Helper() + return c.CreateFileFormatWithOptions(t, &sdk.CreateFileFormatOptions{ + Type: sdk.FileFormatTypeCSV, + }) +} + +func (c *FileFormatClient) CreateFileFormatWithOptions(t *testing.T, opts *sdk.CreateFileFormatOptions) (*sdk.FileFormat, func()) { + t.Helper() + ctx := context.Background() + + id := c.context.newSchemaObjectIdentifier(random.AlphanumericN(12)) + + err := c.client().Create(ctx, id, opts) + require.NoError(t, err) + + fileFormat, err := c.client().ShowByID(ctx, id) + require.NoError(t, err) + + return fileFormat, c.DropFileFormatFunc(t, id) +} + +func (c *FileFormatClient) DropFileFormatFunc(t *testing.T, id sdk.SchemaObjectIdentifier) func() { + t.Helper() + ctx := context.Background() + + return func() { + err := c.client().Drop(ctx, id, &sdk.DropFileFormatOptions{IfExists: sdk.Bool(true)}) + require.NoError(t, err) + } +} diff --git a/pkg/acceptance/helpers/masking_policy_client.go b/pkg/acceptance/helpers/masking_policy_client.go new file mode 100644 index 0000000000..66ac5c25b5 --- /dev/null +++ b/pkg/acceptance/helpers/masking_policy_client.go @@ -0,0 +1,85 @@ +package helpers + +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" +) + +type MaskingPolicyClient struct { + context *TestClientContext +} + +func NewMaskingPolicyClient(context *TestClientContext) *MaskingPolicyClient { + return &MaskingPolicyClient{ + context: context, + } +} + +func (c *MaskingPolicyClient) client() sdk.MaskingPolicies { + return c.context.client.MaskingPolicies +} + +func (c *MaskingPolicyClient) CreateMaskingPolicy(t *testing.T) (*sdk.MaskingPolicy, func()) { + t.Helper() + return c.CreateMaskingPolicyInSchema(t, c.context.schemaId()) +} + +func (c *MaskingPolicyClient) CreateMaskingPolicyInSchema(t *testing.T, schemaId sdk.DatabaseObjectIdentifier) (*sdk.MaskingPolicy, func()) { + t.Helper() + signature := []sdk.TableColumnSignature{ + { + Name: random.String(), + Type: sdk.DataTypeVARCHAR, + }, + { + Name: random.String(), + Type: sdk.DataTypeVARCHAR, + }, + } + expression := "REPLACE('X', 1, 2)" + return c.CreateMaskingPolicyWithOptions(t, schemaId, signature, sdk.DataTypeVARCHAR, expression, &sdk.CreateMaskingPolicyOptions{}) +} + +func (c *MaskingPolicyClient) CreateMaskingPolicyIdentity(t *testing.T, columnType sdk.DataType) (*sdk.MaskingPolicy, func()) { + t.Helper() + name := "a" + signature := []sdk.TableColumnSignature{ + { + Name: name, + Type: columnType, + }, + } + expression := "a" + return c.CreateMaskingPolicyWithOptions(t, c.context.schemaId(), signature, columnType, expression, &sdk.CreateMaskingPolicyOptions{}) +} + +func (c *MaskingPolicyClient) CreateMaskingPolicyWithOptions(t *testing.T, schemaId sdk.DatabaseObjectIdentifier, signature []sdk.TableColumnSignature, returns sdk.DataType, expression string, options *sdk.CreateMaskingPolicyOptions) (*sdk.MaskingPolicy, func()) { + t.Helper() + ctx := context.Background() + + name := random.String() + id := sdk.NewSchemaObjectIdentifier(schemaId.DatabaseName(), schemaId.Name(), name) + + err := c.client().Create(ctx, id, signature, returns, expression, options) + require.NoError(t, err) + + maskingPolicy, err := c.client().ShowByID(ctx, id) + require.NoError(t, err) + + return maskingPolicy, c.DropMaskingPolicyFunc(t, id) +} + +func (c *MaskingPolicyClient) DropMaskingPolicyFunc(t *testing.T, id sdk.SchemaObjectIdentifier) func() { + t.Helper() + ctx := context.Background() + + return func() { + err := c.client().Drop(ctx, id, &sdk.DropMaskingPolicyOptions{IfExists: sdk.Bool(true)}) + assert.NoError(t, err) + } +} diff --git a/pkg/acceptance/helpers/network_policy_client.go b/pkg/acceptance/helpers/network_policy_client.go new file mode 100644 index 0000000000..26082f3524 --- /dev/null +++ b/pkg/acceptance/helpers/network_policy_client.go @@ -0,0 +1,51 @@ +package helpers + +import ( + "context" + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/stretchr/testify/require" +) + +type NetworkPolicyClient struct { + context *TestClientContext +} + +func NewNetworkPolicyClient(context *TestClientContext) *NetworkPolicyClient { + return &NetworkPolicyClient{ + context: context, + } +} + +func (c *NetworkPolicyClient) client() sdk.NetworkPolicies { + return c.context.client.NetworkPolicies +} + +func (c *NetworkPolicyClient) CreateNetworkPolicy(t *testing.T) (*sdk.NetworkPolicy, func()) { + t.Helper() + return c.CreateNetworkPolicyWithRequest(t, sdk.NewCreateNetworkPolicyRequest(sdk.RandomAccountObjectIdentifier())) +} + +func (c *NetworkPolicyClient) CreateNetworkPolicyWithRequest(t *testing.T, request *sdk.CreateNetworkPolicyRequest) (*sdk.NetworkPolicy, func()) { + t.Helper() + ctx := context.Background() + + err := c.client().Create(ctx, request) + require.NoError(t, err) + + networkPolicy, err := c.client().ShowByID(ctx, request.GetName()) + require.NoError(t, err) + + return networkPolicy, c.DropNetworkPolicyFunc(t, request.GetName()) +} + +func (c *NetworkPolicyClient) DropNetworkPolicyFunc(t *testing.T, id sdk.AccountObjectIdentifier) func() { + t.Helper() + ctx := context.Background() + + return func() { + err := c.client().Drop(ctx, sdk.NewDropNetworkPolicyRequest(id).WithIfExists(sdk.Bool(true))) + require.NoError(t, err) + } +} diff --git a/pkg/acceptance/helpers/password_policy_client.go b/pkg/acceptance/helpers/password_policy_client.go new file mode 100644 index 0000000000..a7a0db6d75 --- /dev/null +++ b/pkg/acceptance/helpers/password_policy_client.go @@ -0,0 +1,65 @@ +package helpers + +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" +) + +type PasswordPolicyClient struct { + context *TestClientContext +} + +func NewPasswordPolicyClient(context *TestClientContext) *PasswordPolicyClient { + return &PasswordPolicyClient{ + context: context, + } +} + +func (c *PasswordPolicyClient) client() sdk.PasswordPolicies { + return c.context.client.PasswordPolicies +} + +func (c *PasswordPolicyClient) CreatePasswordPolicy(t *testing.T) (*sdk.PasswordPolicy, func()) { + t.Helper() + return c.CreatePasswordPolicyInSchema(t, c.context.schemaId()) +} + +func (c *PasswordPolicyClient) CreatePasswordPolicyInSchema(t *testing.T, schemaId sdk.DatabaseObjectIdentifier) (*sdk.PasswordPolicy, func()) { + t.Helper() + return c.CreatePasswordPolicyInSchemaWithOptions(t, schemaId, nil) +} + +func (c *PasswordPolicyClient) CreatePasswordPolicyWithOptions(t *testing.T, options *sdk.CreatePasswordPolicyOptions) (*sdk.PasswordPolicy, func()) { + t.Helper() + return c.CreatePasswordPolicyInSchemaWithOptions(t, c.context.schemaId(), options) +} + +func (c *PasswordPolicyClient) CreatePasswordPolicyInSchemaWithOptions(t *testing.T, schemaId sdk.DatabaseObjectIdentifier, options *sdk.CreatePasswordPolicyOptions) (*sdk.PasswordPolicy, func()) { + t.Helper() + ctx := context.Background() + + name := random.AlphanumericN(12) + id := sdk.NewSchemaObjectIdentifier(schemaId.DatabaseName(), schemaId.Name(), name) + + err := c.client().Create(ctx, id, options) + require.NoError(t, err) + + passwordPolicy, err := c.client().ShowByID(ctx, id) + require.NoError(t, err) + + return passwordPolicy, c.DropPasswordPolicyFunc(t, id) +} + +func (c *PasswordPolicyClient) DropPasswordPolicyFunc(t *testing.T, id sdk.SchemaObjectIdentifier) func() { + t.Helper() + ctx := context.Background() + + return func() { + err := c.client().Drop(ctx, id, &sdk.DropPasswordPolicyOptions{IfExists: sdk.Bool(true)}) + require.NoError(t, err) + } +} diff --git a/pkg/acceptance/helpers/pipe_client.go b/pkg/acceptance/helpers/pipe_client.go new file mode 100644 index 0000000000..618e1d715b --- /dev/null +++ b/pkg/acceptance/helpers/pipe_client.go @@ -0,0 +1,54 @@ +package helpers + +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" +) + +type PipeClient struct { + context *TestClientContext +} + +func NewPipeClient(context *TestClientContext) *PipeClient { + return &PipeClient{ + context: context, + } +} + +func (c *PipeClient) client() sdk.Pipes { + return c.context.client.Pipes +} + +func (c *PipeClient) CreatePipe(t *testing.T, copyStatement string) (*sdk.Pipe, func()) { + t.Helper() + return c.CreatePipeInSchema(t, c.context.schemaId(), copyStatement) +} + +func (c *PipeClient) CreatePipeInSchema(t *testing.T, schemaId sdk.DatabaseObjectIdentifier, copyStatement string) (*sdk.Pipe, func()) { + t.Helper() + ctx := context.Background() + + id := sdk.NewSchemaObjectIdentifier(schemaId.DatabaseName(), schemaId.Name(), random.AlphaN(20)) + + err := c.client().Create(ctx, id, copyStatement, &sdk.CreatePipeOptions{}) + require.NoError(t, err) + + pipe, err := c.client().Describe(ctx, id) + require.NoError(t, err) + + return pipe, c.DropPipeFunc(t, id) +} + +func (c *PipeClient) DropPipeFunc(t *testing.T, id sdk.SchemaObjectIdentifier) func() { + t.Helper() + ctx := context.Background() + + return func() { + err := c.client().Drop(ctx, id, &sdk.DropPipeOptions{IfExists: sdk.Bool(true)}) + require.NoError(t, err) + } +} diff --git a/pkg/acceptance/helpers/resource_monitor_client.go b/pkg/acceptance/helpers/resource_monitor_client.go new file mode 100644 index 0000000000..08c1e68548 --- /dev/null +++ b/pkg/acceptance/helpers/resource_monitor_client.go @@ -0,0 +1,71 @@ +package helpers + +import ( + "context" + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/stretchr/testify/require" +) + +type ResourceMonitorClient struct { + context *TestClientContext +} + +func NewResourceMonitorClient(context *TestClientContext) *ResourceMonitorClient { + return &ResourceMonitorClient{ + context: context, + } +} + +func (c *ResourceMonitorClient) client() sdk.ResourceMonitors { + return c.context.client.ResourceMonitors +} + +func (c *ResourceMonitorClient) CreateResourceMonitor(t *testing.T) (*sdk.ResourceMonitor, func()) { + t.Helper() + return c.CreateResourceMonitorWithOptions(t, &sdk.CreateResourceMonitorOptions{ + With: &sdk.ResourceMonitorWith{ + CreditQuota: sdk.Pointer(100), + Triggers: []sdk.TriggerDefinition{ + { + Threshold: 100, + TriggerAction: sdk.TriggerActionSuspend, + }, + { + Threshold: 70, + TriggerAction: sdk.TriggerActionSuspendImmediate, + }, + { + Threshold: 90, + TriggerAction: sdk.TriggerActionNotify, + }, + }, + }, + }) +} + +func (c *ResourceMonitorClient) CreateResourceMonitorWithOptions(t *testing.T, opts *sdk.CreateResourceMonitorOptions) (*sdk.ResourceMonitor, func()) { + t.Helper() + ctx := context.Background() + + id := sdk.RandomAccountObjectIdentifier() + + err := c.client().Create(ctx, id, opts) + require.NoError(t, err) + + resourceMonitor, err := c.client().ShowByID(ctx, id) + require.NoError(t, err) + + return resourceMonitor, c.DropResourceMonitorFunc(t, id) +} + +func (c *ResourceMonitorClient) DropResourceMonitorFunc(t *testing.T, id sdk.AccountObjectIdentifier) func() { + t.Helper() + ctx := context.Background() + + return func() { + err := c.client().Drop(ctx, id, &sdk.DropResourceMonitorOptions{IfExists: sdk.Bool(true)}) + require.NoError(t, err) + } +} diff --git a/pkg/acceptance/helpers/schema_client.go b/pkg/acceptance/helpers/schema_client.go index dd9df1cea1..b44d75defb 100644 --- a/pkg/acceptance/helpers/schema_client.go +++ b/pkg/acceptance/helpers/schema_client.go @@ -25,7 +25,7 @@ func (c *SchemaClient) client() sdk.Schemas { func (c *SchemaClient) CreateSchema(t *testing.T) (*sdk.Schema, func()) { t.Helper() - return c.CreateSchemaInDatabase(t, sdk.NewAccountObjectIdentifier(c.context.database)) + return c.CreateSchemaInDatabase(t, c.context.databaseId()) } func (c *SchemaClient) CreateSchemaInDatabase(t *testing.T, databaseId sdk.AccountObjectIdentifier) (*sdk.Schema, func()) { @@ -35,7 +35,7 @@ func (c *SchemaClient) CreateSchemaInDatabase(t *testing.T, databaseId sdk.Accou func (c *SchemaClient) CreateSchemaWithName(t *testing.T, name string) (*sdk.Schema, func()) { t.Helper() - return c.CreateSchemaInDatabaseWithIdentifier(t, sdk.NewAccountObjectIdentifier(c.context.database), name) + return c.CreateSchemaInDatabaseWithIdentifier(t, c.context.databaseId(), name) } func (c *SchemaClient) CreateSchemaInDatabaseWithIdentifier(t *testing.T, databaseId sdk.AccountObjectIdentifier, name string) (*sdk.Schema, func()) { @@ -56,7 +56,7 @@ func (c *SchemaClient) DropSchemaFunc(t *testing.T, id sdk.DatabaseObjectIdentif return func() { err := c.client().Drop(ctx, id, &sdk.DropSchemaOptions{IfExists: sdk.Bool(true)}) require.NoError(t, err) - err = c.context.client.Sessions.UseSchema(ctx, sdk.NewDatabaseObjectIdentifier(c.context.database, c.context.schema)) + err = c.context.client.Sessions.UseSchema(ctx, c.context.schemaId()) require.NoError(t, err) } } diff --git a/pkg/acceptance/helpers/session_policy_client.go b/pkg/acceptance/helpers/session_policy_client.go index 36949b9809..52bf5a7e54 100644 --- a/pkg/acceptance/helpers/session_policy_client.go +++ b/pkg/acceptance/helpers/session_policy_client.go @@ -25,7 +25,7 @@ func (c *SessionPolicyClient) client() sdk.SessionPolicies { func (c *SessionPolicyClient) CreateSessionPolicy(t *testing.T) (*sdk.SessionPolicy, func()) { t.Helper() - id := sdk.NewSchemaObjectIdentifier(c.context.database, c.context.schema, random.StringN(12)) + id := c.context.newSchemaObjectIdentifier(random.StringN(12)) return c.CreateSessionPolicyWithOptions(t, id, sdk.NewCreateSessionPolicyRequest(id)) } diff --git a/pkg/acceptance/helpers/stage_client.go b/pkg/acceptance/helpers/stage_client.go index 92d9c2bb13..bda41dc200 100644 --- a/pkg/acceptance/helpers/stage_client.go +++ b/pkg/acceptance/helpers/stage_client.go @@ -41,13 +41,13 @@ func (c *StageClient) CreateStageWithURL(t *testing.T, id sdk.SchemaObjectIdenti func (c *StageClient) CreateStageWithDirectory(t *testing.T) (*sdk.Stage, func()) { t.Helper() - id := sdk.NewSchemaObjectIdentifier(c.context.database, c.context.schema, random.AlphaN(8)) + id := c.context.newSchemaObjectIdentifier(random.AlphaN(8)) return c.CreateStageWithRequest(t, sdk.NewCreateInternalStageRequest(id).WithDirectoryTableOptions(sdk.NewInternalDirectoryTableOptionsRequest().WithEnable(sdk.Bool(true)))) } func (c *StageClient) CreateStage(t *testing.T) (*sdk.Stage, func()) { t.Helper() - return c.CreateStageInSchema(t, sdk.NewDatabaseObjectIdentifier(c.context.database, c.context.schema)) + return c.CreateStageInSchema(t, c.context.schemaId()) } func (c *StageClient) CreateStageInSchema(t *testing.T, schemaId sdk.DatabaseObjectIdentifier) (*sdk.Stage, func()) { diff --git a/pkg/acceptance/helpers/table_client.go b/pkg/acceptance/helpers/table_client.go index 13fe0db8f9..6c35953d35 100644 --- a/pkg/acceptance/helpers/table_client.go +++ b/pkg/acceptance/helpers/table_client.go @@ -26,7 +26,7 @@ func (c *TableClient) client() sdk.Tables { func (c *TableClient) CreateTable(t *testing.T) (*sdk.Table, func()) { t.Helper() - return c.CreateTableInSchema(t, sdk.NewDatabaseObjectIdentifier(c.context.database, c.context.schema)) + return c.CreateTableInSchema(t, c.context.schemaId()) } func (c *TableClient) CreateTableInSchema(t *testing.T, schemaId sdk.DatabaseObjectIdentifier) (*sdk.Table, func()) { diff --git a/pkg/acceptance/helpers/tag_client.go b/pkg/acceptance/helpers/tag_client.go new file mode 100644 index 0000000000..b92faa26ef --- /dev/null +++ b/pkg/acceptance/helpers/tag_client.go @@ -0,0 +1,54 @@ +package helpers + +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" +) + +type TagClient struct { + context *TestClientContext +} + +func NewTagClient(context *TestClientContext) *TagClient { + return &TagClient{ + context: context, + } +} + +func (c *TagClient) client() sdk.Tags { + return c.context.client.Tags +} + +func (c *TagClient) CreateTag(t *testing.T) (*sdk.Tag, func()) { + t.Helper() + return c.CreateTagInSchema(t, c.context.schemaId()) +} + +func (c *TagClient) CreateTagInSchema(t *testing.T, schemaId sdk.DatabaseObjectIdentifier) (*sdk.Tag, func()) { + t.Helper() + ctx := context.Background() + + id := sdk.NewSchemaObjectIdentifier(schemaId.DatabaseName(), schemaId.Name(), random.AlphanumericN(12)) + + err := c.client().Create(ctx, sdk.NewCreateTagRequest(id)) + require.NoError(t, err) + + tag, err := c.client().ShowByID(ctx, id) + require.NoError(t, err) + + return tag, c.DropTagFunc(t, id) +} + +func (c *TagClient) DropTagFunc(t *testing.T, id sdk.SchemaObjectIdentifier) func() { + t.Helper() + ctx := context.Background() + + return func() { + err := c.client().Drop(ctx, sdk.NewDropTagRequest(id).WithIfExists(true)) + require.NoError(t, err) + } +} diff --git a/pkg/acceptance/helpers/test_client.go b/pkg/acceptance/helpers/test_client.go index 56c63b768f..77a3b78f74 100644 --- a/pkg/acceptance/helpers/test_client.go +++ b/pkg/acceptance/helpers/test_client.go @@ -5,17 +5,26 @@ import "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" type TestClient struct { context *TestClientContext + Alert *AlertClient Application *ApplicationClient ApplicationPackage *ApplicationPackageClient Context *ContextClient Database *DatabaseClient DatabaseRole *DatabaseRoleClient DynamicTable *DynamicTableClient + FailoverGroup *FailoverGroupClient + FileFormat *FileFormatClient + MaskingPolicy *MaskingPolicyClient + NetworkPolicy *NetworkPolicyClient + PasswordPolicy *PasswordPolicyClient + Pipe *PipeClient + ResourceMonitor *ResourceMonitorClient Role *RoleClient Schema *SchemaClient SessionPolicy *SessionPolicyClient Stage *StageClient Table *TableClient + Tag *TagClient User *UserClient Warehouse *WarehouseClient } @@ -29,16 +38,25 @@ func NewTestClient(c *sdk.Client, database string, schema string, warehouse stri } return &TestClient{ context: context, + Alert: NewAlertClient(context), Application: NewApplicationClient(context), ApplicationPackage: NewApplicationPackageClient(context), Context: NewContextClient(context), Database: NewDatabaseClient(context), DatabaseRole: NewDatabaseRoleClient(context), DynamicTable: NewDynamicTableClient(context), + FailoverGroup: NewFailoverGroupClient(context), + FileFormat: NewFileFormatClient(context), + MaskingPolicy: NewMaskingPolicyClient(context), + NetworkPolicy: NewNetworkPolicyClient(context), + PasswordPolicy: NewPasswordPolicyClient(context), + Pipe: NewPipeClient(context), + ResourceMonitor: NewResourceMonitorClient(context), Role: NewRoleClient(context), Schema: NewSchemaClient(context), SessionPolicy: NewSessionPolicyClient(context), Stage: NewStageClient(context), + Tag: NewTagClient(context), Table: NewTableClient(context), User: NewUserClient(context), Warehouse: NewWarehouseClient(context), @@ -51,3 +69,19 @@ type TestClientContext struct { schema string warehouse string } + +func (c *TestClientContext) databaseId() sdk.AccountObjectIdentifier { + return sdk.NewAccountObjectIdentifier(c.database) +} + +func (c *TestClientContext) schemaId() sdk.DatabaseObjectIdentifier { + return sdk.NewDatabaseObjectIdentifier(c.database, c.schema) +} + +func (c *TestClientContext) warehouseId() sdk.AccountObjectIdentifier { + return sdk.NewAccountObjectIdentifier(c.warehouse) +} + +func (c *TestClientContext) newSchemaObjectIdentifier(name string) sdk.SchemaObjectIdentifier { + return sdk.NewSchemaObjectIdentifier(c.database, c.schema, name) +} diff --git a/pkg/acceptance/helpers/warehouse_client.go b/pkg/acceptance/helpers/warehouse_client.go index 9065f3e5b9..0c1ab55ae2 100644 --- a/pkg/acceptance/helpers/warehouse_client.go +++ b/pkg/acceptance/helpers/warehouse_client.go @@ -28,7 +28,7 @@ func (c *WarehouseClient) UseWarehouse(t *testing.T, id sdk.AccountObjectIdentif err := c.context.client.Sessions.UseWarehouse(ctx, id) require.NoError(t, err) return func() { - err = c.context.client.Sessions.UseWarehouse(ctx, sdk.NewAccountObjectIdentifier(c.context.warehouse)) + err = c.context.client.Sessions.UseWarehouse(ctx, c.context.warehouseId()) require.NoError(t, err) } } @@ -53,7 +53,7 @@ func (c *WarehouseClient) DropWarehouseFunc(t *testing.T, id sdk.AccountObjectId return func() { err := c.client().Drop(ctx, id, &sdk.DropWarehouseOptions{IfExists: sdk.Bool(true)}) require.NoError(t, err) - err = c.context.client.Sessions.UseWarehouse(ctx, sdk.NewAccountObjectIdentifier(c.context.warehouse)) + err = c.context.client.Sessions.UseWarehouse(ctx, c.context.warehouseId()) require.NoError(t, err) } } diff --git a/pkg/resources/alert.go b/pkg/resources/alert.go index b011c449ff..a248cab6e9 100644 --- a/pkg/resources/alert.go +++ b/pkg/resources/alert.go @@ -356,7 +356,7 @@ func DeleteAlert(d *schema.ResourceData, meta interface{}) error { ctx := context.Background() objectIdentifier := helpers.DecodeSnowflakeID(d.Id()).(sdk.SchemaObjectIdentifier) - err := client.Alerts.Drop(ctx, objectIdentifier) + err := client.Alerts.Drop(ctx, objectIdentifier, &sdk.DropAlertOptions{IfExists: sdk.Bool(true)}) if err != nil { return err } diff --git a/pkg/resources/masking_policy.go b/pkg/resources/masking_policy.go index 825063f182..8206f1b2a0 100644 --- a/pkg/resources/masking_policy.go +++ b/pkg/resources/masking_policy.go @@ -304,7 +304,7 @@ func DeleteMaskingPolicy(d *schema.ResourceData, meta interface{}) error { ctx := context.Background() objectIdentifier := helpers.DecodeSnowflakeID(d.Id()).(sdk.SchemaObjectIdentifier) - err := client.MaskingPolicies.Drop(ctx, objectIdentifier) + err := client.MaskingPolicies.Drop(ctx, objectIdentifier, &sdk.DropMaskingPolicyOptions{IfExists: sdk.Bool(true)}) if err != nil { return err } diff --git a/pkg/resources/pipe.go b/pkg/resources/pipe.go index b11f7e13b1..6d6ddcc446 100644 --- a/pkg/resources/pipe.go +++ b/pkg/resources/pipe.go @@ -263,7 +263,7 @@ func DeletePipe(d *schema.ResourceData, meta interface{}) error { ctx := context.Background() objectIdentifier := helpers.DecodeSnowflakeID(d.Id()).(sdk.SchemaObjectIdentifier) - err := client.Pipes.Drop(ctx, objectIdentifier) + err := client.Pipes.Drop(ctx, objectIdentifier, &sdk.DropPipeOptions{IfExists: sdk.Bool(true)}) if err != nil { return err } diff --git a/pkg/resources/resource_monitor.go b/pkg/resources/resource_monitor.go index 8e33f43710..3376b2e225 100644 --- a/pkg/resources/resource_monitor.go +++ b/pkg/resources/resource_monitor.go @@ -492,7 +492,7 @@ func DeleteResourceMonitor(d *schema.ResourceData, meta interface{}) error { ctx := context.Background() objectIdentifier := helpers.DecodeSnowflakeID(d.Id()).(sdk.AccountObjectIdentifier) - err := client.ResourceMonitors.Drop(ctx, objectIdentifier) + err := client.ResourceMonitors.Drop(ctx, objectIdentifier, &sdk.DropResourceMonitorOptions{IfExists: sdk.Bool(true)}) if err != nil { return err } diff --git a/pkg/sdk/alerts.go b/pkg/sdk/alerts.go index a057df1bf3..35b30dfd8c 100644 --- a/pkg/sdk/alerts.go +++ b/pkg/sdk/alerts.go @@ -13,14 +13,14 @@ var _ Alerts = (*alerts)(nil) var ( _ validatable = new(CreateAlertOptions) _ validatable = new(AlterAlertOptions) - _ validatable = new(dropAlertOptions) + _ validatable = new(DropAlertOptions) _ validatable = new(ShowAlertOptions) ) type Alerts interface { Create(ctx context.Context, id SchemaObjectIdentifier, warehouse AccountObjectIdentifier, schedule string, condition string, action string, opts *CreateAlertOptions) error Alter(ctx context.Context, id SchemaObjectIdentifier, opts *AlterAlertOptions) error - Drop(ctx context.Context, id SchemaObjectIdentifier) error + Drop(ctx context.Context, id SchemaObjectIdentifier, opts *DropAlertOptions) error Show(ctx context.Context, opts *ShowAlertOptions) ([]Alert, error) ShowByID(ctx context.Context, id SchemaObjectIdentifier) (*Alert, error) Describe(ctx context.Context, id SchemaObjectIdentifier) (*AlertDetails, error) @@ -160,13 +160,14 @@ func (v *alerts) Alter(ctx context.Context, id SchemaObjectIdentifier, opts *Alt } // DropAlertOptions is based on https://docs.snowflake.com/en/sql-reference/sql/drop-alert. -type dropAlertOptions struct { - drop bool `ddl:"static" sql:"DROP"` - alert bool `ddl:"static" sql:"ALERT"` - name SchemaObjectIdentifier `ddl:"identifier"` +type DropAlertOptions struct { + drop bool `ddl:"static" sql:"DROP"` + alert bool `ddl:"static" sql:"ALERT"` + IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` + name SchemaObjectIdentifier `ddl:"identifier"` } -func (opts *dropAlertOptions) validate() error { +func (opts *DropAlertOptions) validate() error { if opts == nil { return errors.Join(ErrNilOptions) } @@ -176,11 +177,11 @@ func (opts *dropAlertOptions) validate() error { return nil } -func (v *alerts) Drop(ctx context.Context, id SchemaObjectIdentifier) error { - // alert drop does not support [IF EXISTS] so there are no drop options. - opts := &dropAlertOptions{ - name: id, +func (v *alerts) Drop(ctx context.Context, id SchemaObjectIdentifier, opts *DropAlertOptions) error { + if opts == nil { + return errors.Join(ErrNilOptions) } + opts.name = id if err := opts.validate(); err != nil { return fmt.Errorf("validate alert options: %w", err) } diff --git a/pkg/sdk/alerts_test.go b/pkg/sdk/alerts_test.go index dc87618607..fdd96da244 100644 --- a/pkg/sdk/alerts_test.go +++ b/pkg/sdk/alerts_test.go @@ -118,16 +118,24 @@ func TestAlertDrop(t *testing.T) { id := RandomSchemaObjectIdentifier() t.Run("empty options", func(t *testing.T) { - opts := &dropAlertOptions{} + opts := &DropAlertOptions{} assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) }) t.Run("only name", func(t *testing.T) { - opts := &dropAlertOptions{ + opts := &DropAlertOptions{ name: id, } assertOptsValidAndSQLEquals(t, opts, "DROP ALERT %s", id.FullyQualifiedName()) }) + + t.Run("all options", func(t *testing.T) { + opts := &DropAlertOptions{ + name: id, + IfExists: Bool(true), + } + assertOptsValidAndSQLEquals(t, opts, "DROP ALERT IF EXISTS %s", id.FullyQualifiedName()) + }) } func TestAlertShow(t *testing.T) { diff --git a/pkg/sdk/application_packages_dto_builders_gen.go b/pkg/sdk/application_packages_dto_builders_gen.go index f2bf223034..36cbec358e 100644 --- a/pkg/sdk/application_packages_dto_builders_gen.go +++ b/pkg/sdk/application_packages_dto_builders_gen.go @@ -266,6 +266,11 @@ func NewDropApplicationPackageRequest( return &s } +func (s *DropApplicationPackageRequest) WithIfExists(IfExists *bool) *DropApplicationPackageRequest { + s.IfExists = IfExists + return s +} + func NewShowApplicationPackageRequest() *ShowApplicationPackageRequest { return &ShowApplicationPackageRequest{} } diff --git a/pkg/sdk/application_packages_dto_gen.go b/pkg/sdk/application_packages_dto_gen.go index 46e269097f..b222738ca7 100644 --- a/pkg/sdk/application_packages_dto_gen.go +++ b/pkg/sdk/application_packages_dto_gen.go @@ -91,7 +91,8 @@ type AddPatchForVersionRequest struct { } type DropApplicationPackageRequest struct { - name AccountObjectIdentifier // required + IfExists *bool + name AccountObjectIdentifier // required } type ShowApplicationPackageRequest struct { diff --git a/pkg/sdk/application_packages_gen.go b/pkg/sdk/application_packages_gen.go index f9b8aa59ab..53e2b4323d 100644 --- a/pkg/sdk/application_packages_gen.go +++ b/pkg/sdk/application_packages_gen.go @@ -104,6 +104,7 @@ type AddPatchForVersion struct { type DropApplicationPackageOptions struct { drop bool `ddl:"static" sql:"DROP"` applicationPackage bool `ddl:"static" sql:"APPLICATION PACKAGE"` + IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` name AccountObjectIdentifier `ddl:"identifier"` } diff --git a/pkg/sdk/application_packages_impl_gen.go b/pkg/sdk/application_packages_impl_gen.go index 3add1188c7..21872bf3c5 100644 --- a/pkg/sdk/application_packages_impl_gen.go +++ b/pkg/sdk/application_packages_impl_gen.go @@ -136,7 +136,8 @@ func (r *AlterApplicationPackageRequest) toOpts() *AlterApplicationPackageOption func (r *DropApplicationPackageRequest) toOpts() *DropApplicationPackageOptions { opts := &DropApplicationPackageOptions{ - name: r.name, + name: r.name, + IfExists: r.IfExists, } return opts } diff --git a/pkg/sdk/masking_policy.go b/pkg/sdk/masking_policy.go index 40d7f34656..724af71f4d 100644 --- a/pkg/sdk/masking_policy.go +++ b/pkg/sdk/masking_policy.go @@ -23,7 +23,7 @@ var ( type MaskingPolicies interface { Create(ctx context.Context, id SchemaObjectIdentifier, signature []TableColumnSignature, returns DataType, expression string, opts *CreateMaskingPolicyOptions) error Alter(ctx context.Context, id SchemaObjectIdentifier, opts *AlterMaskingPolicyOptions) error - Drop(ctx context.Context, id SchemaObjectIdentifier) error + Drop(ctx context.Context, id SchemaObjectIdentifier, opts *DropMaskingPolicyOptions) error Show(ctx context.Context, opts *ShowMaskingPolicyOptions) ([]MaskingPolicy, error) ShowByID(ctx context.Context, id SchemaObjectIdentifier) (*MaskingPolicy, error) Describe(ctx context.Context, id SchemaObjectIdentifier) (*MaskingPolicyDetails, error) @@ -173,6 +173,7 @@ func (v *maskingPolicies) Alter(ctx context.Context, id SchemaObjectIdentifier, type DropMaskingPolicyOptions struct { drop bool `ddl:"static" sql:"DROP"` maskingPolicy bool `ddl:"static" sql:"MASKING POLICY"` + IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` name SchemaObjectIdentifier `ddl:"identifier"` } @@ -186,11 +187,11 @@ func (opts *DropMaskingPolicyOptions) validate() error { return nil } -func (v *maskingPolicies) Drop(ctx context.Context, id SchemaObjectIdentifier) error { - // masking policy drop does not support [IF EXISTS] so there are no drop options. - opts := &DropMaskingPolicyOptions{ - name: id, +func (v *maskingPolicies) Drop(ctx context.Context, id SchemaObjectIdentifier, opts *DropMaskingPolicyOptions) error { + if opts == nil { + return errors.Join(ErrNilOptions) } + opts.name = id if err := opts.validate(); err != nil { return fmt.Errorf("validate drop options: %w", err) } diff --git a/pkg/sdk/masking_policy_test.go b/pkg/sdk/masking_policy_test.go index 445e5d38f7..47dfec0a51 100644 --- a/pkg/sdk/masking_policy_test.go +++ b/pkg/sdk/masking_policy_test.go @@ -136,6 +136,14 @@ func TestMaskingPolicyDrop(t *testing.T) { } assertOptsValidAndSQLEquals(t, opts, "DROP MASKING POLICY %s", id.FullyQualifiedName()) }) + + t.Run("all options", func(t *testing.T) { + opts := &DropMaskingPolicyOptions{ + name: id, + IfExists: Bool(true), + } + assertOptsValidAndSQLEquals(t, opts, "DROP MASKING POLICY IF EXISTS %s", id.FullyQualifiedName()) + }) } func TestMaskingPolicyShow(t *testing.T) { diff --git a/pkg/sdk/pipes.go b/pkg/sdk/pipes.go index 6306b3f3db..83bc2f2f13 100644 --- a/pkg/sdk/pipes.go +++ b/pkg/sdk/pipes.go @@ -10,7 +10,7 @@ var _ convertibleRow[Pipe] = new(pipeDBRow) type Pipes interface { Create(ctx context.Context, id SchemaObjectIdentifier, copyStatement string, opts *CreatePipeOptions) error Alter(ctx context.Context, id SchemaObjectIdentifier, opts *AlterPipeOptions) error - Drop(ctx context.Context, id SchemaObjectIdentifier) error + Drop(ctx context.Context, id SchemaObjectIdentifier, opts *DropPipeOptions) error Show(ctx context.Context, opts *ShowPipeOptions) ([]Pipe, error) ShowByID(ctx context.Context, id SchemaObjectIdentifier) (*Pipe, error) Describe(ctx context.Context, id SchemaObjectIdentifier) (*Pipe, error) diff --git a/pkg/sdk/pipes_impl.go b/pkg/sdk/pipes_impl.go index 86bc728d7a..b29c4c20a6 100644 --- a/pkg/sdk/pipes_impl.go +++ b/pkg/sdk/pipes_impl.go @@ -25,10 +25,9 @@ func (v *pipes) Alter(ctx context.Context, id SchemaObjectIdentifier, opts *Alte return validateAndExec(v.client, ctx, opts) } -func (v *pipes) Drop(ctx context.Context, id SchemaObjectIdentifier) error { - opts := &DropPipeOptions{ - name: id, - } +func (v *pipes) Drop(ctx context.Context, id SchemaObjectIdentifier, opts *DropPipeOptions) error { + opts = createIfNil[DropPipeOptions](opts) + opts.name = id return validateAndExec(v.client, ctx, opts) } diff --git a/pkg/sdk/resource_monitors.go b/pkg/sdk/resource_monitors.go index 16098547c8..8dc9f74ce8 100644 --- a/pkg/sdk/resource_monitors.go +++ b/pkg/sdk/resource_monitors.go @@ -12,14 +12,14 @@ import ( var ( _ validatable = new(CreateResourceMonitorOptions) _ validatable = new(AlterResourceMonitorOptions) - _ validatable = new(dropResourceMonitorOptions) + _ validatable = new(DropResourceMonitorOptions) _ validatable = new(ShowResourceMonitorOptions) ) type ResourceMonitors interface { Create(ctx context.Context, id AccountObjectIdentifier, opts *CreateResourceMonitorOptions) error Alter(ctx context.Context, id AccountObjectIdentifier, opts *AlterResourceMonitorOptions) error - Drop(ctx context.Context, id AccountObjectIdentifier) error + Drop(ctx context.Context, id AccountObjectIdentifier, opts *DropResourceMonitorOptions) error Show(ctx context.Context, opts *ShowResourceMonitorOptions) ([]ResourceMonitor, error) ShowByID(ctx context.Context, id AccountObjectIdentifier) (*ResourceMonitor, error) } @@ -339,14 +339,15 @@ type ResourceMonitorSet struct { NotifyUsers *NotifyUsers `ddl:"parameter,equals" sql:"NOTIFY_USERS"` } -// dropResourceMonitorOptions is based on https://docs.snowflake.com/en/sql-reference/sql/drop-resource-monitor. -type dropResourceMonitorOptions struct { +// DropResourceMonitorOptions is based on https://docs.snowflake.com/en/sql-reference/sql/drop-resource-monitor. +type DropResourceMonitorOptions struct { drop bool `ddl:"static" sql:"DROP"` resourceMonitor bool `ddl:"static" sql:"RESOURCE MONITOR"` + IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` name AccountObjectIdentifier `ddl:"identifier"` } -func (opts *dropResourceMonitorOptions) validate() error { +func (opts *DropResourceMonitorOptions) validate() error { if opts == nil { return errors.Join(ErrNilOptions) } @@ -356,10 +357,11 @@ func (opts *dropResourceMonitorOptions) validate() error { return nil } -func (v *resourceMonitors) Drop(ctx context.Context, id AccountObjectIdentifier) error { - opts := &dropResourceMonitorOptions{ - name: id, +func (v *resourceMonitors) Drop(ctx context.Context, id AccountObjectIdentifier, opts *DropResourceMonitorOptions) error { + if opts == nil { + return errors.Join(ErrNilOptions) } + opts.name = id if err := opts.validate(); err != nil { return err } diff --git a/pkg/sdk/resource_monitors_test.go b/pkg/sdk/resource_monitors_test.go index b44d0ec85b..07db80ccd0 100644 --- a/pkg/sdk/resource_monitors_test.go +++ b/pkg/sdk/resource_monitors_test.go @@ -119,16 +119,24 @@ func TestResourceMonitorDrop(t *testing.T) { id := RandomAccountObjectIdentifier() t.Run("empty options", func(t *testing.T) { - opts := &dropResourceMonitorOptions{} + opts := &DropResourceMonitorOptions{} assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) }) t.Run("only name", func(t *testing.T) { - opts := &dropResourceMonitorOptions{ + opts := &DropResourceMonitorOptions{ name: id, } assertOptsValidAndSQLEquals(t, opts, "DROP RESOURCE MONITOR %s", id.FullyQualifiedName()) }) + + t.Run("all options", func(t *testing.T) { + opts := &DropResourceMonitorOptions{ + name: id, + IfExists: Bool(true), + } + assertOptsValidAndSQLEquals(t, opts, "DROP RESOURCE MONITOR IF EXISTS %s", id.FullyQualifiedName()) + }) } func TestResourceMonitorShow(t *testing.T) { diff --git a/pkg/sdk/sweepers.go b/pkg/sdk/sweepers.go index fa7ffae81a..b974c2f55a 100644 --- a/pkg/sdk/sweepers.go +++ b/pkg/sdk/sweepers.go @@ -78,7 +78,7 @@ func getResourceMonitorSweeper(client *Client, suffix string) func() error { for _, rm := range rms { if strings.HasSuffix(rm.Name, suffix) { log.Printf("[DEBUG] Dropping resource monitor %s", rm.ID().FullyQualifiedName()) - if err := client.ResourceMonitors.Drop(ctx, rm.ID()); err != nil { + if err := client.ResourceMonitors.Drop(ctx, rm.ID(), &DropResourceMonitorOptions{IfExists: Bool(true)}); err != nil { return fmt.Errorf("sweeping resource monitor %s ended with error, err = %w", rm.ID().FullyQualifiedName(), err) } } else { diff --git a/pkg/sdk/testint/accounts_integration_test.go b/pkg/sdk/testint/accounts_integration_test.go index e3f49568a6..c3962e8965 100644 --- a/pkg/sdk/testint/accounts_integration_test.go +++ b/pkg/sdk/testint/accounts_integration_test.go @@ -215,7 +215,7 @@ func TestInt_AccountAlter(t *testing.T) { }) t.Run("set resource monitor", func(t *testing.T) { - resourceMonitorTest, resourceMonitorCleanup := createResourceMonitor(t, client) + resourceMonitorTest, resourceMonitorCleanup := testClientHelper().ResourceMonitor.CreateResourceMonitor(t) t.Cleanup(resourceMonitorCleanup) opts := &sdk.AlterAccountOptions{ Set: &sdk.AccountSet{ @@ -227,7 +227,7 @@ func TestInt_AccountAlter(t *testing.T) { }) t.Run("set and unset password policy", func(t *testing.T) { - passwordPolicyTest, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), testSchema(t)) + passwordPolicyTest, passwordPolicyCleanup := testClientHelper().PasswordPolicy.CreatePasswordPolicy(t) t.Cleanup(passwordPolicyCleanup) opts := &sdk.AlterAccountOptions{ Set: &sdk.AccountSet{ @@ -270,9 +270,9 @@ func TestInt_AccountAlter(t *testing.T) { }) t.Run("set and unset tag", func(t *testing.T) { - tagTest1, tagCleanup1 := createTag(t, client, testDb(t), testSchema(t)) + tagTest1, tagCleanup1 := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup1) - tagTest2, tagCleanup2 := createTag(t, client, testDb(t), testSchema(t)) + tagTest2, tagCleanup2 := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup2) opts := &sdk.AlterAccountOptions{ diff --git a/pkg/sdk/testint/alerts_integration_test.go b/pkg/sdk/testint/alerts_integration_test.go index 1735bc5322..b8be2f9bed 100644 --- a/pkg/sdk/testint/alerts_integration_test.go +++ b/pkg/sdk/testint/alerts_integration_test.go @@ -15,10 +15,10 @@ func TestInt_AlertsShow(t *testing.T) { client := testClient(t) ctx := testContext(t) - alertTest, alertCleanup := createAlert(t, client, testDb(t), testSchema(t), testWarehouse(t)) + alertTest, alertCleanup := testClientHelper().Alert.CreateAlert(t) t.Cleanup(alertCleanup) - alert2Test, alert2Cleanup := createAlert(t, client, testDb(t), testSchema(t), testWarehouse(t)) + alert2Test, alert2Cleanup := testClientHelper().Alert.CreateAlert(t) t.Cleanup(alert2Cleanup) t.Run("without show options", func(t *testing.T) { @@ -228,7 +228,7 @@ func TestInt_AlertDescribe(t *testing.T) { client := testClient(t) ctx := testContext(t) - alert, alertCleanup := createAlert(t, client, testDb(t), testSchema(t), testWarehouse(t)) + alert, alertCleanup := testClientHelper().Alert.CreateAlert(t) t.Cleanup(alertCleanup) t.Run("when alert exists", func(t *testing.T) { @@ -249,7 +249,7 @@ func TestInt_AlertAlter(t *testing.T) { ctx := testContext(t) t.Run("when setting and unsetting a value", func(t *testing.T) { - alert, alertCleanup := createAlert(t, client, testDb(t), testSchema(t), testWarehouse(t)) + alert, alertCleanup := testClientHelper().Alert.CreateAlert(t) t.Cleanup(alertCleanup) newSchedule := "USING CRON * * * * TUE,FRI GMT" @@ -275,7 +275,7 @@ func TestInt_AlertAlter(t *testing.T) { }) t.Run("when modifying condition and action", func(t *testing.T) { - alert, alertCleanup := createAlert(t, client, testDb(t), testSchema(t), testWarehouse(t)) + alert, alertCleanup := testClientHelper().Alert.CreateAlert(t) t.Cleanup(alertCleanup) newCondition := "select * from DUAL where false" @@ -319,7 +319,7 @@ func TestInt_AlertAlter(t *testing.T) { }) t.Run("resume and then suspend", func(t *testing.T) { - alert, alertCleanup := createAlert(t, client, testDb(t), testSchema(t), testWarehouse(t)) + alert, alertCleanup := testClientHelper().Alert.CreateAlert(t) t.Cleanup(alertCleanup) alterOptions := &sdk.AlterAlertOptions{ @@ -365,9 +365,9 @@ func TestInt_AlertDrop(t *testing.T) { ctx := testContext(t) t.Run("when alert exists", func(t *testing.T) { - alert, _ := createAlert(t, client, testDb(t), testSchema(t), testWarehouse(t)) + alert, _ := testClientHelper().Alert.CreateAlert(t) id := alert.ID() - err := client.Alerts.Drop(ctx, id) + err := client.Alerts.Drop(ctx, id, &sdk.DropAlertOptions{}) require.NoError(t, err) _, err = client.PasswordPolicies.Describe(ctx, id) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) @@ -375,7 +375,7 @@ func TestInt_AlertDrop(t *testing.T) { t.Run("when alert does not exist", func(t *testing.T) { id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, "does_not_exist") - err := client.Alerts.Drop(ctx, id) + err := client.Alerts.Drop(ctx, id, &sdk.DropAlertOptions{}) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) }) } @@ -388,7 +388,7 @@ func TestInt_AlertsShowByID(t *testing.T) { cleanupAlertHandle := func(t *testing.T, id sdk.SchemaObjectIdentifier) func() { t.Helper() return func() { - err := client.Alerts.Drop(ctx, id) + err := client.Alerts.Drop(ctx, id, &sdk.DropAlertOptions{}) if errors.Is(err, sdk.ErrObjectNotExistOrAuthorized) { return } diff --git a/pkg/sdk/testint/api_integrations_gen_integration_test.go b/pkg/sdk/testint/api_integrations_gen_integration_test.go index 3c38d29848..425ee289c4 100644 --- a/pkg/sdk/testint/api_integrations_gen_integration_test.go +++ b/pkg/sdk/testint/api_integrations_gen_integration_test.go @@ -348,7 +348,7 @@ func TestInt_ApiIntegrations(t *testing.T) { }) t.Run("alter api integration: set and unset tags", func(t *testing.T) { - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) integration := createAwsApiIntegration(t) diff --git a/pkg/sdk/testint/application_packages_integration_test.go b/pkg/sdk/testint/application_packages_integration_test.go index c90f6646be..7e0e4bce12 100644 --- a/pkg/sdk/testint/application_packages_integration_test.go +++ b/pkg/sdk/testint/application_packages_integration_test.go @@ -27,8 +27,7 @@ func TestInt_ApplicationPackages(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - tagTest, tagCleanup := createTag(t, client, databaseTest, schemaTest) + tagTest, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) cleanupApplicationPackageHandle := func(id sdk.AccountObjectIdentifier) func() { diff --git a/pkg/sdk/testint/applications_integration_test.go b/pkg/sdk/testint/applications_integration_test.go index 747d5f4621..5df2216d79 100644 --- a/pkg/sdk/testint/applications_integration_test.go +++ b/pkg/sdk/testint/applications_integration_test.go @@ -22,8 +22,7 @@ func TestInt_Applications(t *testing.T) { client := testClient(t) ctx := testContext(t) - databaseTest, schemaTest := testDb(t), testSchema(t) - tagTest, tagCleanup := createTag(t, client, databaseTest, schemaTest) + tagTest, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) cleanupApplicationHandle := func(id sdk.AccountObjectIdentifier) func() { diff --git a/pkg/sdk/testint/databases_integration_test.go b/pkg/sdk/testint/databases_integration_test.go index b78d48f27d..d8d39a8011 100644 --- a/pkg/sdk/testint/databases_integration_test.go +++ b/pkg/sdk/testint/databases_integration_test.go @@ -58,9 +58,9 @@ func TestInt_DatabasesCreate(t *testing.T) { t.Cleanup(databaseCleanup) schemaTest, schemaCleanup := testClientHelper().Schema.CreateSchemaInDatabase(t, databaseTest.ID()) t.Cleanup(schemaCleanup) - tagTest, tagCleanup := createTag(t, client, databaseTest, schemaTest) + tagTest, tagCleanup := testClientHelper().Tag.CreateTagInSchema(t, schemaTest.ID()) t.Cleanup(tagCleanup) - tag2Test, tag2Cleanup := createTag(t, client, databaseTest, schemaTest) + tag2Test, tag2Cleanup := testClientHelper().Tag.CreateTagInSchema(t, schemaTest.ID()) t.Cleanup(tag2Cleanup) comment := random.Comment() diff --git a/pkg/sdk/testint/event_tables_integration_test.go b/pkg/sdk/testint/event_tables_integration_test.go index 19562a5b4b..74e67f1265 100644 --- a/pkg/sdk/testint/event_tables_integration_test.go +++ b/pkg/sdk/testint/event_tables_integration_test.go @@ -16,7 +16,7 @@ func TestInt_EventTables(t *testing.T) { ctx := context.Background() databaseTest, schemaTest := testDb(t), testSchema(t) - tagTest, tagCleaup := createTag(t, client, databaseTest, schemaTest) + tagTest, tagCleaup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleaup) assertEventTableHandle := func(t *testing.T, et *sdk.EventTable, expectedName string, expectedComment string, _ []string) { diff --git a/pkg/sdk/testint/external_tables_integration_test.go b/pkg/sdk/testint/external_tables_integration_test.go index cf45f05841..da2a1f683b 100644 --- a/pkg/sdk/testint/external_tables_integration_test.go +++ b/pkg/sdk/testint/external_tables_integration_test.go @@ -21,7 +21,8 @@ func TestInt_ExternalTables(t *testing.T) { _, stageCleanup := testClientHelper().Stage.CreateStageWithURL(t, stageID, nycWeatherDataURL) t.Cleanup(stageCleanup) - tag, _ := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) + t.Cleanup(tagCleanup) defaultColumns := func() []*sdk.ExternalTableColumnRequest { return []*sdk.ExternalTableColumnRequest{ @@ -112,7 +113,8 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Create: infer schema", func(t *testing.T) { - fileFormat, _ := createFileFormat(t, client, testSchema(t).ID()) + fileFormat, fileFormatCleanup := testClientHelper().FileFormat.CreateFileFormat(t) + t.Cleanup(fileFormatCleanup) err := client.Sessions.UseWarehouse(ctx, testWarehouse(t).ID()) require.NoError(t, err) diff --git a/pkg/sdk/testint/failover_groups_integration_test.go b/pkg/sdk/testint/failover_groups_integration_test.go index 428c46c8e0..f8a1d89007 100644 --- a/pkg/sdk/testint/failover_groups_integration_test.go +++ b/pkg/sdk/testint/failover_groups_integration_test.go @@ -301,7 +301,8 @@ func TestInt_FailoverGroupsAlterSource(t *testing.T) { client := testClient(t) ctx := testContext(t) t.Run("rename the failover group", func(t *testing.T) { - failoverGroup, _ := createFailoverGroup(t, client) + failoverGroup, failoverGroupCleanup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) + t.Cleanup(failoverGroupCleanup) oldID := failoverGroup.ID() newID := sdk.RandomAccountObjectIdentifier() opts := &sdk.AlterSourceFailoverGroupOptions{ @@ -312,15 +313,11 @@ func TestInt_FailoverGroupsAlterSource(t *testing.T) { failoverGroup, err = client.FailoverGroups.ShowByID(ctx, newID) require.NoError(t, err) assert.Equal(t, newID.Name(), failoverGroup.Name) - cleanupFailoverGroup := func() { - err := client.FailoverGroups.Drop(ctx, newID, nil) - require.NoError(t, err) - } - t.Cleanup(cleanupFailoverGroup) + t.Cleanup(testClientHelper().FailoverGroup.DropFailoverGroupFunc(t, newID)) }) t.Run("reset the list of specified object types enabled for replication and failover.", func(t *testing.T) { - failoverGroup, cleanupFailoverGroup := createFailoverGroup(t, client) + failoverGroup, cleanupFailoverGroup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) t.Cleanup(cleanupFailoverGroup) objectTypes := []sdk.PluralObjectType{ sdk.PluralObjectTypeDatabases, @@ -338,7 +335,7 @@ func TestInt_FailoverGroupsAlterSource(t *testing.T) { }) t.Run("set or update the replication schedule for automatic refresh of secondary failover groups.", func(t *testing.T) { - failoverGroup, cleanupFailoverGroup := createFailoverGroup(t, client) + failoverGroup, cleanupFailoverGroup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) t.Cleanup(cleanupFailoverGroup) replicationSchedule := "USING CRON 0 0 10-20 * TUE,THU UTC" opts := &sdk.AlterSourceFailoverGroupOptions{ @@ -354,7 +351,7 @@ func TestInt_FailoverGroupsAlterSource(t *testing.T) { }) t.Run("add and remove database account object", func(t *testing.T) { - failoverGroup, cleanupFailoverGroup := createFailoverGroup(t, client) + failoverGroup, cleanupFailoverGroup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) t.Cleanup(cleanupFailoverGroup) // first add databases to allowed object types @@ -405,7 +402,7 @@ func TestInt_FailoverGroupsAlterSource(t *testing.T) { t.Run("add and remove share account object", func(t *testing.T) { shareTest, cleanupDatabase := createShare(t, client) t.Cleanup(cleanupDatabase) - failoverGroup, cleanupFailoverGroup := createFailoverGroup(t, client) + failoverGroup, cleanupFailoverGroup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) t.Cleanup(cleanupFailoverGroup) // first add shares to allowed object types @@ -453,7 +450,7 @@ func TestInt_FailoverGroupsAlterSource(t *testing.T) { }) t.Run("add and remove security integration account object", func(t *testing.T) { - failoverGroup, cleanupFailoverGroup := createFailoverGroup(t, client) + failoverGroup, cleanupFailoverGroup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) t.Cleanup(cleanupFailoverGroup) // first add security integrations to allowed object types opts := &sdk.AlterSourceFailoverGroupOptions{ @@ -497,7 +494,7 @@ func TestInt_FailoverGroupsAlterSource(t *testing.T) { }) t.Run("add or remove target accounts enabled for replication and failover", func(t *testing.T) { - failoverGroup, cleanupFailoverGroup := createFailoverGroup(t, client) + failoverGroup, cleanupFailoverGroup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) t.Cleanup(cleanupFailoverGroup) secondaryAccountID := getAccountIdentifier(t, testSecondaryClient(t)) @@ -533,7 +530,7 @@ func TestInt_FailoverGroupsAlterSource(t *testing.T) { }) t.Run("move shares to another failover group", func(t *testing.T) { - failoverGroup, cleanupFailoverGroup := createFailoverGroup(t, client) + failoverGroup, cleanupFailoverGroup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) t.Cleanup(cleanupFailoverGroup) // add "SHARES" to object types of both failover groups @@ -547,7 +544,7 @@ func TestInt_FailoverGroupsAlterSource(t *testing.T) { err := client.FailoverGroups.AlterSource(ctx, failoverGroup.ID(), opts) require.NoError(t, err) - failoverGroup2, cleanupFailoverGroup2 := createFailoverGroup(t, client) + failoverGroup2, cleanupFailoverGroup2 := testClientHelper().FailoverGroup.CreateFailoverGroup(t) t.Cleanup(cleanupFailoverGroup2) err = client.FailoverGroups.AlterSource(ctx, failoverGroup2.ID(), opts) @@ -592,7 +589,7 @@ func TestInt_FailoverGroupsAlterSource(t *testing.T) { }) t.Run("move database to another failover group", func(t *testing.T) { - failoverGroup, cleanupFailoverGroup := createFailoverGroup(t, client) + failoverGroup, cleanupFailoverGroup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) t.Cleanup(cleanupFailoverGroup) // add "DATABASES" to object types of both failover groups @@ -606,7 +603,7 @@ func TestInt_FailoverGroupsAlterSource(t *testing.T) { err := client.FailoverGroups.AlterSource(ctx, failoverGroup.ID(), opts) require.NoError(t, err) - failoverGroup2, cleanupFailoverGroup2 := createFailoverGroup(t, client) + failoverGroup2, cleanupFailoverGroup2 := testClientHelper().FailoverGroup.CreateFailoverGroup(t) t.Cleanup(cleanupFailoverGroup2) err = client.FailoverGroups.AlterSource(ctx, failoverGroup2.ID(), opts) @@ -783,13 +780,15 @@ func TestInt_FailoverGroupsDrop(t *testing.T) { client := testClient(t) ctx := testContext(t) t.Run("no options", func(t *testing.T) { - failoverGroup, _ := createFailoverGroup(t, client) + failoverGroup, failoverGroupCleanup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) + t.Cleanup(failoverGroupCleanup) err := client.FailoverGroups.Drop(ctx, failoverGroup.ID(), nil) require.NoError(t, err) }) t.Run("with IfExists", func(t *testing.T) { - failoverGroup, _ := createFailoverGroup(t, client) + failoverGroup, failoverGroupCleanup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) + t.Cleanup(failoverGroupCleanup) opts := &sdk.DropFailoverGroupOptions{ IfExists: sdk.Bool(true), } @@ -804,7 +803,7 @@ func TestInt_FailoverGroupsShow(t *testing.T) { client := testClient(t) ctx := testContext(t) - failoverGroupTest, failoverGroupCleanup := createFailoverGroup(t, client) + failoverGroupTest, failoverGroupCleanup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) t.Cleanup(failoverGroupCleanup) t.Run("without show options", func(t *testing.T) { @@ -836,7 +835,7 @@ func TestInt_FailoverGroupsShowDatabases(t *testing.T) { client := testClient(t) ctx := testContext(t) - failoverGroupTest, failoverGroupCleanup := createFailoverGroup(t, client) + failoverGroupTest, failoverGroupCleanup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) t.Cleanup(failoverGroupCleanup) opts := &sdk.AlterSourceFailoverGroupOptions{ @@ -869,7 +868,7 @@ func TestInt_FailoverGroupsShowShares(t *testing.T) { client := testClient(t) ctx := testContext(t) - failoverGroupTest, failoverGroupCleanup := createFailoverGroup(t, client) + failoverGroupTest, failoverGroupCleanup := testClientHelper().FailoverGroup.CreateFailoverGroup(t) t.Cleanup(failoverGroupCleanup) shareTest, shareCleanup := createShare(t, client) diff --git a/pkg/sdk/testint/file_format_integration_test.go b/pkg/sdk/testint/file_format_integration_test.go index 2dc2c247c4..0cb08ec7c6 100644 --- a/pkg/sdk/testint/file_format_integration_test.go +++ b/pkg/sdk/testint/file_format_integration_test.go @@ -375,7 +375,7 @@ func TestInt_FileFormatsAlter(t *testing.T) { ctx := testContext(t) t.Run("rename", func(t *testing.T) { - fileFormat, fileFormatCleanup := createFileFormat(t, client, testSchema(t).ID()) + fileFormat, fileFormatCleanup := testClientHelper().FileFormat.CreateFileFormat(t) t.Cleanup(fileFormatCleanup) oldId := fileFormat.ID() newId := sdk.NewSchemaObjectIdentifier(oldId.DatabaseName(), oldId.SchemaName(), random.String()) @@ -404,7 +404,7 @@ func TestInt_FileFormatsAlter(t *testing.T) { }) t.Run("set + set comment", func(t *testing.T) { - fileFormat, fileFormatCleanup := createFileFormatWithOptions(t, client, testSchema(t).ID(), &sdk.CreateFileFormatOptions{ + fileFormat, fileFormatCleanup := testClientHelper().FileFormat.CreateFileFormatWithOptions(t, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeCSV, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ CSVCompression: &sdk.CSVCompressionAuto, @@ -435,7 +435,9 @@ func TestInt_FileFormatsDrop(t *testing.T) { ctx := testContext(t) t.Run("no options", func(t *testing.T) { - fileFormat, _ := createFileFormat(t, client, testSchema(t).ID()) + fileFormat, fileFormatCleanup := testClientHelper().FileFormat.CreateFileFormat(t) + t.Cleanup(fileFormatCleanup) + err := client.FileFormats.Drop(ctx, fileFormat.ID(), nil) require.NoError(t, err) @@ -444,7 +446,9 @@ func TestInt_FileFormatsDrop(t *testing.T) { }) t.Run("with IfExists", func(t *testing.T) { - fileFormat, _ := createFileFormat(t, client, testSchema(t).ID()) + fileFormat, fileFormatCleanup := testClientHelper().FileFormat.CreateFileFormat(t) + t.Cleanup(fileFormatCleanup) + err := client.FileFormats.Drop(ctx, fileFormat.ID(), &sdk.DropFileFormatOptions{ IfExists: sdk.Bool(true), }) @@ -459,9 +463,9 @@ func TestInt_FileFormatsShow(t *testing.T) { client := testClient(t) ctx := testContext(t) - fileFormatTest, cleanupFileFormat := createFileFormat(t, client, testSchema(t).ID()) + fileFormatTest, cleanupFileFormat := testClientHelper().FileFormat.CreateFileFormat(t) t.Cleanup(cleanupFileFormat) - fileFormatTest2, cleanupFileFormat2 := createFileFormat(t, client, testSchema(t).ID()) + fileFormatTest2, cleanupFileFormat2 := testClientHelper().FileFormat.CreateFileFormat(t) t.Cleanup(cleanupFileFormat2) t.Run("without options", func(t *testing.T) { @@ -500,7 +504,7 @@ func TestInt_FileFormatsShowById(t *testing.T) { client := testClient(t) ctx := testContext(t) - fileFormatTest, cleanupFileFormat := createFileFormat(t, client, testSchema(t).ID()) + fileFormatTest, cleanupFileFormat := testClientHelper().FileFormat.CreateFileFormat(t) t.Cleanup(cleanupFileFormat) // new database and schema created on purpose diff --git a/pkg/sdk/testint/functions_integration_test.go b/pkg/sdk/testint/functions_integration_test.go index ea72d19de1..595349d3ca 100644 --- a/pkg/sdk/testint/functions_integration_test.go +++ b/pkg/sdk/testint/functions_integration_test.go @@ -199,7 +199,7 @@ func TestInt_OtherFunctions(t *testing.T) { ctx := testContext(t) databaseTest, schemaTest := testDb(t), testSchema(t) - tagTest, tagCleanup := createTag(t, client, databaseTest, schemaTest) + tagTest, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) assertFunction := func(t *testing.T, id sdk.SchemaObjectIdentifier, secure bool, withArguments bool) { diff --git a/pkg/sdk/testint/grants_integration_test.go b/pkg/sdk/testint/grants_integration_test.go index 1cb0cf0bff..8962ce90d9 100644 --- a/pkg/sdk/testint/grants_integration_test.go +++ b/pkg/sdk/testint/grants_integration_test.go @@ -89,7 +89,7 @@ func TestInt_GrantAndRevokePrivilegesToAccountRole(t *testing.T) { t.Run("on account object", func(t *testing.T) { roleTest, roleCleanup := testClientHelper().Role.CreateRole(t) t.Cleanup(roleCleanup) - resourceMonitorTest, resourceMonitorCleanup := createResourceMonitor(t, client) + resourceMonitorTest, resourceMonitorCleanup := testClientHelper().ResourceMonitor.CreateResourceMonitor(t) t.Cleanup(resourceMonitorCleanup) privileges := &sdk.AccountRoleGrantPrivileges{ AccountObjectPrivileges: []sdk.AccountObjectPrivilege{sdk.AccountObjectPrivilegeMonitor}, @@ -235,8 +235,7 @@ func TestInt_GrantAndRevokePrivilegesToAccountRole(t *testing.T) { }) t.Run("grant and revoke on all pipes", func(t *testing.T) { - schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) - t.Cleanup(schemaCleanup) + schema := testSchema(t) table, tableCleanup := testClientHelper().Table.CreateTableInSchema(t, schema.ID()) t.Cleanup(tableCleanup) @@ -244,10 +243,10 @@ func TestInt_GrantAndRevokePrivilegesToAccountRole(t *testing.T) { stage, stageCleanup := testClientHelper().Stage.CreateStageInSchema(t, sdk.NewDatabaseObjectIdentifier(testDb(t).Name, schema.Name)) t.Cleanup(stageCleanup) - pipe, pipeCleanup := createPipe(t, client, testDb(t), schema, random.AlphaN(20), createPipeCopyStatement(t, table, stage)) + pipe, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, createPipeCopyStatement(t, table, stage)) t.Cleanup(pipeCleanup) - secondPipe, secondPipeCleanup := createPipe(t, client, testDb(t), schema, random.AlphaN(20), createPipeCopyStatement(t, table, stage)) + secondPipe, secondPipeCleanup := testClientHelper().Pipe.CreatePipe(t, createPipeCopyStatement(t, table, stage)) t.Cleanup(secondPipeCleanup) role, roleCleanup := testClientHelper().Role.CreateRole(t) @@ -295,8 +294,7 @@ func TestInt_GrantAndRevokePrivilegesToAccountRole(t *testing.T) { }) t.Run("grant and revoke on all pipes with multiple errors", func(t *testing.T) { - schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) - t.Cleanup(schemaCleanup) + schema := testSchema(t) table, tableCleanup := testClientHelper().Table.CreateTableInSchema(t, schema.ID()) t.Cleanup(tableCleanup) @@ -304,10 +302,10 @@ func TestInt_GrantAndRevokePrivilegesToAccountRole(t *testing.T) { stage, stageCleanup := testClientHelper().Stage.CreateStageInSchema(t, sdk.NewDatabaseObjectIdentifier(testDb(t).Name, schema.Name)) t.Cleanup(stageCleanup) - _, pipeCleanup := createPipe(t, client, testDb(t), schema, random.AlphaN(20), createPipeCopyStatement(t, table, stage)) + _, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, createPipeCopyStatement(t, table, stage)) t.Cleanup(pipeCleanup) - _, secondPipeCleanup := createPipe(t, client, testDb(t), schema, random.AlphaN(20), createPipeCopyStatement(t, table, stage)) + _, secondPipeCleanup := testClientHelper().Pipe.CreatePipe(t, createPipeCopyStatement(t, table, stage)) t.Cleanup(secondPipeCleanup) role, roleCleanup := testClientHelper().Role.CreateRole(t) @@ -588,8 +586,7 @@ func TestInt_GrantAndRevokePrivilegesToDatabaseRole(t *testing.T) { }) t.Run("grant and revoke on all pipes", func(t *testing.T) { - schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) - t.Cleanup(schemaCleanup) + schema := testSchema(t) table, tableCleanup := testClientHelper().Table.CreateTableInSchema(t, schema.ID()) t.Cleanup(tableCleanup) @@ -597,10 +594,10 @@ func TestInt_GrantAndRevokePrivilegesToDatabaseRole(t *testing.T) { stage, stageCleanup := testClientHelper().Stage.CreateStageInSchema(t, sdk.NewDatabaseObjectIdentifier(testDb(t).Name, schema.Name)) t.Cleanup(stageCleanup) - pipe, pipeCleanup := createPipe(t, client, testDb(t), schema, random.StringN(20), createPipeCopyStatement(t, table, stage)) + pipe, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, createPipeCopyStatement(t, table, stage)) t.Cleanup(pipeCleanup) - secondPipe, secondPipeCleanup := createPipe(t, client, testDb(t), schema, random.StringN(20), createPipeCopyStatement(t, table, stage)) + secondPipe, secondPipeCleanup := testClientHelper().Pipe.CreatePipe(t, createPipeCopyStatement(t, table, stage)) t.Cleanup(secondPipeCleanup) role, roleCleanup := testClientHelper().DatabaseRole.CreateDatabaseRole(t) @@ -648,8 +645,7 @@ func TestInt_GrantAndRevokePrivilegesToDatabaseRole(t *testing.T) { }) t.Run("grant and revoke on all pipes with multiple errors", func(t *testing.T) { - schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t) - t.Cleanup(schemaCleanup) + schema := testSchema(t) table, tableCleanup := testClientHelper().Table.CreateTableInSchema(t, schema.ID()) t.Cleanup(tableCleanup) @@ -657,10 +653,10 @@ func TestInt_GrantAndRevokePrivilegesToDatabaseRole(t *testing.T) { stage, stageCleanup := testClientHelper().Stage.CreateStageInSchema(t, sdk.NewDatabaseObjectIdentifier(testDb(t).Name, schema.Name)) t.Cleanup(stageCleanup) - _, pipeCleanup := createPipe(t, client, testDb(t), schema, random.AlphaN(20), createPipeCopyStatement(t, table, stage)) + _, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, createPipeCopyStatement(t, table, stage)) t.Cleanup(pipeCleanup) - _, secondPipeCleanup := createPipe(t, client, testDb(t), schema, random.AlphaN(20), createPipeCopyStatement(t, table, stage)) + _, secondPipeCleanup := testClientHelper().Pipe.CreatePipe(t, createPipeCopyStatement(t, table, stage)) t.Cleanup(secondPipeCleanup) role, roleCleanup := testClientHelper().DatabaseRole.CreateDatabaseRole(t) @@ -1132,7 +1128,7 @@ func TestInt_GrantOwnership(t *testing.T) { }) t.Run("on pipe - with ownership", func(t *testing.T) { - pipe, pipeCleanup := createPipe(t, client, testDb(t), testSchema(t), random.AlphaN(20), copyStatement) + pipe, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, copyStatement) t.Cleanup(pipeCleanup) pipeExecutionState, err := client.SystemFunctions.PipeStatus(pipe.ID()) @@ -1180,7 +1176,7 @@ func TestInt_GrantOwnership(t *testing.T) { // Use a previously prepared role to create a pipe and grant MONITOR + OPERATE to the previously used role (ACCOUNTADMIN). usePreviousRole := testClientHelper().Role.UseRole(t, pipeRole.Name) - pipe, pipeCleanup := createPipe(t, client, testDb(t), testSchema(t), random.AlphaN(20), copyStatement) + pipe, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, copyStatement) t.Cleanup(func() { usePreviousRole = testClientHelper().Role.UseRole(t, role.Name) defer usePreviousRole() @@ -1242,7 +1238,7 @@ func TestInt_GrantOwnership(t *testing.T) { // Use a previously prepared role to create a pipe and grant MONITOR + OPERATE to the previously used role (ACCOUNTADMIN). usePreviousRole := testClientHelper().Role.UseRole(t, pipeRole.Name) - pipe, pipeCleanup := createPipe(t, client, testDb(t), testSchema(t), random.AlphaN(20), copyStatement) + pipe, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, copyStatement) t.Cleanup(func() { usePreviousRole = testClientHelper().Role.UseRole(t, role.Name) defer usePreviousRole() @@ -1302,7 +1298,7 @@ func TestInt_GrantOwnership(t *testing.T) { // Use a previously prepared role to create a pipe and grant MONITOR + OPERATE to the previously used role (ACCOUNTADMIN). usePreviousRole := testClientHelper().Role.UseRole(t, pipeRole.Name) - pipe, pipeCleanup := createPipe(t, client, testDb(t), testSchema(t), random.AlphaN(20), copyStatement) + pipe, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, copyStatement) t.Cleanup(func() { usePreviousRole = testClientHelper().Role.UseRole(t, pipeRole.Name) defer usePreviousRole() @@ -1348,7 +1344,7 @@ func TestInt_GrantOwnership(t *testing.T) { // Use a previously prepared role to create a pipe and grant MONITOR + OPERATE to the previously used role (ACCOUNTADMIN). usePreviousRole := testClientHelper().Role.UseRole(t, pipeRole.Name) - pipe, pipeCleanup := createPipe(t, client, testDb(t), testSchema(t), random.AlphaN(20), copyStatement) + pipe, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, copyStatement) t.Cleanup(func() { usePreviousRole = testClientHelper().Role.UseRole(t, role.Name) defer usePreviousRole() @@ -1381,10 +1377,10 @@ func TestInt_GrantOwnership(t *testing.T) { }) t.Run("on all pipes", func(t *testing.T) { - pipe, pipeCleanup := createPipe(t, client, testDb(t), testSchema(t), random.AlphaN(20), copyStatement) + pipe, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, copyStatement) t.Cleanup(pipeCleanup) - secondPipe, secondPipeCleanup := createPipe(t, client, testDb(t), testSchema(t), random.AlphaN(20), copyStatement) + secondPipe, secondPipeCleanup := testClientHelper().Pipe.CreatePipe(t, copyStatement) t.Cleanup(secondPipeCleanup) pipeExecutionState, err := client.SystemFunctions.PipeStatus(pipe.ID()) diff --git a/pkg/sdk/testint/helpers_test.go b/pkg/sdk/testint/helpers_test.go index 105b77e562..7befa3a40e 100644 --- a/pkg/sdk/testint/helpers_test.go +++ b/pkg/sdk/testint/helpers_test.go @@ -33,289 +33,6 @@ func getAccountIdentifier(t *testing.T, client *sdk.Client) sdk.AccountIdentifie return sdk.AccountIdentifier{} } -func createTag(t *testing.T, client *sdk.Client, database *sdk.Database, schema *sdk.Schema) (*sdk.Tag, func()) { - t.Helper() - name := random.StringRange(8, 28) - ctx := context.Background() - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) - err := client.Tags.Create(ctx, sdk.NewCreateTagRequest(id)) - require.NoError(t, err) - tag, err := client.Tags.ShowByID(ctx, id) - require.NoError(t, err) - return tag, func() { - err := client.Tags.Drop(ctx, sdk.NewDropTagRequest(id)) - require.NoError(t, err) - } -} - -func createPipe(t *testing.T, client *sdk.Client, database *sdk.Database, schema *sdk.Schema, name string, copyStatement string) (*sdk.Pipe, func()) { - t.Helper() - require.NotNil(t, database, "database has to be created") - require.NotNil(t, schema, "schema has to be created") - - id := sdk.NewSchemaObjectIdentifier(database.Name, schema.Name, name) - ctx := context.Background() - - pipeCleanup := func() { - err := client.Pipes.Drop(ctx, id) - require.NoError(t, err) - } - - err := client.Pipes.Create(ctx, id, copyStatement, &sdk.CreatePipeOptions{}) - if err != nil { - return nil, pipeCleanup - } - require.NoError(t, err) - - createdPipe, errDescribe := client.Pipes.Describe(ctx, id) - if errDescribe != nil { - return nil, pipeCleanup - } - require.NoError(t, errDescribe) - - return createdPipe, pipeCleanup -} - -func createPasswordPolicy(t *testing.T, client *sdk.Client, database *sdk.Database, schema *sdk.Schema) (*sdk.PasswordPolicy, func()) { - t.Helper() - return createPasswordPolicyWithOptions(t, client, database, schema, nil) -} - -func createPasswordPolicyWithOptions(t *testing.T, client *sdk.Client, database *sdk.Database, schema *sdk.Schema, options *sdk.CreatePasswordPolicyOptions) (*sdk.PasswordPolicy, func()) { - t.Helper() - var databaseCleanup func() - if database == nil { - database, databaseCleanup = testClientHelper().Database.CreateDatabase(t) - } - var schemaCleanup func() - if schema == nil { - schema, schemaCleanup = testClientHelper().Schema.CreateSchemaInDatabase(t, database.ID()) - } - name := random.UUID() - id := sdk.NewSchemaObjectIdentifier(schema.DatabaseName, schema.Name, name) - ctx := context.Background() - err := client.PasswordPolicies.Create(ctx, id, options) - require.NoError(t, err) - - showOptions := &sdk.ShowPasswordPolicyOptions{ - Like: &sdk.Like{ - Pattern: sdk.String(name), - }, - In: &sdk.In{ - Schema: schema.ID(), - }, - } - passwordPolicyList, err := client.PasswordPolicies.Show(ctx, showOptions) - require.NoError(t, err) - require.Equal(t, 1, len(passwordPolicyList)) - return &passwordPolicyList[0], func() { - err := client.PasswordPolicies.Drop(ctx, id, nil) - require.NoError(t, err) - if schemaCleanup != nil { - schemaCleanup() - } - if databaseCleanup != nil { - databaseCleanup() - } - } -} - -func createNetworkPolicy(t *testing.T, client *sdk.Client, req *sdk.CreateNetworkPolicyRequest) (error, func()) { - t.Helper() - ctx := context.Background() - err := client.NetworkPolicies.Create(ctx, req) - return err, func() { - err := client.NetworkPolicies.Drop(ctx, sdk.NewDropNetworkPolicyRequest(req.GetName())) - require.NoError(t, err) - } -} - -func createResourceMonitor(t *testing.T, client *sdk.Client) (*sdk.ResourceMonitor, func()) { - t.Helper() - return createResourceMonitorWithOptions(t, client, &sdk.CreateResourceMonitorOptions{ - With: &sdk.ResourceMonitorWith{ - CreditQuota: sdk.Pointer(100), - Triggers: []sdk.TriggerDefinition{ - { - Threshold: 100, - TriggerAction: sdk.TriggerActionSuspend, - }, - { - Threshold: 70, - TriggerAction: sdk.TriggerActionSuspendImmediate, - }, - { - Threshold: 90, - TriggerAction: sdk.TriggerActionNotify, - }, - }, - }, - }) -} - -func createResourceMonitorWithOptions(t *testing.T, client *sdk.Client, opts *sdk.CreateResourceMonitorOptions) (*sdk.ResourceMonitor, func()) { - t.Helper() - id := sdk.RandomAccountObjectIdentifier() - ctx := context.Background() - err := client.ResourceMonitors.Create(ctx, id, opts) - require.NoError(t, err) - resourceMonitor, err := client.ResourceMonitors.ShowByID(ctx, id) - require.NoError(t, err) - return resourceMonitor, func() { - err := client.ResourceMonitors.Drop(ctx, id) - require.NoError(t, err) - } -} - -func createMaskingPolicy(t *testing.T, client *sdk.Client, database *sdk.Database, schema *sdk.Schema) (*sdk.MaskingPolicy, func()) { - t.Helper() - signature := []sdk.TableColumnSignature{ - { - Name: random.String(), - Type: sdk.DataTypeVARCHAR, - }, - } - n := random.IntRange(0, 5) - for i := 0; i < n; i++ { - signature = append(signature, sdk.TableColumnSignature{ - Name: random.String(), - Type: sdk.DataTypeVARCHAR, - }) - } - expression := "REPLACE('X', 1, 2)" - return createMaskingPolicyWithOptions(t, client, database, schema, signature, sdk.DataTypeVARCHAR, expression, &sdk.CreateMaskingPolicyOptions{}) -} - -func createMaskingPolicyIdentity(t *testing.T, client *sdk.Client, database *sdk.Database, schema *sdk.Schema, columnType sdk.DataType) (*sdk.MaskingPolicy, func()) { - t.Helper() - name := "a" - signature := []sdk.TableColumnSignature{ - { - Name: name, - Type: columnType, - }, - } - expression := "a" - return createMaskingPolicyWithOptions(t, client, database, schema, signature, columnType, expression, &sdk.CreateMaskingPolicyOptions{}) -} - -func createMaskingPolicyWithOptions(t *testing.T, client *sdk.Client, database *sdk.Database, schema *sdk.Schema, signature []sdk.TableColumnSignature, returns sdk.DataType, expression string, options *sdk.CreateMaskingPolicyOptions) (*sdk.MaskingPolicy, func()) { - t.Helper() - var databaseCleanup func() - if database == nil { - database, databaseCleanup = testClientHelper().Database.CreateDatabase(t) - } - var schemaCleanup func() - if schema == nil { - schema, schemaCleanup = testClientHelper().Schema.CreateSchemaInDatabase(t, database.ID()) - } - name := random.String() - id := sdk.NewSchemaObjectIdentifier(schema.DatabaseName, schema.Name, name) - ctx := context.Background() - err := client.MaskingPolicies.Create(ctx, id, signature, returns, expression, options) - require.NoError(t, err) - - showOptions := &sdk.ShowMaskingPolicyOptions{ - Like: &sdk.Like{ - Pattern: sdk.String(name), - }, - In: &sdk.In{ - Schema: schema.ID(), - }, - } - maskingPolicyList, err := client.MaskingPolicies.Show(ctx, showOptions) - require.NoError(t, err) - require.Equal(t, 1, len(maskingPolicyList)) - return &maskingPolicyList[0], func() { - err := client.MaskingPolicies.Drop(ctx, id) - require.NoError(t, err) - if schemaCleanup != nil { - schemaCleanup() - } - if databaseCleanup != nil { - databaseCleanup() - } - } -} - -func createAlert(t *testing.T, client *sdk.Client, database *sdk.Database, schema *sdk.Schema, warehouse *sdk.Warehouse) (*sdk.Alert, func()) { - t.Helper() - schedule := "USING CRON * * * * * UTC" - condition := "SELECT 1" - action := "SELECT 1" - return createAlertWithOptions(t, client, database, schema, warehouse, schedule, condition, action, &sdk.CreateAlertOptions{}) -} - -func createAlertWithOptions(t *testing.T, client *sdk.Client, database *sdk.Database, schema *sdk.Schema, warehouse *sdk.Warehouse, schedule string, condition string, action string, opts *sdk.CreateAlertOptions) (*sdk.Alert, func()) { - t.Helper() - var databaseCleanup func() - if database == nil { - database, databaseCleanup = testClientHelper().Database.CreateDatabase(t) - } - var schemaCleanup func() - if schema == nil { - schema, schemaCleanup = testClientHelper().Schema.CreateSchemaInDatabase(t, database.ID()) - } - var warehouseCleanup func() - if warehouse == nil { - warehouse, warehouseCleanup = testClientHelper().Warehouse.CreateWarehouse(t) - } - - name := random.String() - id := sdk.NewSchemaObjectIdentifier(schema.DatabaseName, schema.Name, name) - ctx := context.Background() - err := client.Alerts.Create(ctx, id, warehouse.ID(), schedule, condition, action, opts) - require.NoError(t, err) - - showOptions := &sdk.ShowAlertOptions{ - Like: &sdk.Like{ - Pattern: sdk.String(name), - }, - In: &sdk.In{ - Schema: schema.ID(), - }, - } - alertList, err := client.Alerts.Show(ctx, showOptions) - require.NoError(t, err) - require.Equal(t, 1, len(alertList)) - return &alertList[0], func() { - err := client.Alerts.Drop(ctx, id) - require.NoError(t, err) - if schemaCleanup != nil { - schemaCleanup() - } - if databaseCleanup != nil { - databaseCleanup() - } - if warehouseCleanup != nil { - warehouseCleanup() - } - } -} - -func createFailoverGroup(t *testing.T, client *sdk.Client) (*sdk.FailoverGroup, func()) { - t.Helper() - objectTypes := []sdk.PluralObjectType{sdk.PluralObjectTypeRoles} - currentAccount := testClientHelper().Context.CurrentAccount(t) - accountID := sdk.NewAccountIdentifierFromAccountLocator(currentAccount) - allowedAccounts := []sdk.AccountIdentifier{accountID} - return createFailoverGroupWithOptions(t, client, objectTypes, allowedAccounts, nil) -} - -func createFailoverGroupWithOptions(t *testing.T, client *sdk.Client, objectTypes []sdk.PluralObjectType, allowedAccounts []sdk.AccountIdentifier, opts *sdk.CreateFailoverGroupOptions) (*sdk.FailoverGroup, func()) { - t.Helper() - id := sdk.RandomAlphanumericAccountObjectIdentifier() - ctx := context.Background() - err := client.FailoverGroups.Create(ctx, id, objectTypes, allowedAccounts, opts) - require.NoError(t, err) - failoverGroup, err := client.FailoverGroups.ShowByID(ctx, id) - require.NoError(t, err) - return failoverGroup, func() { - err := client.FailoverGroups.Drop(ctx, id, nil) - require.NoError(t, err) - } -} - func createShare(t *testing.T, client *sdk.Client) (*sdk.Share, func()) { t.Helper() // TODO(SNOW-1058419): Try with identifier containing dot during identifiers rework @@ -336,27 +53,6 @@ func createShareWithOptions(t *testing.T, client *sdk.Client, id sdk.AccountObje } } -func createFileFormat(t *testing.T, client *sdk.Client, schema sdk.DatabaseObjectIdentifier) (*sdk.FileFormat, func()) { - t.Helper() - return createFileFormatWithOptions(t, client, schema, &sdk.CreateFileFormatOptions{ - Type: sdk.FileFormatTypeCSV, - }) -} - -func createFileFormatWithOptions(t *testing.T, client *sdk.Client, schema sdk.DatabaseObjectIdentifier, opts *sdk.CreateFileFormatOptions) (*sdk.FileFormat, func()) { - t.Helper() - id := sdk.NewSchemaObjectIdentifier(schema.DatabaseName(), schema.Name(), random.String()) - ctx := context.Background() - err := client.FileFormats.Create(ctx, id, opts) - require.NoError(t, err) - fileFormat, err := client.FileFormats.ShowByID(ctx, id) - require.NoError(t, err) - return fileFormat, func() { - err := client.FileFormats.Drop(ctx, id, nil) - require.NoError(t, err) - } -} - func createView(t *testing.T, client *sdk.Client, viewId sdk.SchemaObjectIdentifier, asQuery string) func() { t.Helper() ctx := context.Background() diff --git a/pkg/sdk/testint/masking_policy_integration_test.go b/pkg/sdk/testint/masking_policy_integration_test.go index bfde3fab4a..f76f9b2910 100644 --- a/pkg/sdk/testint/masking_policy_integration_test.go +++ b/pkg/sdk/testint/masking_policy_integration_test.go @@ -15,10 +15,10 @@ func TestInt_MaskingPoliciesShow(t *testing.T) { client := testClient(t) ctx := testContext(t) - maskingPolicyTest, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) + maskingPolicyTest, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicy(t) t.Cleanup(maskingPolicyCleanup) - maskingPolicy2Test, maskingPolicy2Cleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) + maskingPolicy2Test, maskingPolicy2Cleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicy(t) t.Cleanup(maskingPolicy2Cleanup) t.Run("without show options", func(t *testing.T) { @@ -243,7 +243,7 @@ func TestInt_MaskingPolicyDescribe(t *testing.T) { client := testClient(t) ctx := testContext(t) - maskingPolicy, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) + maskingPolicy, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicy(t) t.Cleanup(maskingPolicyCleanup) t.Run("when masking policy exists", func(t *testing.T) { @@ -264,7 +264,7 @@ func TestInt_MaskingPolicyAlter(t *testing.T) { ctx := testContext(t) t.Run("when setting and unsetting a value", func(t *testing.T) { - maskingPolicy, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) + maskingPolicy, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicy(t) t.Cleanup(maskingPolicyCleanup) comment := random.Comment() alterOptions := &sdk.AlterMaskingPolicyOptions{ @@ -309,7 +309,7 @@ func TestInt_MaskingPolicyAlter(t *testing.T) { }) t.Run("when renaming", func(t *testing.T) { - maskingPolicy, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) + maskingPolicy, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicy(t) oldID := maskingPolicy.ID() t.Cleanup(maskingPolicyCleanup) newName := random.String() @@ -331,14 +331,14 @@ func TestInt_MaskingPolicyAlter(t *testing.T) { }) t.Run("setting and unsetting tags", func(t *testing.T) { - maskingPolicy, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) + maskingPolicy, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicy(t) id := maskingPolicy.ID() t.Cleanup(maskingPolicyCleanup) - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) - tag2, tag2Cleanup := createTag(t, client, testDb(t), testSchema(t)) + tag2, tag2Cleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tag2Cleanup) tagAssociations := []sdk.TagAssociation{{Name: tag.ID(), Value: "value1"}, {Name: tag2.ID(), Value: "value2"}} @@ -370,9 +370,10 @@ func TestInt_MaskingPolicyDrop(t *testing.T) { ctx := testContext(t) t.Run("when masking policy exists", func(t *testing.T) { - maskingPolicy, _ := createMaskingPolicy(t, client, testDb(t), testSchema(t)) + maskingPolicy, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicy(t) + t.Cleanup(maskingPolicyCleanup) id := maskingPolicy.ID() - err := client.MaskingPolicies.Drop(ctx, id) + err := client.MaskingPolicies.Drop(ctx, id, &sdk.DropMaskingPolicyOptions{}) require.NoError(t, err) _, err = client.MaskingPolicies.Describe(ctx, id) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) @@ -380,7 +381,7 @@ func TestInt_MaskingPolicyDrop(t *testing.T) { t.Run("when masking policy does not exist", func(t *testing.T) { id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, "does_not_exist") - err := client.MaskingPolicies.Drop(ctx, id) + err := client.MaskingPolicies.Drop(ctx, id, &sdk.DropMaskingPolicyOptions{}) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) }) } @@ -394,7 +395,7 @@ func TestInt_MaskingPoliciesShowByID(t *testing.T) { cleanupMaskingPolicyHandle := func(t *testing.T, id sdk.SchemaObjectIdentifier) func() { t.Helper() return func() { - err := client.MaskingPolicies.Drop(ctx, id) + err := client.MaskingPolicies.Drop(ctx, id, &sdk.DropMaskingPolicyOptions{IfExists: sdk.Bool(true)}) if errors.Is(err, sdk.ErrObjectNotExistOrAuthorized) { return } diff --git a/pkg/sdk/testint/materialized_views_gen_integration_test.go b/pkg/sdk/testint/materialized_views_gen_integration_test.go index cf65c83719..501d877988 100644 --- a/pkg/sdk/testint/materialized_views_gen_integration_test.go +++ b/pkg/sdk/testint/materialized_views_gen_integration_test.go @@ -116,7 +116,7 @@ func TestInt_MaterializedViews(t *testing.T) { rowAccessPolicyId, rowAccessPolicyCleanup := createRowAccessPolicy(t, client, testSchema(t)) t.Cleanup(rowAccessPolicyCleanup) - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) request := createMaterializedViewBasicRequest(t). @@ -314,7 +314,7 @@ func TestInt_MaterializedViews(t *testing.T) { // Based on usage notes, set/unset tags is done through VIEW (https://docs.snowflake.com/en/sql-reference/sql/alter-materialized-view#usage-notes). // TODO [SNOW-1022645]: discuss how we handle situation like this in the SDK t.Run("alter materialized view: set and unset tags", func(t *testing.T) { - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) materializedView := createMaterializedView(t) diff --git a/pkg/sdk/testint/network_policies_gen_integration_test.go b/pkg/sdk/testint/network_policies_gen_integration_test.go index 1397f80925..8c944874f0 100644 --- a/pkg/sdk/testint/network_policies_gen_integration_test.go +++ b/pkg/sdk/testint/network_policies_gen_integration_test.go @@ -56,8 +56,7 @@ func TestInt_NetworkPolicies(t *testing.T) { req = req.WithAllowedNetworkRuleList([]sdk.SchemaObjectIdentifier{allowedNetworkRule}) req = req.WithBlockedNetworkRuleList([]sdk.SchemaObjectIdentifier{blockedNetworkRule}) - err, dropNetworkPolicy := createNetworkPolicy(t, client, req) - require.NoError(t, err) + _, dropNetworkPolicy := testClientHelper().NetworkPolicy.CreateNetworkPolicyWithRequest(t, req) t.Cleanup(dropNetworkPolicy) nps, err := client.NetworkPolicies.Show(ctx, sdk.NewShowNetworkPolicyRequest()) @@ -74,11 +73,10 @@ func TestInt_NetworkPolicies(t *testing.T) { t.Run("Alter - set allowed ip list", func(t *testing.T) { req := defaultCreateRequest() - err, dropNetworkPolicy := createNetworkPolicy(t, client, req) - require.NoError(t, err) + _, dropNetworkPolicy := testClientHelper().NetworkPolicy.CreateNetworkPolicyWithRequest(t, req) t.Cleanup(dropNetworkPolicy) - err = client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). + err := client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). WithSet(sdk.NewNetworkPolicySetRequest().WithAllowedIpList([]sdk.IPRequest{{IP: "123.0.0.1"}, {IP: "125.0.0.1"}}))) require.NoError(t, err) @@ -92,11 +90,10 @@ func TestInt_NetworkPolicies(t *testing.T) { t.Run("Alter - set blocked ip list", func(t *testing.T) { req := defaultCreateRequest() - err, dropNetworkPolicy := createNetworkPolicy(t, client, req) - require.NoError(t, err) + _, dropNetworkPolicy := testClientHelper().NetworkPolicy.CreateNetworkPolicyWithRequest(t, req) t.Cleanup(dropNetworkPolicy) - err = client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). + err := client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). WithSet(sdk.NewNetworkPolicySetRequest().WithBlockedIpList([]sdk.IPRequest{{IP: "123.0.0.1"}}))) require.NoError(t, err) @@ -112,11 +109,10 @@ func TestInt_NetworkPolicies(t *testing.T) { allowedNetworkRule := createNetworkRuleHandle(t, client) allowedNetworkRule2 := createNetworkRuleHandle(t, client) req := defaultCreateRequest() - err, dropNetworkPolicy := createNetworkPolicy(t, client, req) - require.NoError(t, err) + _, dropNetworkPolicy := testClientHelper().NetworkPolicy.CreateNetworkPolicyWithRequest(t, req) t.Cleanup(dropNetworkPolicy) - err = client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). + err := client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). WithSet(sdk.NewNetworkPolicySetRequest().WithAllowedNetworkRuleList([]sdk.SchemaObjectIdentifier{allowedNetworkRule, allowedNetworkRule2}))) require.NoError(t, err) @@ -129,11 +125,10 @@ func TestInt_NetworkPolicies(t *testing.T) { blockedNetworkRule := createNetworkRuleHandle(t, client) req := defaultCreateRequest() - err, dropNetworkPolicy := createNetworkPolicy(t, client, req) - require.NoError(t, err) + _, dropNetworkPolicy := testClientHelper().NetworkPolicy.CreateNetworkPolicyWithRequest(t, req) t.Cleanup(dropNetworkPolicy) - err = client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). + err := client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). WithSet(sdk.NewNetworkPolicySetRequest().WithBlockedNetworkRuleList([]sdk.SchemaObjectIdentifier{blockedNetworkRule}))) require.NoError(t, err) @@ -146,11 +141,10 @@ func TestInt_NetworkPolicies(t *testing.T) { allowedNetworkRule := createNetworkRuleHandle(t, client) req := defaultCreateRequest() - err, dropNetworkPolicy := createNetworkPolicy(t, client, req) - require.NoError(t, err) + _, dropNetworkPolicy := testClientHelper().NetworkPolicy.CreateNetworkPolicyWithRequest(t, req) t.Cleanup(dropNetworkPolicy) - err = client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). + err := client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). WithAdd(sdk.NewAddNetworkRuleRequest().WithAllowedNetworkRuleList([]sdk.SchemaObjectIdentifier{allowedNetworkRule}))) require.NoError(t, err) @@ -171,11 +165,10 @@ func TestInt_NetworkPolicies(t *testing.T) { blockedNetworkRule := createNetworkRuleHandle(t, client) req := defaultCreateRequest() - err, dropNetworkPolicy := createNetworkPolicy(t, client, req) - require.NoError(t, err) + _, dropNetworkPolicy := testClientHelper().NetworkPolicy.CreateNetworkPolicyWithRequest(t, req) t.Cleanup(dropNetworkPolicy) - err = client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). + err := client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). WithAdd(sdk.NewAddNetworkRuleRequest().WithBlockedNetworkRuleList([]sdk.SchemaObjectIdentifier{blockedNetworkRule}))) require.NoError(t, err) @@ -194,12 +187,11 @@ func TestInt_NetworkPolicies(t *testing.T) { t.Run("Alter - set comment", func(t *testing.T) { req := defaultCreateRequest() - err, dropNetworkPolicy := createNetworkPolicy(t, client, req) - require.NoError(t, err) + _, dropNetworkPolicy := testClientHelper().NetworkPolicy.CreateNetworkPolicyWithRequest(t, req) t.Cleanup(dropNetworkPolicy) alteredComment := "altered_comment" - err = client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). + err := client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()). WithSet(sdk.NewNetworkPolicySetRequest().WithComment(&alteredComment))) require.NoError(t, err) @@ -213,11 +205,10 @@ func TestInt_NetworkPolicies(t *testing.T) { t.Run("Alter - unset comment", func(t *testing.T) { req := defaultCreateRequest() - err, dropNetworkPolicy := createNetworkPolicy(t, client, req) - require.NoError(t, err) + _, dropNetworkPolicy := testClientHelper().NetworkPolicy.CreateNetworkPolicyWithRequest(t, req) t.Cleanup(dropNetworkPolicy) - err = client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()).WithUnsetComment(sdk.Bool(true))) + err := client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()).WithUnsetComment(sdk.Bool(true))) require.NoError(t, err) nps, err := client.NetworkPolicies.Show(ctx, sdk.NewShowNetworkPolicyRequest()) @@ -229,27 +220,14 @@ func TestInt_NetworkPolicies(t *testing.T) { }) t.Run("Alter - rename", func(t *testing.T) { - altered := false - req := defaultCreateRequest() - err, dropNetworkPolicy := createNetworkPolicy(t, client, req) - require.NoError(t, err) - t.Cleanup(func() { - if !altered { - dropNetworkPolicy() - } - }) + _, dropNetworkPolicy := testClientHelper().NetworkPolicy.CreateNetworkPolicyWithRequest(t, req) + t.Cleanup(dropNetworkPolicy) newID := sdk.RandomAccountObjectIdentifier() - err = client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()).WithRenameTo(&newID)) + err := client.NetworkPolicies.Alter(ctx, sdk.NewAlterNetworkPolicyRequest(req.GetName()).WithRenameTo(&newID)) require.NoError(t, err) - altered = true - t.Cleanup(func() { - if altered { - err = client.NetworkPolicies.Drop(ctx, sdk.NewDropNetworkPolicyRequest(newID)) - require.NoError(t, err) - } - }) + t.Cleanup(testClientHelper().NetworkPolicy.DropNetworkPolicyFunc(t, newID)) nps, err := client.NetworkPolicies.Show(ctx, sdk.NewShowNetworkPolicyRequest()) require.NoError(t, err) @@ -264,8 +242,7 @@ func TestInt_NetworkPolicies(t *testing.T) { t.Run("Describe", func(t *testing.T) { req := defaultCreateRequest() - err, dropNetworkPolicy := createNetworkPolicy(t, client, req) - require.NoError(t, err) + _, dropNetworkPolicy := testClientHelper().NetworkPolicy.CreateNetworkPolicyWithRequest(t, req) t.Cleanup(dropNetworkPolicy) desc, err := client.NetworkPolicies.Describe(ctx, req.GetName()) diff --git a/pkg/sdk/testint/notification_integrations_gen_integration_test.go b/pkg/sdk/testint/notification_integrations_gen_integration_test.go index 5f064204c4..1cc527d497 100644 --- a/pkg/sdk/testint/notification_integrations_gen_integration_test.go +++ b/pkg/sdk/testint/notification_integrations_gen_integration_test.go @@ -359,7 +359,7 @@ func TestInt_NotificationIntegrations(t *testing.T) { }) t.Run("alter notification integration: set and unset tags", func(t *testing.T) { - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) integration := createNotificationIntegrationEmail(t) diff --git a/pkg/sdk/testint/password_policy_integration_test.go b/pkg/sdk/testint/password_policy_integration_test.go index d503dc1501..1998fbb460 100644 --- a/pkg/sdk/testint/password_policy_integration_test.go +++ b/pkg/sdk/testint/password_policy_integration_test.go @@ -14,10 +14,10 @@ func TestInt_PasswordPoliciesShow(t *testing.T) { client := testClient(t) ctx := testContext(t) - passwordPolicyTest, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), testSchema(t)) + passwordPolicyTest, passwordPolicyCleanup := testClientHelper().PasswordPolicy.CreatePasswordPolicy(t) t.Cleanup(passwordPolicyCleanup) - passwordPolicy2Test, passwordPolicy2Cleanup := createPasswordPolicy(t, client, testDb(t), testSchema(t)) + passwordPolicy2Test, passwordPolicy2Cleanup := testClientHelper().PasswordPolicy.CreatePasswordPolicy(t) t.Cleanup(passwordPolicy2Cleanup) t.Run("without show options", func(t *testing.T) { @@ -165,7 +165,7 @@ func TestInt_PasswordPolicyDescribe(t *testing.T) { client := testClient(t) ctx := testContext(t) - passwordPolicy, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), testSchema(t)) + passwordPolicy, passwordPolicyCleanup := testClientHelper().PasswordPolicy.CreatePasswordPolicy(t) t.Cleanup(passwordPolicyCleanup) t.Run("when password policy exists", func(t *testing.T) { @@ -187,7 +187,7 @@ func TestInt_PasswordPolicyAlter(t *testing.T) { ctx := testContext(t) t.Run("when setting new values", func(t *testing.T) { - passwordPolicy, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), testSchema(t)) + passwordPolicy, passwordPolicyCleanup := testClientHelper().PasswordPolicy.CreatePasswordPolicy(t) t.Cleanup(passwordPolicyCleanup) alterOptions := &sdk.AlterPasswordPolicyOptions{ Set: &sdk.PasswordPolicySet{ @@ -207,7 +207,7 @@ func TestInt_PasswordPolicyAlter(t *testing.T) { }) t.Run("when renaming", func(t *testing.T) { - passwordPolicy, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), testSchema(t)) + passwordPolicy, passwordPolicyCleanup := testClientHelper().PasswordPolicy.CreatePasswordPolicy(t) oldID := passwordPolicy.ID() t.Cleanup(passwordPolicyCleanup) newName := random.UUID() @@ -234,7 +234,7 @@ func TestInt_PasswordPolicyAlter(t *testing.T) { PasswordMaxRetries: sdk.Int(10), Comment: sdk.String("test comment"), } - passwordPolicy, passwordPolicyCleanup := createPasswordPolicyWithOptions(t, client, testDb(t), testSchema(t), createOptions) + passwordPolicy, passwordPolicyCleanup := testClientHelper().PasswordPolicy.CreatePasswordPolicyWithOptions(t, createOptions) id := passwordPolicy.ID() t.Cleanup(passwordPolicyCleanup) alterOptions := &sdk.AlterPasswordPolicyOptions{ @@ -265,7 +265,7 @@ func TestInt_PasswordPolicyAlter(t *testing.T) { PasswordMaxRetries: sdk.Int(10), Comment: sdk.String("test comment"), } - passwordPolicy, passwordPolicyCleanup := createPasswordPolicyWithOptions(t, client, testDb(t), testSchema(t), createOptions) + passwordPolicy, passwordPolicyCleanup := testClientHelper().PasswordPolicy.CreatePasswordPolicyWithOptions(t, createOptions) id := passwordPolicy.ID() t.Cleanup(passwordPolicyCleanup) alterOptions := &sdk.AlterPasswordPolicyOptions{ @@ -285,7 +285,8 @@ func TestInt_PasswordPolicyDrop(t *testing.T) { ctx := testContext(t) t.Run("when password policy exists", func(t *testing.T) { - passwordPolicy, _ := createPasswordPolicy(t, client, testDb(t), testSchema(t)) + passwordPolicy, passwordPolicyCleanup := testClientHelper().PasswordPolicy.CreatePasswordPolicy(t) + t.Cleanup(passwordPolicyCleanup) id := passwordPolicy.ID() err := client.PasswordPolicies.Drop(ctx, id, nil) require.NoError(t, err) @@ -300,7 +301,8 @@ func TestInt_PasswordPolicyDrop(t *testing.T) { }) t.Run("when password policy exists and if exists is true", func(t *testing.T) { - passwordPolicy, _ := createPasswordPolicy(t, client, testDb(t), testSchema(t)) + passwordPolicy, passwordPolicyCleanup := testClientHelper().PasswordPolicy.CreatePasswordPolicy(t) + t.Cleanup(passwordPolicyCleanup) id := passwordPolicy.ID() dropOptions := &sdk.DropPasswordPolicyOptions{IfExists: sdk.Bool(true)} err := client.PasswordPolicies.Drop(ctx, id, dropOptions) diff --git a/pkg/sdk/testint/pipes_integration_test.go b/pkg/sdk/testint/pipes_integration_test.go index f75310a5a8..622e95b0e1 100644 --- a/pkg/sdk/testint/pipes_integration_test.go +++ b/pkg/sdk/testint/pipes_integration_test.go @@ -75,14 +75,12 @@ func TestInt_PipesShowAndDescribe(t *testing.T) { stage, stageCleanup := testClientHelper().Stage.CreateStage(t) t.Cleanup(stageCleanup) - pipe1Name := random.AlphanumericN(20) pipe1CopyStatement := createPipeCopyStatement(t, table1, stage) - pipe1, pipe1Cleanup := createPipe(t, itc.client, testDb(t), testSchema(t), pipe1Name, pipe1CopyStatement) + pipe1, pipe1Cleanup := testClientHelper().Pipe.CreatePipe(t, pipe1CopyStatement) t.Cleanup(pipe1Cleanup) - pipe2Name := random.AlphanumericN(20) pipe2CopyStatement := createPipeCopyStatement(t, table2, stage) - pipe2, pipe2Cleanup := createPipe(t, itc.client, testDb(t), testSchema(t), pipe2Name, pipe2CopyStatement) + pipe2, pipe2Cleanup := testClientHelper().Pipe.CreatePipe(t, pipe2CopyStatement) t.Cleanup(pipe2Cleanup) t.Run("show: without options", func(t *testing.T) { @@ -111,7 +109,7 @@ func TestInt_PipesShowAndDescribe(t *testing.T) { t.Run("show: like", func(t *testing.T) { showOptions := &sdk.ShowPipeOptions{ Like: &sdk.Like{ - Pattern: sdk.String(pipe1Name), + Pattern: sdk.String(pipe1.Name), }, } pipes, err := itc.client.Pipes.Show(itc.ctx, showOptions) @@ -227,11 +225,10 @@ func TestInt_PipeDrop(t *testing.T) { t.Cleanup(stageCleanup) t.Run("pipe exists", func(t *testing.T) { - pipeName := random.AlphanumericN(20) pipeCopyStatement := createPipeCopyStatement(t, table, stage) - pipe, _ := createPipe(t, itc.client, testDb(t), testSchema(t), pipeName, pipeCopyStatement) + pipe, _ := testClientHelper().Pipe.CreatePipe(t, pipeCopyStatement) - err := itc.client.Pipes.Drop(itc.ctx, pipe.ID()) + err := itc.client.Pipes.Drop(itc.ctx, pipe.ID(), nil) require.NoError(t, err) _, err = itc.client.Pipes.Describe(itc.ctx, pipe.ID()) @@ -241,7 +238,7 @@ func TestInt_PipeDrop(t *testing.T) { t.Run("pipe does not exist", func(t *testing.T) { id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testDb(t).Name, "does_not_exist") - err := itc.client.Alerts.Drop(itc.ctx, id) + err := itc.client.Pipes.Drop(itc.ctx, id, &sdk.DropPipeOptions{}) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) }) } @@ -257,8 +254,7 @@ func TestInt_PipeAlter(t *testing.T) { // TODO: test error integration when we have them in project t.Run("set value and unset value", func(t *testing.T) { - pipeName := random.AlphanumericN(20) - pipe, pipeCleanup := createPipe(t, itc.client, testDb(t), testSchema(t), pipeName, pipeCopyStatement) + pipe, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, pipeCopyStatement) t.Cleanup(pipeCleanup) alterOptions := &sdk.AlterPipeOptions{ @@ -293,11 +289,10 @@ func TestInt_PipeAlter(t *testing.T) { }) t.Run("set and unset tag", func(t *testing.T) { - tag, tagCleanup := createTag(t, itc.client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) - pipeName := random.AlphanumericN(20) - pipe, pipeCleanup := createPipe(t, itc.client, testDb(t), testSchema(t), pipeName, pipeCopyStatement) + pipe, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, pipeCopyStatement) t.Cleanup(pipeCleanup) tagValue := "abc" @@ -332,8 +327,7 @@ func TestInt_PipeAlter(t *testing.T) { }) t.Run("refresh with all", func(t *testing.T) { - pipeName := random.AlphanumericN(20) - pipe, pipeCleanup := createPipe(t, itc.client, testDb(t), testSchema(t), pipeName, pipeCopyStatement) + pipe, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, pipeCopyStatement) t.Cleanup(pipeCleanup) alterOptions := &sdk.AlterPipeOptions{ @@ -361,7 +355,7 @@ func TestInt_PipesShowByID(t *testing.T) { cleanupPipeHandle := func(t *testing.T, id sdk.SchemaObjectIdentifier) func() { t.Helper() return func() { - err := client.Pipes.Drop(ctx, id) + err := client.Pipes.Drop(ctx, id, nil) if errors.Is(err, sdk.ErrObjectNotExistOrAuthorized) { return } diff --git a/pkg/sdk/testint/policy_references_integration_test.go b/pkg/sdk/testint/policy_references_integration_test.go index d8882d09c5..247ca252a8 100644 --- a/pkg/sdk/testint/policy_references_integration_test.go +++ b/pkg/sdk/testint/policy_references_integration_test.go @@ -40,10 +40,10 @@ func TestInt_PolicyReferences(t *testing.T) { }) t.Run("tag domain", func(t *testing.T) { - maskingPolicy, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) + maskingPolicy, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicy(t) t.Cleanup(maskingPolicyCleanup) - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) err = client.Tags.Alter(ctx, sdk.NewAlterTagRequest(tag.ID()).WithSet( diff --git a/pkg/sdk/testint/procedures_integration_test.go b/pkg/sdk/testint/procedures_integration_test.go index c0c899edab..4e652e372c 100644 --- a/pkg/sdk/testint/procedures_integration_test.go +++ b/pkg/sdk/testint/procedures_integration_test.go @@ -346,7 +346,7 @@ func TestInt_OtherProcedureFunctions(t *testing.T) { ctx := testContext(t) databaseTest, schemaTest := testDb(t), testSchema(t) - tagTest, tagCleanup := createTag(t, client, databaseTest, schemaTest) + tagTest, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) assertProcedure := func(t *testing.T, id sdk.SchemaObjectIdentifier, secure bool) { diff --git a/pkg/sdk/testint/resource_monitors_integration_test.go b/pkg/sdk/testint/resource_monitors_integration_test.go index 2eb3ff8c50..a7f7e30be0 100644 --- a/pkg/sdk/testint/resource_monitors_integration_test.go +++ b/pkg/sdk/testint/resource_monitors_integration_test.go @@ -14,7 +14,7 @@ func TestInt_ResourceMonitorsShow(t *testing.T) { client := testClient(t) ctx := testContext(t) - resourceMonitorTest, resourceMonitorCleanup := createResourceMonitor(t, client) + resourceMonitorTest, resourceMonitorCleanup := testClientHelper().ResourceMonitor.CreateResourceMonitor(t) t.Cleanup(resourceMonitorCleanup) t.Run("with like", func(t *testing.T) { @@ -107,10 +107,7 @@ func TestInt_ResourceMonitorCreate(t *testing.T) { } assert.Equal(t, thresholds, allThresholds) - t.Cleanup(func() { - err = client.ResourceMonitors.Drop(ctx, id) - require.NoError(t, err) - }) + t.Cleanup(testClientHelper().ResourceMonitor.DropResourceMonitorFunc(t, id)) }) t.Run("test no options", func(t *testing.T) { @@ -139,10 +136,7 @@ func TestInt_ResourceMonitorCreate(t *testing.T) { assert.Empty(t, resourceMonitor.SuspendAt) assert.Empty(t, resourceMonitor.SuspendImmediateAt) - t.Cleanup(func() { - err = client.ResourceMonitors.Drop(ctx, id) - require.NoError(t, err) - }) + t.Cleanup(testClientHelper().ResourceMonitor.DropResourceMonitorFunc(t, id)) }) } @@ -151,7 +145,7 @@ func TestInt_ResourceMonitorAlter(t *testing.T) { ctx := testContext(t) t.Run("when adding a new trigger", func(t *testing.T) { - resourceMonitor, resourceMonitorCleanup := createResourceMonitor(t, client) + resourceMonitor, resourceMonitorCleanup := testClientHelper().ResourceMonitor.CreateResourceMonitor(t) t.Cleanup(resourceMonitorCleanup) var oldNotifyTriggers []sdk.TriggerDefinition @@ -190,7 +184,7 @@ func TestInt_ResourceMonitorAlter(t *testing.T) { }) t.Run("when setting credit quota", func(t *testing.T) { - resourceMonitor, resourceMonitorCleanup := createResourceMonitor(t, client) + resourceMonitor, resourceMonitorCleanup := testClientHelper().ResourceMonitor.CreateResourceMonitor(t) t.Cleanup(resourceMonitorCleanup) creditQuota := 100 alterOptions := &sdk.AlterResourceMonitorOptions{ @@ -212,7 +206,7 @@ func TestInt_ResourceMonitorAlter(t *testing.T) { }) t.Run("when changing notify users", func(t *testing.T) { - resourceMonitor, resourceMonitorCleanup := createResourceMonitor(t, client) + resourceMonitor, resourceMonitorCleanup := testClientHelper().ResourceMonitor.CreateResourceMonitor(t) t.Cleanup(resourceMonitorCleanup) alterOptions := &sdk.AlterResourceMonitorOptions{ Set: &sdk.ResourceMonitorSet{ @@ -236,7 +230,7 @@ func TestInt_ResourceMonitorAlter(t *testing.T) { }) t.Run("when changing scheduling info", func(t *testing.T) { - resourceMonitor, resourceMonitorCleanup := createResourceMonitor(t, client) + resourceMonitor, resourceMonitorCleanup := testClientHelper().ResourceMonitor.CreateResourceMonitor(t) t.Cleanup(resourceMonitorCleanup) frequency, err := sdk.FrequencyFromString("NEVER") require.NoError(t, err) @@ -270,7 +264,7 @@ func TestInt_ResourceMonitorAlter(t *testing.T) { }) t.Run("all options together", func(t *testing.T) { - resourceMonitor, resourceMonitorCleanup := createResourceMonitor(t, client) + resourceMonitor, resourceMonitorCleanup := testClientHelper().ResourceMonitor.CreateResourceMonitor(t) t.Cleanup(resourceMonitorCleanup) newTriggers := make([]sdk.TriggerDefinition, 0) @@ -309,9 +303,10 @@ func TestInt_ResourceMonitorDrop(t *testing.T) { ctx := testContext(t) t.Run("when resource monitor exists", func(t *testing.T) { - resourceMonitor, _ := createResourceMonitor(t, client) + resourceMonitor, resourceMonitorCleanup := testClientHelper().ResourceMonitor.CreateResourceMonitor(t) + t.Cleanup(resourceMonitorCleanup) id := resourceMonitor.ID() - err := client.ResourceMonitors.Drop(ctx, id) + err := client.ResourceMonitors.Drop(ctx, id, &sdk.DropResourceMonitorOptions{}) require.NoError(t, err) _, err = client.ResourceMonitors.ShowByID(ctx, id) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) @@ -319,7 +314,7 @@ func TestInt_ResourceMonitorDrop(t *testing.T) { t.Run("when resource monitor does not exist", func(t *testing.T) { id := sdk.NewAccountObjectIdentifier("does_not_exist") - err := client.ResourceMonitors.Drop(ctx, id) + err := client.ResourceMonitors.Drop(ctx, id, &sdk.DropResourceMonitorOptions{}) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) }) } diff --git a/pkg/sdk/testint/roles_integration_test.go b/pkg/sdk/testint/roles_integration_test.go index 48e607e80b..e509249277 100644 --- a/pkg/sdk/testint/roles_integration_test.go +++ b/pkg/sdk/testint/roles_integration_test.go @@ -13,8 +13,10 @@ func TestInt_Roles(t *testing.T) { client := testClient(t) ctx := testContext(t) - tag, _ := createTag(t, client, testDb(t), testSchema(t)) - tag2, _ := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) + t.Cleanup(tagCleanup) + tag2, tagCleanup2 := testClientHelper().Tag.CreateTag(t) + t.Cleanup(tagCleanup2) t.Run("create no options", func(t *testing.T) { roleID := sdk.RandomAccountObjectIdentifier() 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 c1de3baab2..91c454aae2 100644 --- a/pkg/sdk/testint/row_access_policies_gen_integration_test.go +++ b/pkg/sdk/testint/row_access_policies_gen_integration_test.go @@ -199,7 +199,7 @@ func TestInt_RowAccessPolicies(t *testing.T) { }) t.Run("alter row access policy: set and unset tags", func(t *testing.T) { - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) rowAccessPolicy := createRowAccessPolicy(t) diff --git a/pkg/sdk/testint/schemas_integration_test.go b/pkg/sdk/testint/schemas_integration_test.go index 2fd4e5f1aa..10f03c2539 100644 --- a/pkg/sdk/testint/schemas_integration_test.go +++ b/pkg/sdk/testint/schemas_integration_test.go @@ -221,7 +221,7 @@ func TestInt_SchemasAlter(t *testing.T) { s, err := client.Schemas.ShowByID(ctx, schemaID) require.NoError(t, err) - tag, cleanupTag := createTag(t, client, testDb(t), s) + tag, cleanupTag := testClientHelper().Tag.CreateTagInSchema(t, s.ID()) t.Cleanup(cleanupTag) tagValue := "tag-value" diff --git a/pkg/sdk/testint/session_policies_gen_integration_test.go b/pkg/sdk/testint/session_policies_gen_integration_test.go index 61b1174d1d..a2db1bc29b 100644 --- a/pkg/sdk/testint/session_policies_gen_integration_test.go +++ b/pkg/sdk/testint/session_policies_gen_integration_test.go @@ -147,7 +147,7 @@ func TestInt_SessionPolicies(t *testing.T) { }) t.Run("set and unset tag", func(t *testing.T) { - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) name := random.String() diff --git a/pkg/sdk/testint/shares_integration_test.go b/pkg/sdk/testint/shares_integration_test.go index 792d142425..19891adecd 100644 --- a/pkg/sdk/testint/shares_integration_test.go +++ b/pkg/sdk/testint/shares_integration_test.go @@ -295,9 +295,9 @@ func TestInt_SharesAlter(t *testing.T) { require.NoError(t, err) }) - tagTest, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tagTest, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) - tagTest2, tagCleanup2 := createTag(t, client, testDb(t), testSchema(t)) + tagTest2, tagCleanup2 := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup2) tagAssociations := []sdk.TagAssociation{ { diff --git a/pkg/sdk/testint/stages_gen_integration_test.go b/pkg/sdk/testint/stages_gen_integration_test.go index 3d4a488c63..25bba24664 100644 --- a/pkg/sdk/testint/stages_gen_integration_test.go +++ b/pkg/sdk/testint/stages_gen_integration_test.go @@ -237,7 +237,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)) - tag, cleanupTag := createTag(t, client, testDb(t), testSchema(t)) + tag, cleanupTag := testClientHelper().Tag.CreateTag(t) t.Cleanup(cleanupTag) err := client.Stages.CreateInternal(ctx, sdk.NewCreateInternalStageRequest(id)) diff --git a/pkg/sdk/testint/storage_integration_gen_integration_test.go b/pkg/sdk/testint/storage_integration_gen_integration_test.go index 3a47c95d57..1d355ded9e 100644 --- a/pkg/sdk/testint/storage_integration_gen_integration_test.go +++ b/pkg/sdk/testint/storage_integration_gen_integration_test.go @@ -310,7 +310,7 @@ func TestInt_StorageIntegrations(t *testing.T) { t.Run("Alter - set and unset tags", func(t *testing.T) { id := createS3StorageIntegration(t) - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) err := client.StorageIntegrations.Alter(ctx, sdk.NewAlterStorageIntegrationRequest(id). diff --git a/pkg/sdk/testint/streams_gen_integration_test.go b/pkg/sdk/testint/streams_gen_integration_test.go index e4cd0ab81a..d1adc1fa6d 100644 --- a/pkg/sdk/testint/streams_gen_integration_test.go +++ b/pkg/sdk/testint/streams_gen_integration_test.go @@ -167,7 +167,7 @@ func TestInt_Streams(t *testing.T) { require.NoError(t, err) }) - tag, cleanupTag := createTag(t, client, db, schema) + tag, cleanupTag := testClientHelper().Tag.CreateTag(t) t.Cleanup(cleanupTag) _, err = client.SystemFunctions.GetTag(ctx, tag.ID(), id, sdk.ObjectTypeStream) diff --git a/pkg/sdk/testint/system_functions_integration_test.go b/pkg/sdk/testint/system_functions_integration_test.go index 853d5334d4..0371f69969 100644 --- a/pkg/sdk/testint/system_functions_integration_test.go +++ b/pkg/sdk/testint/system_functions_integration_test.go @@ -15,11 +15,11 @@ func TestInt_GetTag(t *testing.T) { client := testClient(t) ctx := testContext(t) - tagTest, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tagTest, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) t.Run("masking policy tag", func(t *testing.T) { - maskingPolicyTest, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) + maskingPolicyTest, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicy(t) t.Cleanup(maskingPolicyCleanup) tagValue := random.String() @@ -38,7 +38,7 @@ func TestInt_GetTag(t *testing.T) { }) t.Run("masking policy with no set tag", func(t *testing.T) { - maskingPolicyTest, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) + maskingPolicyTest, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicy(t) t.Cleanup(maskingPolicyCleanup) s, err := client.SystemFunctions.GetTag(ctx, tagTest.ID(), maskingPolicyTest.ID(), sdk.ObjectTypeMaskingPolicy) @@ -60,7 +60,7 @@ func TestInt_PipeStatus(t *testing.T) { t.Cleanup(stageCleanup) copyStatement := createPipeCopyStatement(t, table, stage) - pipe, pipeCleanup := createPipe(t, client, testDb(t), testSchema(t), random.AlphaN(20), copyStatement) + pipe, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, copyStatement) t.Cleanup(pipeCleanup) pipeExecutionState, err := client.SystemFunctions.PipeStatus(pipe.ID()) @@ -109,7 +109,7 @@ func TestInt_PipeForceResume(t *testing.T) { t.Cleanup(stageCleanup) copyStatement := createPipeCopyStatement(t, table, stage) - pipe, pipeCleanup := createPipe(t, client, testDb(t), testSchema(t), random.AlphaN(20), copyStatement) + pipe, pipeCleanup := testClientHelper().Pipe.CreatePipe(t, copyStatement) t.Cleanup(pipeCleanup) pipeExecutionState, err := client.SystemFunctions.PipeStatus(pipe.ID()) diff --git a/pkg/sdk/testint/tables_integration_test.go b/pkg/sdk/testint/tables_integration_test.go index dd465b6f2a..2a67278eb3 100644 --- a/pkg/sdk/testint/tables_integration_test.go +++ b/pkg/sdk/testint/tables_integration_test.go @@ -33,8 +33,10 @@ func TestInt_Table(t *testing.T) { require.NoError(t, err) } } - tag1, _ := createTag(t, client, database, schema) - tag2, _ := createTag(t, client, database, schema) + tag1, tagCleanup := testClientHelper().Tag.CreateTag(t) + t.Cleanup(tagCleanup) + tag2, tagCleanup2 := testClientHelper().Tag.CreateTag(t) + t.Cleanup(tagCleanup2) assertColumns := func(t *testing.T, expectedColumns []expectedColumn, createdColumns []informationSchemaColumns) { t.Helper() @@ -91,17 +93,10 @@ func TestInt_Table(t *testing.T) { }) t.Run("create table: complete optionals", func(t *testing.T) { - maskingPolicy, _ := createMaskingPolicyWithOptions(t, client, database, schema, []sdk.TableColumnSignature{ - { - Name: "col1", - Type: sdk.DataTypeVARCHAR, - }, - { - Name: "col2", - Type: sdk.DataTypeVARCHAR, - }, - }, sdk.DataTypeVARCHAR, "REPLACE('X', 1, 2)", nil) - table2, _ := testClientHelper().Table.CreateTable(t) + maskingPolicy, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicy(t) + t.Cleanup(maskingPolicyCleanup) + table2, table2Cleanup := testClientHelper().Table.CreateTable(t) + t.Cleanup(table2Cleanup) name := random.String() comment := random.String() @@ -169,12 +164,8 @@ func TestInt_Table(t *testing.T) { }) t.Run("create table as select", func(t *testing.T) { - maskingPolicy, _ := createMaskingPolicyWithOptions(t, client, database, schema, []sdk.TableColumnSignature{ - { - Name: "col1", - Type: sdk.DataTypeVARCHAR, - }, - }, sdk.DataTypeVARCHAR, "REPLACE('X', 1)", nil) + maskingPolicy, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicyIdentity(t, sdk.DataTypeVARCHAR) + t.Cleanup(maskingPolicyCleanup) columns := []sdk.TableAsSelectColumnRequest{ *sdk.NewTableAsSelectColumnRequest("COLUMN_3"). WithType_(sdk.Pointer(sdk.DataTypeVARCHAR)). @@ -213,7 +204,7 @@ func TestInt_Table(t *testing.T) { // TODO [SNOW-1007542]: fix this test, it should create two integer column but is creating 3 text ones instead t.Run("create table using template", func(t *testing.T) { - fileFormat, fileFormatCleanup := createFileFormat(t, client, schema.ID()) + fileFormat, fileFormatCleanup := testClientHelper().FileFormat.CreateFileFormat(t) t.Cleanup(fileFormatCleanup) stage, stageCleanup := testClientHelper().Stage.CreateStage(t) t.Cleanup(stageCleanup) @@ -534,12 +525,7 @@ func TestInt_Table(t *testing.T) { }) t.Run("alter table: unset masking policy", func(t *testing.T) { - maskingPolicy, maskingPolicyCleanup := createMaskingPolicyWithOptions(t, client, database, schema, []sdk.TableColumnSignature{ - { - Name: "col1", - Type: sdk.DataTypeVARCHAR, - }, - }, sdk.DataTypeVARCHAR, "REPLACE('X', 1)", nil) + maskingPolicy, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicyIdentity(t, sdk.DataTypeVARCHAR) t.Cleanup(maskingPolicyCleanup) name := random.String() diff --git a/pkg/sdk/testint/tags_integration_test.go b/pkg/sdk/testint/tags_integration_test.go index 01f52658c1..feeda3fbd8 100644 --- a/pkg/sdk/testint/tags_integration_test.go +++ b/pkg/sdk/testint/tags_integration_test.go @@ -169,7 +169,7 @@ func TestInt_Tags(t *testing.T) { }) t.Run("alter tag: set and unset masking policies", func(t *testing.T) { - policyTest, policyCleanup := createMaskingPolicy(t, client, databaseTest, schemaTest) + policyTest, policyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicyInSchema(t, schemaTest.ID()) t.Cleanup(policyCleanup) tag := createTagHandle(t) diff --git a/pkg/sdk/testint/tasks_gen_integration_test.go b/pkg/sdk/testint/tasks_gen_integration_test.go index 1f10d9bced..adb751b14d 100644 --- a/pkg/sdk/testint/tasks_gen_integration_test.go +++ b/pkg/sdk/testint/tasks_gen_integration_test.go @@ -330,7 +330,7 @@ func TestInt_Tasks(t *testing.T) { // }) t.Run("create task: with tags", func(t *testing.T) { - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) request := createTaskBasicRequest(t). @@ -410,7 +410,7 @@ func TestInt_Tasks(t *testing.T) { }) t.Run("alter task: set and unset tag", func(t *testing.T) { - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) task := createTask(t) diff --git a/pkg/sdk/testint/users_integration_test.go b/pkg/sdk/testint/users_integration_test.go index 18c9b516f4..923ebb9df0 100644 --- a/pkg/sdk/testint/users_integration_test.go +++ b/pkg/sdk/testint/users_integration_test.go @@ -80,7 +80,7 @@ func TestInt_UserCreate(t *testing.T) { client := testClient(t) ctx := testContext(t) - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) t.Run("test complete case", func(t *testing.T) { diff --git a/pkg/sdk/testint/views_gen_integration_test.go b/pkg/sdk/testint/views_gen_integration_test.go index 52ad9f93ff..e6638f5157 100644 --- a/pkg/sdk/testint/views_gen_integration_test.go +++ b/pkg/sdk/testint/views_gen_integration_test.go @@ -139,7 +139,7 @@ func TestInt_Views(t *testing.T) { rowAccessPolicyId, rowAccessPolicyCleanup := createRowAccessPolicy(t, client, testSchema(t)) t.Cleanup(rowAccessPolicyCleanup) - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) request := createViewBasicRequest(t). @@ -280,7 +280,7 @@ func TestInt_Views(t *testing.T) { }) t.Run("alter view: set and unset tag", func(t *testing.T) { - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) view := createView(t) @@ -318,7 +318,7 @@ func TestInt_Views(t *testing.T) { }) t.Run("alter view: set and unset masking policy", func(t *testing.T) { - maskingPolicy, maskingPolicyCleanup := createMaskingPolicyIdentity(t, client, testDb(t), testSchema(t), sdk.DataTypeNumber) + maskingPolicy, maskingPolicyCleanup := testClientHelper().MaskingPolicy.CreateMaskingPolicyIdentity(t, sdk.DataTypeNumber) t.Cleanup(maskingPolicyCleanup) view := createView(t) @@ -350,7 +350,7 @@ func TestInt_Views(t *testing.T) { }) t.Run("alter view: set and unset tags on column", func(t *testing.T) { - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) view := createView(t) diff --git a/pkg/sdk/testint/warehouses_integration_test.go b/pkg/sdk/testint/warehouses_integration_test.go index e517c3d13c..035c45cc70 100644 --- a/pkg/sdk/testint/warehouses_integration_test.go +++ b/pkg/sdk/testint/warehouses_integration_test.go @@ -56,9 +56,9 @@ func TestInt_WarehousesShow(t *testing.T) { func TestInt_WarehouseCreate(t *testing.T) { client := testClient(t) ctx := testContext(t) - tagTest, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tagTest, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) - tag2Test, tag2Cleanup := createTag(t, client, testDb(t), testSchema(t)) + tag2Test, tag2Cleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tag2Cleanup) t.Run("test complete", func(t *testing.T) { @@ -186,9 +186,9 @@ func TestInt_WarehouseAlter(t *testing.T) { client := testClient(t) ctx := testContext(t) - tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + tag, tagCleanup := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup) - tag2, tagCleanup2 := createTag(t, client, testDb(t), testSchema(t)) + tag2, tagCleanup2 := testClientHelper().Tag.CreateTag(t) t.Cleanup(tagCleanup2) t.Run("terraform acc test", func(t *testing.T) {