From f9c4f6a932073b3066a82519dc6633ca99566bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Budzy=C5=84ski?= Date: Tue, 29 Oct 2024 09:18:53 +0100 Subject: [PATCH] resolved comments --- .../objectassert/connection_snowflake_ext.go | 8 ++-- pkg/acceptance/helpers/connection_client.go | 2 +- pkg/sdk/connections_def.go | 12 +++-- pkg/sdk/connections_dto_builders_gen.go | 10 +---- pkg/sdk/connections_dto_gen.go | 6 +-- pkg/sdk/connections_gen.go | 15 +++---- pkg/sdk/connections_gen_test.go | 6 +-- pkg/sdk/connections_impl_gen.go | 4 +- pkg/sdk/connections_validations_gen.go | 6 +-- .../connections_gen_integration_test.go | 45 +++++++++++++------ 10 files changed, 56 insertions(+), 58 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/connection_snowflake_ext.go b/pkg/acceptance/bettertestspoc/assert/objectassert/connection_snowflake_ext.go index 4a585ed82c..4e237798ef 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/connection_snowflake_ext.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/connection_snowflake_ext.go @@ -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 }) diff --git a/pkg/acceptance/helpers/connection_client.go b/pkg/acceptance/helpers/connection_client.go index 5ea271f064..24fdf9384a 100644 --- a/pkg/acceptance/helpers/connection_client.go +++ b/pkg/acceptance/helpers/connection_client.go @@ -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) diff --git a/pkg/sdk/connections_def.go b/pkg/sdk/connections_def.go index 45a87feec4..39f583aff2 100644 --- a/pkg/sdk/connections_def.go +++ b/pkg/sdk/connections_def.go @@ -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"). diff --git a/pkg/sdk/connections_dto_builders_gen.go b/pkg/sdk/connections_dto_builders_gen.go index 30d75649c0..eb226b05a2 100644 --- a/pkg/sdk/connections_dto_builders_gen.go +++ b/pkg/sdk/connections_dto_builders_gen.go @@ -15,7 +15,7 @@ func (s *CreateConnectionRequest) WithIfNotExists(IfNotExists bool) *CreateConne return s } -func (s *CreateConnectionRequest) WithAsReplicaOf(AsReplicaOf AsReplicaOfRequest) *CreateConnectionRequest { +func (s *CreateConnectionRequest) WithAsReplicaOf(AsReplicaOf ExternalObjectIdentifier) *CreateConnectionRequest { s.AsReplicaOf = &AsReplicaOf return s } @@ -25,14 +25,6 @@ func (s *CreateConnectionRequest) WithComment(Comment string) *CreateConnectionR return s } -func NewAsReplicaOfRequest( - AsReplicaOf ExternalObjectIdentifier, -) *AsReplicaOfRequest { - s := AsReplicaOfRequest{} - s.AsReplicaOf = AsReplicaOf - return &s -} - func NewAlterConnectionRequest( name AccountObjectIdentifier, ) *AlterConnectionRequest { diff --git a/pkg/sdk/connections_dto_gen.go b/pkg/sdk/connections_dto_gen.go index 2225137072..1323bf0af3 100644 --- a/pkg/sdk/connections_dto_gen.go +++ b/pkg/sdk/connections_dto_gen.go @@ -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 diff --git a/pkg/sdk/connections_gen.go b/pkg/sdk/connections_gen.go index 9006c9c2a4..80885df87b 100644 --- a/pkg/sdk/connections_gen.go +++ b/pkg/sdk/connections_gen.go @@ -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. diff --git a/pkg/sdk/connections_gen_test.go b/pkg/sdk/connections_gen_test.go index 797beb8ee2..8ee6f7441a 100644 --- a/pkg/sdk/connections_gen_test.go +++ b/pkg/sdk/connections_gen_test.go @@ -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) }) @@ -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()) }) @@ -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()) }) diff --git a/pkg/sdk/connections_impl_gen.go b/pkg/sdk/connections_impl_gen.go index f70f37aa77..325141116e 100644 --- a/pkg/sdk/connections_impl_gen.go +++ b/pkg/sdk/connections_impl_gen.go @@ -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 diff --git a/pkg/sdk/connections_validations_gen.go b/pkg/sdk/connections_validations_gen.go index 52ecb38c1c..df6b4e1d0f 100644 --- a/pkg/sdk/connections_validations_gen.go +++ b/pkg/sdk/connections_validations_gen.go @@ -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...) } diff --git a/pkg/sdk/testint/connections_gen_integration_test.go b/pkg/sdk/testint/connections_gen_integration_test.go index 77ca241312..79573d1b6d 100644 --- a/pkg/sdk/testint/connections_gen_integration_test.go +++ b/pkg/sdk/testint/connections_gen_integration_test.go @@ -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) @@ -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(), @@ -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). @@ -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(), @@ -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() @@ -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(), @@ -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()) @@ -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(), @@ -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(), @@ -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) @@ -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) @@ -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) @@ -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() @@ -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() @@ -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)