Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
vplauzon committed Oct 19, 2023
1 parent 6e07907 commit 06bbc1f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
2 changes: 2 additions & 0 deletions code/DeltaKustoLib/CommandModel/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ public override int GetHashCode()
case "DeleteTablePolicyStreamingIngestion":
case "DeleteDatabasePolicyStreamingIngestion":
return DeleteStreamingIngestionPolicyCommand.FromCode(commandBlock);
case "AlterTablePolicyIngestionTime":
return AlterIngestionTimePolicyCommand.FromCode(commandBlock);
#endregion

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ public AlterIngestionTimePolicyCommand(EntityName tableName, bool isEnabled)
internal static CommandBase FromCode(SyntaxElement rootElement)
{
var tableName = rootElement.GetDescendants<NameReference>().Last();
var enabledToken = rootElement.GetUniqueDescendant<SyntaxToken>(
"Ingestion time",
t => t.Kind == SyntaxKind.BooleanLiteralToken);
var isEnabled = (bool)enabledToken.Value;

throw new NotImplementedException();
//return new AlterIngestionTimePolicyCommand(EntityName.FromCode(tableName.Name), policy);
return new AlterIngestionTimePolicyCommand(EntityName.FromCode(tableName.Name), isEnabled);
}

public override string ToScript(ScriptingContext? context)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using DeltaKustoLib.CommandModel;
using DeltaKustoLib.CommandModel.Policies;
using System;
using System.Linq;
using System.Text.Json;
using Xunit;

namespace DeltaKustoUnitTest.CommandParsing.Policies
{
public class AlterIngestionTimePolicyTest : ParsingTestBase
{
[Fact]
public void SimpleTable()
{
TestIngestionTimePolicy("A");
}

[Fact]
public void FunkyTable()
{
TestIngestionTimePolicy("['A- 1']");
}

[Fact]
public void DbComposedTableName()
{
var command = ParseOneCommand(
".alter table mydb.mytable policy auto_delete"
+ "@'{\"ExpiryDate\":\"2030-02-01\"}'");

Assert.IsType<AlterAutoDeletePolicyCommand>(command);

var realCommand = (AlterAutoDeletePolicyCommand)command;

Assert.Equal("mytable", realCommand.TableName.Name);
}

[Fact]
public void ClusterComposedTableName()
{
var command = ParseOneCommand(
".alter table mycluster.['my db'].mytable policy auto_delete "
+ "@'{\"ExpiryDate\":\"2031-02-01\"}'");

Assert.IsType<AlterAutoDeletePolicyCommand>(command);

var realCommand = (AlterAutoDeletePolicyCommand)command;

Assert.Equal("mytable", realCommand.TableName.Name);
}

private void TestIngestionTimePolicy(string tableName)
{
TestIngestionTimePolicy(tableName, true);
TestIngestionTimePolicy(tableName, false);
}

private void TestIngestionTimePolicy(string tableName, bool isEnabled)
{
var commandText = $@"
.alter table {tableName} policy ingestiontime {isEnabled.ToString().ToLower()}";
var command = ParseOneCommand(commandText);

Assert.IsType<AlterIngestionTimePolicyCommand>(command);

var realCommand = (AlterIngestionTimePolicyCommand)command;

Assert.Equal(tableName, realCommand.TableName.Name);
Assert.Equal(isEnabled, realCommand.IsEnabled);
}
}
}

0 comments on commit 06bbc1f

Please sign in to comment.