Skip to content

Commit

Permalink
Merge pull request #129 from microsoft/vpl/fix-function-param-length
Browse files Browse the repository at this point in the history
Vpl/fix function param length
  • Loading branch information
vplauzon authored Apr 14, 2023
2 parents 6d2191c + 4eb0d65 commit 10400f8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions code/DeltaKustoLib/CommandModel/CreateFunctionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public override bool Equals(CommandBase? other)
var areEqualed = otherFunction != null
&& otherFunction.FunctionName.Equals(FunctionName)
// Check that all parameters are equal
&& otherFunction.Parameters.Count() == Parameters.Count()
&& otherFunction.Parameters.Zip(Parameters, (p1, p2) => p1.Equals(p2)).All(p => p)
&& otherFunction.Body.Equals(Body)
&& object.Equals(otherFunction.Folder, Folder)
Expand Down
42 changes: 42 additions & 0 deletions code/DeltaKustoUnitTest/Delta/DeltaFunctionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,48 @@ public void UpdateOne()
Assert.Equal("MyOtherFunction", ((CreateFunctionCommand)delta[0]).FunctionName.Name);
}

[Fact]
public void UpdateParameter()
{
var currentCommands = Parse(".create function MyFunction(Id:int) { 42 }");
var currentDatabase = DatabaseModel.FromCommands(currentCommands);
var targetCommands = Parse(".create function MyFunction(){ 42 }");
var targetDatabase = DatabaseModel.FromCommands(targetCommands);
var delta = currentDatabase.ComputeDelta(targetDatabase);

Assert.Single(delta);
Assert.IsType<CreateFunctionCommand>(delta[0]);
Assert.Equal("MyFunction", ((CreateFunctionCommand)delta[0]).FunctionName.Name);
}

[Fact]
public void UpdateParameterWithDefaultValue()
{
var currentCommands = Parse(".create function MyFunction(Id:int) { 42 }");
var currentDatabase = DatabaseModel.FromCommands(currentCommands);
var targetCommands = Parse(".create function MyFunction(Id:int=5){ 42 }");
var targetDatabase = DatabaseModel.FromCommands(targetCommands);
var delta = currentDatabase.ComputeDelta(targetDatabase);

Assert.Single(delta);
Assert.IsType<CreateFunctionCommand>(delta[0]);
Assert.Equal("MyFunction", ((CreateFunctionCommand)delta[0]).FunctionName.Name);
}

[Fact]
public void NoUpdateParameterWithDefaultValue()
{
var currentCommands = Parse(
".create function MyFunction(StartTime:datetime=datetime(null)) { 42 }");
var currentDatabase = DatabaseModel.FromCommands(currentCommands);
var targetCommands = Parse(
".create function MyFunction(StartTime:datetime=datetime(null)){ 42 }");
var targetDatabase = DatabaseModel.FromCommands(targetCommands);
var delta = currentDatabase.ComputeDelta(targetDatabase);

Assert.Empty(delta);
}

[Fact]
public void DetectDuplicates()
{
Expand Down
2 changes: 1 addition & 1 deletion code/delta-kusto/delta-kusto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>delta_kusto</RootNamespace>
<Nullable>enable</Nullable>
<Version>0.12.0</Version>
<Version>0.12.1</Version>
<!-- Avoid having each library being trimmed (instead of only opt-in ones) -->
<TrimMode>partial</TrimMode>
<!-- Important to avoid the trimming warning hell ; since we automate-test everything, we do not need static analysis -->
Expand Down

0 comments on commit 10400f8

Please sign in to comment.