-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
9475e35
commit 1f165bf
Showing
74 changed files
with
870 additions
and
599 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
Oops, something went wrong.