Skip to content

Commit

Permalink
resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-fbudzynski committed Oct 29, 2024
1 parent d7b13de commit f9c4f6a
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ func (c *ConnectionAssert) HasConnectionUrlNotEmpty() *ConnectionAssert {
return c
}

func (c *ConnectionAssert) HasPrimaryIdentifier(expected string) *ConnectionAssert {
func (c *ConnectionAssert) HasPrimaryIdentifier(expected sdk.ExternalObjectIdentifier) *ConnectionAssert {
c.AddAssertion(func(t *testing.T, o *sdk.Connection) error {
t.Helper()
expected = strings.ReplaceAll(expected, `"`, "")
if o.Primary != expected {
return fmt.Errorf("expected primary identifier: %v; got: %v", expected, o.Primary)
expectedString := strings.ReplaceAll(expected.FullyQualifiedName(), `"`, "")
if o.Primary != expectedString {
return fmt.Errorf("expected primary identifier: %v; got: %v", expectedString, o.Primary)
}
return nil
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/acceptance/helpers/connection_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *ConnectionClient) Create(t *testing.T, id sdk.AccountObjectIdentifier)
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(sdk.AsReplicaOfRequest{AsReplicaOf: replicaOf})
request := sdk.NewCreateConnectionRequest(id).WithAsReplicaOf(replicaOf)
err := c.client().Create(ctx, request)
require.NoError(t, err)
connection, err := c.client().ShowByID(ctx, id)
Expand Down
12 changes: 5 additions & 7 deletions pkg/sdk/connections_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ var ConnectionDef = g.NewInterface(
SQL("CONNECTION").
IfNotExists().
Name().
OptionalQueryStructField(
OptionalIdentifier(
"AsReplicaOf",
g.NewQueryStruct("AsReplicaOf").
Identifier("AsReplicaOf", g.KindOfT[ExternalObjectIdentifier](), g.IdentifierOptions().Required().SQL("AS REPLICA OF")).
WithValidation(g.ValidIdentifier, "AsReplicaOf"),
g.IdentifierOptions(),
).
g.KindOfT[ExternalObjectIdentifier](),
g.IdentifierOptions().Required().SQL("AS REPLICA OF")).
OptionalComment().
WithValidation(g.ValidIdentifier, "name"),
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ValidIdentifierIfSet, "AsReplicaOf"),
).AlterOperation(
"https://docs.snowflake.com/en/sql-reference/sql/alter-connection",
g.NewQueryStruct("Alter").
Expand Down
10 changes: 1 addition & 9 deletions pkg/sdk/connections_dto_builders_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions pkg/sdk/connections_dto_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ var (
type CreateConnectionRequest struct {
IfNotExists *bool
name AccountObjectIdentifier // required
AsReplicaOf *AsReplicaOfRequest
AsReplicaOf *ExternalObjectIdentifier
Comment *string
}

type AsReplicaOfRequest struct {
AsReplicaOf ExternalObjectIdentifier // required
}

type AlterConnectionRequest struct {
IfExists *bool
name AccountObjectIdentifier // required
Expand Down
15 changes: 6 additions & 9 deletions pkg/sdk/connections_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ type Connections interface {

// CreateConnectionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-connection.
type CreateConnectionOptions struct {
create bool `ddl:"static" sql:"CREATE"`
connection bool `ddl:"static" sql:"CONNECTION"`
IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"`
name AccountObjectIdentifier `ddl:"identifier"`
AsReplicaOf *AsReplicaOf `ddl:"identifier"`
Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"`
}
type AsReplicaOf struct {
AsReplicaOf ExternalObjectIdentifier `ddl:"identifier" sql:"AS REPLICA OF"`
create bool `ddl:"static" sql:"CREATE"`
connection bool `ddl:"static" sql:"CONNECTION"`
IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"`
name AccountObjectIdentifier `ddl:"identifier"`
AsReplicaOf *ExternalObjectIdentifier `ddl:"identifier" sql:"AS REPLICA OF"`
Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"`
}

// AlterConnectionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/alter-connection.
Expand Down
6 changes: 3 additions & 3 deletions pkg/sdk/connections_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestConnections_Create(t *testing.T) {
t.Run("validation: valid identifier for [opts.ReplicaOf]", func(t *testing.T) {
opts := defaultOpts()
opts.name = id
opts.AsReplicaOf = &AsReplicaOf{emptyExternalObjectIdentifier}
opts.AsReplicaOf = &emptyExternalObjectIdentifier
assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier)
})

Expand All @@ -46,7 +46,7 @@ func TestConnections_Create(t *testing.T) {
externalId := randomExternalObjectIdentifier()
opts := defaultOpts()
opts.name = id
opts.AsReplicaOf = &AsReplicaOf{externalId}
opts.AsReplicaOf = &externalId
assertOptsValidAndSQLEquals(t, opts, "CREATE CONNECTION %s AS REPLICA OF %s", id.FullyQualifiedName(), externalId.FullyQualifiedName())
})

Expand All @@ -55,7 +55,7 @@ func TestConnections_Create(t *testing.T) {
opts := defaultOpts()
opts.name = id
opts.IfNotExists = Bool(true)
opts.AsReplicaOf = &AsReplicaOf{externalId}
opts.AsReplicaOf = &externalId
opts.Comment = String("comment")
assertOptsValidAndSQLEquals(t, opts, "CREATE CONNECTION IF NOT EXISTS %s AS REPLICA OF %s COMMENT = 'comment'", id.FullyQualifiedName(), externalId.FullyQualifiedName())
})
Expand Down
4 changes: 1 addition & 3 deletions pkg/sdk/connections_impl_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ func (r *CreateConnectionRequest) toOpts() *CreateConnectionOptions {
}

if r.AsReplicaOf != nil {
opts.AsReplicaOf = &AsReplicaOf{
AsReplicaOf: r.AsReplicaOf.AsReplicaOf,
}
opts.AsReplicaOf = r.AsReplicaOf
}

return opts
Expand Down
6 changes: 2 additions & 4 deletions pkg/sdk/connections_validations_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ func (opts *CreateConnectionOptions) validate() error {
if !ValidObjectIdentifier(opts.name) {
errs = append(errs, ErrInvalidObjectIdentifier)
}
if valueSet(opts.AsReplicaOf) {
if !ValidObjectIdentifier(opts.AsReplicaOf.AsReplicaOf) {
errs = append(errs, ErrInvalidObjectIdentifier)
}
if opts.AsReplicaOf != nil && !ValidObjectIdentifier(opts.AsReplicaOf) {
errs = append(errs, ErrInvalidObjectIdentifier)
}
return JoinErrors(errs...)
}
Expand Down
45 changes: 32 additions & 13 deletions pkg/sdk/testint/connections_gen_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func TestInt_Connections(t *testing.T) {
accountId := testClientHelper().Account.GetAccountIdentifier(t)

t.Run("Create minimal", func(t *testing.T) {
// TODO: [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed
_ = testenvs.GetOrSkipTest(t, testenvs.TestFailoverGroups)

id := testClientHelper().Ids.RandomAccountObjectIdentifier()
require.NoError(t, err)

Expand All @@ -39,7 +42,7 @@ func TestInt_Connections(t *testing.T) {
HasName(id.Name()).
HasNoComment().
HasIsPrimary(true).
HasPrimaryIdentifier(externalObjectIdentifier.FullyQualifiedName()).
HasPrimaryIdentifier(externalObjectIdentifier).
HasFailoverAllowedToAccounts(
[]string{
accountId.Name(),
Expand All @@ -56,6 +59,9 @@ func TestInt_Connections(t *testing.T) {
})

t.Run("Create all options", func(t *testing.T) {
// TODO: [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed
_ = testenvs.GetOrSkipTest(t, testenvs.TestFailoverGroups)

id := testClientHelper().Ids.RandomAccountObjectIdentifier()
err := client.Connections.Create(ctx, sdk.NewCreateConnectionRequest(id).
WithIfNotExists(true).
Expand All @@ -70,7 +76,7 @@ func TestInt_Connections(t *testing.T) {
HasName(id.Name()).
HasComment("test comment for connection").
HasIsPrimary(true).
HasPrimaryIdentifier(externalObjectIdentifier.FullyQualifiedName()).
HasPrimaryIdentifier(externalObjectIdentifier).
HasFailoverAllowedToAccounts(
[]string{
accountId.Name(),
Expand All @@ -87,7 +93,7 @@ func TestInt_Connections(t *testing.T) {
})

t.Run("Alter enable failover", func(t *testing.T) {
// TODO: [SNOW-1763442]: Unskip; Business Critical Snowflake Edition needed
// TODO: [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed
_ = testenvs.GetOrSkipTest(t, testenvs.TestFailoverGroups)

id := testClientHelper().Ids.RandomAccountObjectIdentifier()
Expand Down Expand Up @@ -117,7 +123,7 @@ func TestInt_Connections(t *testing.T) {
HasName(id.Name()).
HasNoComment().
HasIsPrimary(true).
HasPrimaryIdentifier(externalObjectIdentifier.FullyQualifiedName()).
HasPrimaryIdentifier(externalObjectIdentifier).
HasFailoverAllowedToAccounts(
[]string{
accountId.Name(),
Expand All @@ -136,11 +142,9 @@ func TestInt_Connections(t *testing.T) {
})

t.Run("Create as replica of", func(t *testing.T) {
// TODO: [SNOW-1763442]: Unskip; Business Critical Snowflake Edition needed
// TODO: [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed
_ = testenvs.GetOrSkipTest(t, testenvs.TestFailoverGroups)

id := testClientHelper().Ids.RandomAccountObjectIdentifier()
_ = id
secondaryAccountId := secondaryTestClientHelper().Ids.AccountIdentifierWithLocator()

primaryConn, connectionCleanup := testClientHelper().Connection.Create(t, testClientHelper().Ids.RandomAccountObjectIdentifier())
Expand Down Expand Up @@ -176,7 +180,7 @@ func TestInt_Connections(t *testing.T) {
HasName(id.Name()).
HasNoComment().
HasIsPrimary(false).
HasPrimaryIdentifier(externalObjectIdentifier.FullyQualifiedName()).
HasPrimaryIdentifier(externalObjectIdentifier).
HasFailoverAllowedToAccounts(
[]string{
accountId.Name(),
Expand Down Expand Up @@ -227,7 +231,7 @@ func TestInt_Connections(t *testing.T) {
// Assert that promotion for other account has been disabled
externalObjectIdentifier := sdk.NewExternalObjectIdentifier(accountId, id)
assertions.AssertThatObject(t, objectassert.Connection(t, primaryConn.ID()).
HasPrimaryIdentifier(externalObjectIdentifier.FullyQualifiedName()).
HasPrimaryIdentifier(externalObjectIdentifier).
HasFailoverAllowedToAccounts(
[]string{
accountId.Name(),
Expand All @@ -236,14 +240,14 @@ func TestInt_Connections(t *testing.T) {
)

// Try to create repllication on secondary account
err = secondaryClient.Connections.Create(ctx, sdk.NewCreateConnectionRequest(id).
WithAsReplicaOf(sdk.AsReplicaOfRequest{
AsReplicaOf: externalObjectIdentifier,
}))
err = secondaryClient.Connections.Create(ctx, sdk.NewCreateConnectionRequest(id).WithAsReplicaOf(externalObjectIdentifier))
require.ErrorContains(t, err, "This account is not authorized to create a secondary connection of this primary connection")
})

t.Run("Alter comment", func(t *testing.T) {
// TODO: [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed
_ = testenvs.GetOrSkipTest(t, testenvs.TestFailoverGroups)

id := testClientHelper().Ids.RandomAccountObjectIdentifier()
_, connectionCleanup := testClientHelper().Connection.Create(t, id)
t.Cleanup(connectionCleanup)
Expand Down Expand Up @@ -272,6 +276,9 @@ func TestInt_Connections(t *testing.T) {
})

t.Run("Drop", func(t *testing.T) {
// TODO: [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed
_ = testenvs.GetOrSkipTest(t, testenvs.TestFailoverGroups)

id := testClientHelper().Ids.RandomAccountObjectIdentifier()
_, connectionCleanup := testClientHelper().Connection.Create(t, id)
t.Cleanup(connectionCleanup)
Expand All @@ -289,6 +296,9 @@ func TestInt_Connections(t *testing.T) {
})

t.Run("Drop with if exists", func(t *testing.T) {
// TODO: [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed
_ = testenvs.GetOrSkipTest(t, testenvs.TestFailoverGroups)

err = client.Connections.Drop(ctx, sdk.NewDropConnectionRequest(NonExistingAccountObjectIdentifier))
require.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized)

Expand All @@ -297,6 +307,9 @@ func TestInt_Connections(t *testing.T) {
})

t.Run("Show", func(t *testing.T) {
// TODO: [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed
_ = testenvs.GetOrSkipTest(t, testenvs.TestFailoverGroups)

id1 := testClientHelper().Ids.RandomAccountObjectIdentifier()
id2 := testClientHelper().Ids.RandomAccountObjectIdentifier()

Expand All @@ -313,6 +326,9 @@ func TestInt_Connections(t *testing.T) {
})

t.Run("Show with Like", func(t *testing.T) {
// TODO: [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed
_ = testenvs.GetOrSkipTest(t, testenvs.TestFailoverGroups)

id1 := testClientHelper().Ids.RandomAccountObjectIdentifier()
id2 := testClientHelper().Ids.RandomAccountObjectIdentifier()

Expand All @@ -332,6 +348,9 @@ func TestInt_Connections(t *testing.T) {
})

t.Run("ShowByID", func(t *testing.T) {
// TODO: [SNOW-1002023]: Unskip; Business Critical Snowflake Edition needed
_ = testenvs.GetOrSkipTest(t, testenvs.TestFailoverGroups)

id := testClientHelper().Ids.RandomAccountObjectIdentifier()

_, connectionCleanup := testClientHelper().Connection.Create(t, id)
Expand Down

0 comments on commit f9c4f6a

Please sign in to comment.