Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Aug 22, 2024
1 parent 3f07fef commit 3221374
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 38 deletions.
59 changes: 39 additions & 20 deletions pkg/resources/grant_ownership_identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ func TestParseGrantOwnershipId(t *testing.T) {
},
},
},
{
Name: "grant ownership on all tables in database to account role - empty database id",
Identifier: `ToAccountRole|"account-role"||OnAll|TABLES|InDatabase|`,
Expected: GrantOwnershipId{
GrantOwnershipTargetRoleKind: ToAccountGrantOwnershipTargetRoleKind,
AccountRoleName: sdk.NewAccountObjectIdentifier("account-role"),
Kind: OnAllGrantOwnershipKind,
Data: &BulkOperationGrantData{
ObjectNamePlural: sdk.PluralObjectTypeTables,
Kind: InDatabaseBulkOperationGrantKind,
Database: sdk.Pointer(sdk.NewAccountObjectIdentifier("")),
},
},
},
{
Name: "grant ownership on all tables in schema to account role",
Identifier: `ToAccountRole|"account-role"||OnAll|TABLES|InSchema|"database-name"."schema-name"`,
Expand Down Expand Up @@ -115,6 +129,21 @@ func TestParseGrantOwnershipId(t *testing.T) {
},
},
},
{
Name: "grant ownership on future tables in database to account role - empty database",
Identifier: `ToAccountRole|"account-role"|COPY|OnFuture|TABLES|InDatabase|`,
Expected: GrantOwnershipId{
GrantOwnershipTargetRoleKind: ToAccountGrantOwnershipTargetRoleKind,
AccountRoleName: sdk.NewAccountObjectIdentifier("account-role"),
OutboundPrivilegesBehavior: sdk.Pointer(CopyOutboundPrivilegesBehavior),
Kind: OnFutureGrantOwnershipKind,
Data: &BulkOperationGrantData{
ObjectNamePlural: sdk.PluralObjectTypeTables,
Kind: InDatabaseBulkOperationGrantKind,
Database: sdk.Pointer(sdk.NewAccountObjectIdentifier("")),
},
},
},
{
Name: "grant ownership on future tables in schema to account role",
Identifier: `ToAccountRole|"account-role"|COPY|OnFuture|TABLES|InSchema|"database-name"."schema-name"`,
Expand Down Expand Up @@ -188,16 +217,11 @@ func TestParseGrantOwnershipId(t *testing.T) {
Identifier: `ToAccountRole|"account-role"|COPY|OnAll|TABLES|InvalidOption|"some-identifier"`,
Error: "invalid BulkOperationGrantKind: InvalidOption, valid options are InDatabase | InSchema",
},
// {
// Name: "TODO(SNOW-999049 - no error because of bad identifiers): validation: OnAll in database - missing database identifier",
// Identifier: `ToAccountRole|"account-role"|COPY|OnAll|InvalidTarget|InDatabase|`,
// Error: "TODO",
// },
// {
// Name: "TODO(SNOW-999049 - panic because of bad identifiers): validation: OnAll in database - missing schema identifier",
// Identifier: `ToAccountRole|"account-role"|COPY|OnAll|InvalidTarget|InSchema|`,
// Error: "TODO",
// },
{
Name: "validation: OnAll in database - missing schema identifier",
Identifier: `ToAccountRole|"account-role"|COPY|OnAll|InvalidTarget|InSchema|`,
Error: "incompatible identifier: ",
},
{
Name: "validation: not enough parts for OnFuture kind",
Identifier: `ToAccountRole|"account-role"|COPY|OnFuture|TABLES`,
Expand All @@ -208,16 +232,11 @@ func TestParseGrantOwnershipId(t *testing.T) {
Identifier: `ToAccountRole|"account-role"|COPY|OnFuture|TABLES|InvalidOption|"some-identifier"`,
Error: "invalid BulkOperationGrantKind: InvalidOption, valid options are InDatabase | InSchema",
},
// {
// Name: "TODO(SNOW-999049 - no error because of bad identifiers): validation: OnFuture in database - missing database identifier",
// Identifier: `ToAccountRole|"account-role"|COPY|OnFuture|InvalidTarget|InDatabase|`,
// Error: "TODO",
// },
// {
// Name: "TODO(SNOW-999049 - panic because of bad identifiers): validation: OnFuture in database - missing schema identifier",
// Identifier: `ToAccountRole|"account-role"|COPY|OnFuture|InvalidTarget|InSchema|`,
// Error: "TODO",
// },
{
Name: "validation: OnFuture in database - missing schema identifier",
Identifier: `ToAccountRole|"account-role"|COPY|OnFuture|InvalidTarget|InSchema|`,
Error: "incompatible identifier: ",
},
}

for _, tt := range testCases {
Expand Down
6 changes: 4 additions & 2 deletions pkg/resources/grant_ownership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestGetOnObjectIdentifier(t *testing.T) {
Name: "validation - valid identifier",
ObjectType: sdk.ObjectTypeDatabase,
ObjectName: "to.many.parts.in.this.identifier",
Error: "unexpected number of parts 6 in identifier to.many.parts.in.this.identifier, expected 1 in a form of \"<account_object_name>\"",
Expected: sdk.NewAccountObjectIdentifier("to.many.parts.in.this.identifier"),
},
{
Name: "validation - unsupported type",
Expand Down Expand Up @@ -420,7 +420,9 @@ func TestValidAccountRoleNameGetOwnershipGrantTo(t *testing.T) {
{
Name: "account role name - with dots",
AccountRole: sdk.String("account.role.with.dots"),
Error: "unexpected number of parts 4 in identifier account.role.with.dots, expected 1 in a form of \"<account_object_name>\"",
Expected: sdk.OwnershipGrantTo{
AccountRoleName: sdk.Pointer(sdk.NewAccountObjectIdentifier("account.role.with.dots")),
},
},
{
Name: "account role name - with dots quoted",
Expand Down
16 changes: 11 additions & 5 deletions pkg/resources/grant_privileges_to_account_role_identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ func TestParseGrantPrivilegesToAccountRoleId(t *testing.T) {
Data: new(OnAccountGrantData),
},
},
{
Name: "grant account role on account - empty role name",
Identifier: `|false|false|CREATE DATABASE,CREATE USER|OnAccount`,
Expected: GrantPrivilegesToAccountRoleId{
RoleName: sdk.NewAccountObjectIdentifier(""),
WithGrantOption: false,
Privileges: []string{"CREATE DATABASE", "CREATE USER"},
Kind: OnAccountAccountRoleGrantKind,
Data: new(OnAccountGrantData),
},
},
{
Name: "grant account role on account - always apply with grant option",
Identifier: `"account-role"|true|true|CREATE DATABASE,CREATE USER|OnAccount`,
Expand Down Expand Up @@ -320,11 +331,6 @@ func TestParseGrantPrivilegesToAccountRoleId(t *testing.T) {
Identifier: `"account-role"|false||ALL PRIVILEGES|OnAccount`,
Error: `invalid AlwaysApply value: , should be either "true" or "false"`,
},
{
Name: "validation: grant account role empty role name",
Identifier: `|false|false|ALL PRIVILEGES|OnAccount`,
Error: "incompatible identifier: ",
},
{
Name: "validation: account role empty type",
Identifier: `"account-role"|false|false|ALL PRIVILEGES||"on-database-name"`,
Expand Down
19 changes: 12 additions & 7 deletions pkg/resources/grant_privileges_to_share_identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ func TestParseGrantPrivilegesToShareId(t *testing.T) {
Identifier: sdk.NewAccountObjectIdentifier("on-database-name"),
},
},
{
Name: "grant privileges on database to share - database identifier with dots",
Identifier: `"share-name"|SELECT|OnDatabase|"one.two.three.four.five.six.seven.eight.nine.ten"`,
Expected: GrantPrivilegesToShareId{
ShareName: sdk.NewAccountObjectIdentifier("share-name"),
Privileges: []string{"SELECT"},
Kind: OnDatabaseShareGrantKind,
Identifier: sdk.NewAccountObjectIdentifier("one.two.three.four.five.six.seven.eight.nine.ten"),
},
},
{
Name: "grant privileges on schema to share",
Identifier: `"share-name"|USAGE|OnSchema|"on-database-name"."on-schema-name"`,
Expand Down Expand Up @@ -109,15 +119,10 @@ func TestParseGrantPrivilegesToShareId(t *testing.T) {
Identifier: `"share-name"|SELECT|OnSomething|"object-name"`,
Error: `unexpected share grant kind: OnSomething`,
},
{
Name: "validation: invalid identifier",
Identifier: `"share-name"|SELECT|OnDatabase|one.two.three.four.five.six.seven.eight.nine.ten`,
Error: `unexpected number of parts 10 in identifier one.two.three.four.five.six.seven.eight.nine.ten, expected 1 in a form of "<account_object_name>"`,
},
{
Name: "validation: invalid account object identifier",
Identifier: `"share-name"|SELECT|OnDatabase|one.two`,
Error: `unexpected number of parts 2 in identifier one.two, expected 1 in a form of "<account_object_name>"`,
Identifier: `"share-name"|SELECT|OnDatabase|"one"."two"`,
Error: `unexpected number of parts 2 in identifier "one"."two", expected 1 in a form of "<account_object_name>"`,
},
{
Name: "validation: invalid database object identifier",
Expand Down
8 changes: 4 additions & 4 deletions pkg/sdk/identifier_parsers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ func Test_IdentifierParsers(t *testing.T) {
Expected ObjectIdentifier
Error string
}{
{IdentifierType: "AccountObjectIdentifier", Input: ``, Error: "incompatible identifier: "},
{IdentifierType: "AccountObjectIdentifier", Input: "a\nb", Error: "incompatible identifier: a\nb"},
{IdentifierType: "AccountObjectIdentifier", Input: `a"b`, Error: "unable to read identifier: a\"b, err = parse error on line 1, column 2: bare \" in non-quoted-field"},
{IdentifierType: "AccountObjectIdentifier", Input: `abc.cde`, Error: `unexpected number of parts 2 in identifier abc.cde, expected 1 in a form of "<account_object_name>"`},
{IdentifierType: "AccountObjectIdentifier", Input: ``, Expected: NewAccountObjectIdentifier("")},
{IdentifierType: "AccountObjectIdentifier", Input: "a\nb", Expected: NewAccountObjectIdentifier("a\nb")},
{IdentifierType: "AccountObjectIdentifier", Input: `a"b`, Error: `unable to read identifier: "a"b", err = parse error on line 1, column 3: extraneous or missing " in quoted-field`},
{IdentifierType: "AccountObjectIdentifier", Input: `abc.cde`, Expected: NewAccountObjectIdentifier("abc.cde")},
{IdentifierType: "AccountObjectIdentifier", Input: `""""`, Error: `unable to parse identifier: """", currently identifiers containing double quotes are not supported in the provider`},
{IdentifierType: "AccountObjectIdentifier", Input: `"a""bc"`, Error: `unable to parse identifier: "a""bc", currently identifiers containing double quotes are not supported in the provider`},
{IdentifierType: "AccountObjectIdentifier", Input: `""`, Expected: NewAccountObjectIdentifier(``)},
Expand Down

0 comments on commit 3221374

Please sign in to comment.