-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Improve tags integration tests (#3193)
<!-- Feel free to delete comments as you fill this in --> - move all of the set/unset tags integration tests to one place - add necessary helper clients - return error on getting tag of a resource that is not supported <!-- summary of changes --> ## Test Plan <!-- detail ways in which this PR has been tested or needs to be tested --> <!-- add more below if you think they are relevant --> * [x] integration tests ## TODO - rework tag and tag_association resources - add tags data source - support empty tag values in GetTag
- Loading branch information
1 parent
5ec9c86
commit 7736e0a
Showing
48 changed files
with
1,366 additions
and
1,579 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type EventTableClient struct { | ||
context *TestClientContext | ||
ids *IdsGenerator | ||
} | ||
|
||
func NewEventTableClient(context *TestClientContext, idsGenerator *IdsGenerator) *EventTableClient { | ||
return &EventTableClient{ | ||
context: context, | ||
ids: idsGenerator, | ||
} | ||
} | ||
|
||
func (c *EventTableClient) client() sdk.EventTables { | ||
return c.context.client.EventTables | ||
} | ||
|
||
func (c *EventTableClient) Create(t *testing.T) (*sdk.EventTable, func()) { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
id := c.ids.RandomSchemaObjectIdentifier() | ||
err := c.client().Create(ctx, sdk.NewCreateEventTableRequest(id)) | ||
require.NoError(t, err) | ||
|
||
integration, err := c.client().ShowByID(ctx, id) | ||
require.NoError(t, err) | ||
|
||
return integration, c.DropFunc(t, id) | ||
} | ||
|
||
func (c *EventTableClient) DropFunc(t *testing.T, id sdk.SchemaObjectIdentifier) func() { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
return func() { | ||
err := c.client().Drop(ctx, sdk.NewDropEventTableRequest(id).WithIfExists(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,54 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type NotificationIntegrationClient struct { | ||
context *TestClientContext | ||
ids *IdsGenerator | ||
} | ||
|
||
func NewNotificationIntegrationClient(context *TestClientContext, idsGenerator *IdsGenerator) *NotificationIntegrationClient { | ||
return &NotificationIntegrationClient{ | ||
context: context, | ||
ids: idsGenerator, | ||
} | ||
} | ||
|
||
func (c *NotificationIntegrationClient) client() sdk.NotificationIntegrations { | ||
return c.context.client.NotificationIntegrations | ||
} | ||
|
||
func (c *NotificationIntegrationClient) Create(t *testing.T) (*sdk.NotificationIntegration, func()) { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
id := c.ids.RandomAccountObjectIdentifier() | ||
|
||
// TODO [SNOW-1007539]: use email of our service user | ||
request := sdk.NewCreateNotificationIntegrationRequest(id, true). | ||
WithEmailParams(sdk.NewEmailParamsRequest().WithAllowedRecipients([]sdk.NotificationIntegrationAllowedRecipient{{Email: "artur.sawicki@snowflake.com"}})) | ||
|
||
err := c.client().Create(ctx, request) | ||
require.NoError(t, err) | ||
|
||
integration, err := c.client().ShowByID(ctx, id) | ||
require.NoError(t, err) | ||
|
||
return integration, c.DropFunc(t, id) | ||
} | ||
|
||
func (c *NotificationIntegrationClient) DropFunc(t *testing.T, id sdk.AccountObjectIdentifier) func() { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
return func() { | ||
err := c.client().Drop(ctx, sdk.NewDropNotificationIntegrationRequest(id).WithIfExists(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type StorageIntegrationClient struct { | ||
context *TestClientContext | ||
ids *IdsGenerator | ||
} | ||
|
||
func NewStorageIntegrationClient(context *TestClientContext, idsGenerator *IdsGenerator) *StorageIntegrationClient { | ||
return &StorageIntegrationClient{ | ||
context: context, | ||
ids: idsGenerator, | ||
} | ||
} | ||
|
||
func (c *StorageIntegrationClient) client() sdk.StorageIntegrations { | ||
return c.context.client.StorageIntegrations | ||
} | ||
|
||
func (c *StorageIntegrationClient) CreateS3(t *testing.T, awsBucketUrl, awsRoleArn string) (*sdk.StorageIntegration, func()) { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
allowedLocations := func(prefix string) []sdk.StorageLocation { | ||
return []sdk.StorageLocation{ | ||
{ | ||
Path: prefix + "/allowed-location", | ||
}, | ||
{ | ||
Path: prefix + "/allowed-location2", | ||
}, | ||
} | ||
} | ||
s3AllowedLocations := allowedLocations(awsBucketUrl) | ||
|
||
blockedLocations := func(prefix string) []sdk.StorageLocation { | ||
return []sdk.StorageLocation{ | ||
{ | ||
Path: prefix + "/blocked-location", | ||
}, | ||
{ | ||
Path: prefix + "/blocked-location2", | ||
}, | ||
} | ||
} | ||
s3BlockedLocations := blockedLocations(awsBucketUrl) | ||
|
||
id := c.ids.RandomAccountObjectIdentifier() | ||
req := sdk.NewCreateStorageIntegrationRequest(id, true, s3AllowedLocations). | ||
WithIfNotExists(sdk.Bool(true)). | ||
WithS3StorageProviderParams(sdk.NewS3StorageParamsRequest(awsRoleArn)). | ||
WithStorageBlockedLocations(s3BlockedLocations). | ||
WithComment(sdk.String("some comment")) | ||
|
||
err := c.client().Create(ctx, req) | ||
require.NoError(t, err) | ||
|
||
integration, err := c.client().ShowByID(ctx, id) | ||
require.NoError(t, err) | ||
|
||
return integration, c.DropFunc(t, id) | ||
} | ||
|
||
func (c *StorageIntegrationClient) DropFunc(t *testing.T, id sdk.AccountObjectIdentifier) func() { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
return func() { | ||
err := c.client().Drop(ctx, sdk.NewDropStorageIntegrationRequest(id).WithIfExists(sdk.Bool(true))) | ||
require.NoError(t, err) | ||
} | ||
} |
Oops, something went wrong.