-
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.
<!-- Feel free to delete comments as you fill this in --> ## Info - `ignore edition check` has been removed since I can no longer execute an sql operation with it on snowflake - `Syntax error: unexpected 'IGNORE'` <!-- summary of changes --> ## Changes - connection sdk - connection snowflake object assertions ## Test Plan <!-- detail ways in which this PR has been tested or needs to be tested --> * [x] unit tests * [x] integration tests ## TODO * [uncomment integration tests for failover](https://snowflakecomputing.atlassian.net/browse/SNOW-1763442) * [Unskip integration tests](https://snowflakecomputing.atlassian.net/browse/SNOW-1002023) * Resource * Datasource ## References <!-- issues documentation links, etc --> * https://docs.snowflake.com/en/sql-reference/sql/create-connection
- Loading branch information
1 parent
5b7412f
commit bd11e0f
Showing
16 changed files
with
1,445 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
pkg/acceptance/bettertestspoc/assert/objectassert/connection_snowflake_ext.go
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 objectassert | ||
|
||
import ( | ||
"fmt" | ||
"slices" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" | ||
) | ||
|
||
func (c *ConnectionAssert) HasFailoverAllowedToAccounts(expected []string) *ConnectionAssert { | ||
c.AddAssertion(func(t *testing.T, o *sdk.Connection) error { | ||
t.Helper() | ||
if !slices.Equal(expected, o.FailoverAllowedToAccounts) { | ||
return fmt.Errorf("expected failover_allowed_to_accounts to be: %v; got: %v", expected, o.FailoverAllowedToAccounts) | ||
} | ||
return nil | ||
}) | ||
return c | ||
} | ||
|
||
func (c *ConnectionAssert) HasNoComment() *ConnectionAssert { | ||
c.AddAssertion(func(t *testing.T, o *sdk.Connection) error { | ||
t.Helper() | ||
if o.Comment != nil { | ||
return fmt.Errorf("expected comment to have nil; got: %s", *o.Comment) | ||
} | ||
return nil | ||
}) | ||
return c | ||
} | ||
|
||
func (c *ConnectionAssert) HasConnectionUrlNotEmpty() *ConnectionAssert { | ||
c.AddAssertion(func(t *testing.T, o *sdk.Connection) error { | ||
t.Helper() | ||
if o.ConnectionUrl == "" { | ||
return fmt.Errorf("expected connection url not empty, got: %s", o.ConnectionUrl) | ||
} | ||
return nil | ||
}) | ||
|
||
return c | ||
} | ||
|
||
func (c *ConnectionAssert) HasPrimaryIdentifier(expected sdk.ExternalObjectIdentifier) *ConnectionAssert { | ||
c.AddAssertion(func(t *testing.T, o *sdk.Connection) error { | ||
t.Helper() | ||
expectedString := strings.ReplaceAll(expected.FullyQualifiedName(), `"`, "") | ||
if o.Primary != expectedString { | ||
return fmt.Errorf("expected primary identifier: %v; got: %v", expectedString, o.Primary) | ||
} | ||
return nil | ||
}) | ||
return c | ||
} |
145 changes: 145 additions & 0 deletions
145
pkg/acceptance/bettertestspoc/assert/objectassert/connection_snowflake_gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,72 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type ConnectionClient struct { | ||
context *TestClientContext | ||
ids *IdsGenerator | ||
} | ||
|
||
func NewConnectionClient(context *TestClientContext, idsGenerator *IdsGenerator) *ConnectionClient { | ||
return &ConnectionClient{ | ||
context: context, | ||
ids: idsGenerator, | ||
} | ||
} | ||
|
||
func (c *ConnectionClient) client() sdk.Connections { | ||
return c.context.client.Connections | ||
} | ||
|
||
func (c *ConnectionClient) Create(t *testing.T, id sdk.AccountObjectIdentifier) (*sdk.Connection, func()) { | ||
t.Helper() | ||
ctx := context.Background() | ||
request := sdk.NewCreateConnectionRequest(id) | ||
err := c.client().Create(ctx, request) | ||
require.NoError(t, err) | ||
connection, err := c.client().ShowByID(ctx, id) | ||
require.NoError(t, err) | ||
return connection, c.DropFunc(t, id) | ||
} | ||
|
||
func (c *ConnectionClient) CreateReplication(t *testing.T, id sdk.AccountObjectIdentifier, replicaOf sdk.ExternalObjectIdentifier) (*sdk.Connection, func()) { | ||
t.Helper() | ||
ctx := context.Background() | ||
request := sdk.NewCreateConnectionRequest(id).WithAsReplicaOf(replicaOf) | ||
err := c.client().Create(ctx, request) | ||
require.NoError(t, err) | ||
connection, err := c.client().ShowByID(ctx, id) | ||
require.NoError(t, err) | ||
return connection, c.DropFunc(t, id) | ||
} | ||
|
||
func (c *ConnectionClient) Alter(t *testing.T, id sdk.AccountObjectIdentifier, req *sdk.AlterConnectionRequest) { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
err := c.client().Alter(ctx, req) | ||
require.NoError(t, err) | ||
} | ||
|
||
func (c *ConnectionClient) DropFunc(t *testing.T, id sdk.AccountObjectIdentifier) func() { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
return func() { | ||
err := c.client().Drop(ctx, sdk.NewDropConnectionRequest(id).WithIfExists(true)) | ||
require.NoError(t, err) | ||
} | ||
} | ||
|
||
func (c *ConnectionClient) Show(t *testing.T, id sdk.AccountObjectIdentifier) (*sdk.Connection, error) { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
return c.client().ShowByID(ctx, id) | ||
} |
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
Oops, something went wrong.