-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
18 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
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
61 changes: 61 additions & 0 deletions
61
code/DeltaKustoUnitTest/CommandParsing/Policies/AlterRowLevelSecurityPolicyTest.cs
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 @@ | ||
using DeltaKustoLib.CommandModel; | ||
using DeltaKustoLib.CommandModel.Policies; | ||
using System; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using Xunit; | ||
|
||
namespace DeltaKustoUnitTest.CommandParsing.Policies | ||
{ | ||
public class AlterRowLevelSecurityPolicyTest : ParsingTestBase | ||
{ | ||
[Fact] | ||
public void SimpleTable() | ||
{ | ||
TestRowLevelPolicy("A", "MyFunction"); | ||
} | ||
|
||
[Fact] | ||
public void FunkyTable() | ||
{ | ||
TestRowLevelPolicy("['A- 1']", "MyTable | where TenantId == 42"); | ||
} | ||
|
||
// Currently not supported by the parser | ||
//[Fact] | ||
//public void DbComposedTableName() | ||
//{ | ||
// TestRowLevelPolicy("mydb.mytable", "MyFunction"); | ||
//} | ||
|
||
// Currently not supported by the parser | ||
//[Fact] | ||
//public void ClusterComposedTableName() | ||
//{ | ||
// TestRowLevelPolicy("mycluster.['my db'].mytable", "MyFunction"); | ||
//} | ||
|
||
private void TestRowLevelPolicy(string tableName, string query) | ||
{ | ||
TestRowLevelPolicy(tableName, true, query); | ||
TestRowLevelPolicy(tableName, false, query); | ||
} | ||
|
||
private void TestRowLevelPolicy(string tableName, bool isEnabled, string query) | ||
{ | ||
var realTableName = tableName.Split('.').Last(); | ||
var enableToken = isEnabled ? "enable" : "disable"; | ||
var commandText = $@" | ||
.alter table {tableName} policy row_level_security {enableToken} ""{query}"" | ||
"; | ||
var command = ParseOneCommand(commandText); | ||
|
||
Assert.IsType<AlterRowLevelSecurityPolicyCommand>(command); | ||
|
||
var realCommand = (AlterRowLevelSecurityPolicyCommand)command; | ||
|
||
Assert.Equal(isEnabled, realCommand.IsEnabled); | ||
Assert.Equal(query, realCommand.Query.Text); | ||
} | ||
} | ||
} |