Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
vplauzon committed Oct 19, 2023
1 parent 06bbc1f commit 24add2c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public override string ToScript(ScriptingContext? context)
var builder = new StringBuilder();

builder.Append(".alter table ");
builder.Append(TableName);
builder.Append(TableName.ToScript());
builder.Append(" policy update");
builder.AppendLine();
builder.Append("```");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,18 @@ 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);
}
// Currently unsupported in parser
//[Fact]
//public void DbComposedTableName()
//{
// TestIngestionTimePolicy("mydb.mytable");
//}

//[Fact]
//public void ClusterComposedTableName()
//{
// TestIngestionTimePolicy("mycluster.['my db'].mytable");
//}

private void TestIngestionTimePolicy(string tableName)
{
Expand All @@ -57,6 +42,7 @@ private void TestIngestionTimePolicy(string tableName)

private void TestIngestionTimePolicy(string tableName, bool isEnabled)
{
var actualTableName = GetActualTableName(tableName);
var commandText = $@"
.alter table {tableName} policy ingestiontime {isEnabled.ToString().ToLower()}";
var command = ParseOneCommand(commandText);
Expand All @@ -65,7 +51,7 @@ private void TestIngestionTimePolicy(string tableName, bool isEnabled)

var realCommand = (AlterIngestionTimePolicyCommand)command;

Assert.Equal(tableName, realCommand.TableName.Name);
Assert.Equal(actualTableName, realCommand.TableName.Name);
Assert.Equal(isEnabled, realCommand.IsEnabled);
}
}
Expand Down
14 changes: 14 additions & 0 deletions code/DeltaKustoUnitTest/ParsingTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,19 @@ protected CommandBase ParseOneCommand(string script)

return commands.First();
}

protected static string GetActualTableName(string tableName)
{
var actualTableName = tableName.Split('.').Last();

if (actualTableName.StartsWith('['))
{
return actualTableName.Substring(2, actualTableName.Length - 4);
}
else
{
return actualTableName;
}
}
}
}

0 comments on commit 24add2c

Please sign in to comment.