-
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.
fix: support different tag association queries for COLUMN object types (
#1380) * support different tag association queries for COLUMN object types * refactor after testing * fix logic for getting table and column name * fix logic for when non-FQ name is used * db name is required by the resource, updating tests/logic accordingly * fix sql syntax to use MODIFY rather than ALTER on column * fix show logic to support column-level tagging
- Loading branch information
1 parent
00fc00c
commit 546d0a1
Showing
2 changed files
with
93 additions
and
4 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
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,61 @@ | ||
package snowflake | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type TagAssociationTest struct { | ||
Builder *TagAssociationBuilder | ||
ExpectedCreate string | ||
ExpectedDrop string | ||
ExpectedShow string | ||
} | ||
|
||
func TestTagAssociation(t *testing.T) { | ||
tests := []TagAssociationTest{ | ||
{ | ||
Builder: NewTagAssociationBuilder("test_db|test_schema|sensitive").WithObjectIdentifier(`"test_db"."test_schema"."test_table"`).WithObjectType("TABLE").WithTagValue("true"), | ||
ExpectedCreate: `ALTER TABLE "test_db"."test_schema"."test_table" SET TAG "test_db"."test_schema"."sensitive" = 'true'`, | ||
ExpectedDrop: `ALTER TABLE "test_db"."test_schema"."test_table" UNSET TAG "test_db"."test_schema"."sensitive"`, | ||
ExpectedShow: `SELECT SYSTEM$GET_TAG('"test_db"."test_schema"."sensitive"', '"test_db"."test_schema"."test_table"', 'TABLE') TAG_VALUE WHERE TAG_VALUE IS NOT NULL`, | ||
}, | ||
{ | ||
Builder: NewTagAssociationBuilder("test_db|test_schema|sensitive").WithObjectIdentifier(`"test_db"."test_schema"."test_table.important"`).WithObjectType("COLUMN").WithTagValue("true"), | ||
ExpectedCreate: `ALTER TABLE "test_db"."test_schema"."test_table" MODIFY COLUMN important SET TAG "test_db"."test_schema"."sensitive" = 'true'`, | ||
ExpectedDrop: `ALTER TABLE "test_db"."test_schema"."test_table" MODIFY COLUMN important UNSET TAG "test_db"."test_schema"."sensitive"`, | ||
ExpectedShow: `SELECT SYSTEM$GET_TAG('"test_db"."test_schema"."sensitive"', '"test_db"."test_schema"."test_table"."important"', 'COLUMN') TAG_VALUE WHERE TAG_VALUE IS NOT NULL`, | ||
}, | ||
{ | ||
Builder: NewTagAssociationBuilder("OPERATION_DB|SECURITY|PII_2").WithObjectIdentifier(`"OPERATION_DB"."SECURITY"."test_table.important"`).WithObjectType("COLUMN").WithTagValue("true"), | ||
ExpectedCreate: `ALTER TABLE "OPERATION_DB"."SECURITY"."test_table" MODIFY COLUMN important SET TAG "OPERATION_DB"."SECURITY"."PII_2" = 'true'`, | ||
ExpectedDrop: `ALTER TABLE "OPERATION_DB"."SECURITY"."test_table" MODIFY COLUMN important UNSET TAG "OPERATION_DB"."SECURITY"."PII_2"`, | ||
ExpectedShow: `SELECT SYSTEM$GET_TAG('"OPERATION_DB"."SECURITY"."PII_2"', '"OPERATION_DB"."SECURITY"."test_table"."important"', 'COLUMN') TAG_VALUE WHERE TAG_VALUE IS NOT NULL`, | ||
}, | ||
} | ||
for _, testCase := range tests { | ||
r := require.New(t) | ||
r.Equal(testCase.ExpectedCreate, testCase.Builder.Create()) | ||
r.Equal(testCase.ExpectedDrop, testCase.Builder.Drop()) | ||
r.Equal(testCase.ExpectedShow, testCase.Builder.Show()) | ||
} | ||
} | ||
|
||
type TableColumnNameTest struct { | ||
Builder *TagAssociationBuilder | ||
expectedTableName, expectedColumnName string | ||
} | ||
|
||
func TestTableColumnName(t *testing.T) { | ||
tests := []TableColumnNameTest{ | ||
{NewTagAssociationBuilder("a|b|sensitive").WithObjectIdentifier(`"a"."b"."c"`).WithObjectType("TABLE"), `"a"."b"."c"`, ""}, | ||
{NewTagAssociationBuilder("db|schema|sensitive").WithObjectIdentifier(`"db"."schema"."table.column"`).WithObjectType("COLUMN"), `"db"."schema"."table"`, "column"}, | ||
} | ||
for _, testCase := range tests { | ||
r := require.New(t) | ||
tableName, columnName := testCase.Builder.GetTableAndColumnName() | ||
r.Equal(testCase.expectedTableName, tableName) | ||
r.Equal(testCase.expectedColumnName, columnName) | ||
} | ||
} |