Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into bcr-update
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jmichalak committed Apr 25, 2024
2 parents 30ee853 + 1f165bf commit 640823c
Show file tree
Hide file tree
Showing 88 changed files with 1,406 additions and 964 deletions.
2 changes: 1 addition & 1 deletion framework/provider/resource_monitor_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
58 changes: 58 additions & 0 deletions pkg/acceptance/helpers/alert_client.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
48 changes: 48 additions & 0 deletions pkg/acceptance/helpers/application_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 ApplicationClient struct {
context *TestClientContext
}

func NewApplicationClient(context *TestClientContext) *ApplicationClient {
return &ApplicationClient{
context: context,
}
}

func (c *ApplicationClient) client() sdk.Applications {
return c.context.client.Applications
}

func (c *ApplicationClient) CreateApplication(t *testing.T, packageId sdk.AccountObjectIdentifier, version string) (*sdk.Application, func()) {
t.Helper()
ctx := context.Background()

id := sdk.NewAccountObjectIdentifier(random.AlphaN(8))
err := c.client().Create(ctx, sdk.NewCreateApplicationRequest(id, packageId).WithVersion(sdk.NewApplicationVersionRequest().WithVersionAndPatch(sdk.NewVersionAndPatchRequest(version, nil))))
require.NoError(t, err)

application, err := c.client().ShowByID(ctx, id)
require.NoError(t, err)

return application, c.DropApplicationFunc(t, id)
}

func (c *ApplicationClient) DropApplicationFunc(t *testing.T, id sdk.AccountObjectIdentifier) func() {
t.Helper()
ctx := context.Background()

return func() {
err := c.client().Drop(ctx, sdk.NewDropApplicationRequest(id).WithIfExists(sdk.Bool(true)))
require.NoError(t, err)
}
}
58 changes: 58 additions & 0 deletions pkg/acceptance/helpers/application_package_client.go
Original file line number Diff line number Diff line change
@@ -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 ApplicationPackageClient struct {
context *TestClientContext
}

func NewApplicationPackageClient(context *TestClientContext) *ApplicationPackageClient {
return &ApplicationPackageClient{
context: context,
}
}

func (c *ApplicationPackageClient) client() sdk.ApplicationPackages {
return c.context.client.ApplicationPackages
}

func (c *ApplicationPackageClient) CreateApplicationPackage(t *testing.T) (*sdk.ApplicationPackage, func()) {
t.Helper()
ctx := context.Background()

id := sdk.NewAccountObjectIdentifier(random.AlphaN(8))
err := c.client().Create(ctx, sdk.NewCreateApplicationPackageRequest(id))
require.NoError(t, err)

applicationPackage, err := c.client().ShowByID(ctx, id)
require.NoError(t, err)

return applicationPackage, c.DropApplicationPackageFunc(t, id)
}

func (c *ApplicationPackageClient) DropApplicationPackageFunc(t *testing.T, id sdk.AccountObjectIdentifier) func() {
t.Helper()
ctx := context.Background()

return func() {
err := c.client().Drop(ctx, sdk.NewDropApplicationPackageRequest(id).WithIfExists(sdk.Bool(true)))
require.NoError(t, err)
}
}

func (c *ApplicationPackageClient) AddApplicationPackageVersion(t *testing.T, id sdk.AccountObjectIdentifier, stageId sdk.SchemaObjectIdentifier, versionName string) {
t.Helper()
ctx := context.Background()

using := "@" + stageId.FullyQualifiedName()

err := c.client().Alter(ctx, sdk.NewAlterApplicationPackageRequest(id).WithAddVersion(sdk.NewAddVersionRequest(using).WithVersionIdentifier(sdk.String(versionName))))
require.NoError(t, err)
}
4 changes: 2 additions & 2 deletions pkg/acceptance/helpers/database_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/acceptance/helpers/database_role_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand Down
59 changes: 59 additions & 0 deletions pkg/acceptance/helpers/dynamic_table_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package helpers

import (
"context"
"fmt"
"testing"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/stretchr/testify/require"
)

type DynamicTableClient struct {
context *TestClientContext
}

func NewDynamicTableClient(context *TestClientContext) *DynamicTableClient {
return &DynamicTableClient{
context: context,
}
}

func (c *DynamicTableClient) client() sdk.DynamicTables {
return c.context.client.DynamicTables
}

func (c *DynamicTableClient) CreateDynamicTable(t *testing.T, tableId sdk.SchemaObjectIdentifier) (*sdk.DynamicTable, func()) {
t.Helper()
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()) {
t.Helper()
id := sdk.NewSchemaObjectIdentifier(schemaId.DatabaseName(), schemaId.Name(), name)
targetLag := sdk.TargetLag{
MaximumDuration: sdk.String("2 minutes"),
}
query := fmt.Sprintf(`select "ID" from %s`, tableId.FullyQualifiedName())
comment := random.Comment()
ctx := context.Background()

err := c.client().Create(ctx, sdk.NewCreateDynamicTableRequest(id, warehouseId, targetLag, query).WithComment(&comment))
require.NoError(t, err)

dynamicTable, err := c.client().ShowByID(ctx, id)
require.NoError(t, err)

return dynamicTable, c.DropDynamicTableFunc(t, id)
}

func (c *DynamicTableClient) DropDynamicTableFunc(t *testing.T, id sdk.SchemaObjectIdentifier) func() {
t.Helper()
ctx := context.Background()

return func() {
err := c.client().Drop(ctx, sdk.NewDropDynamicTableRequest(id).WithIfExists(true))
require.NoError(t, err)
}
}
58 changes: 58 additions & 0 deletions pkg/acceptance/helpers/failover_group_client.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
56 changes: 56 additions & 0 deletions pkg/acceptance/helpers/file_format_client.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading

0 comments on commit 640823c

Please sign in to comment.