Skip to content

Commit

Permalink
add missing test case for previous load functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
scbedd committed May 31, 2023
1 parent e5e0572 commit e8ffd7a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<None Update="TestResources\basic_output\output.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestResources\configurations\sample-repo-configuration.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@ public void TestParsePreviouslyOutputResults()
Assert.That(resultSet.Results[2].ScanDate, Is.EqualTo(DateTime.Parse("2023-05-08T00:00:00")));
}

[Test]
[GitTokenSkip]
public void TestLoadConfiguration()
{
var scanner = new AssetsScanner(TestDirectory);
var runConfigurationPath = Path.Combine(TestDirectory, "TestResources", "configurations", "sample-repo-configuration.json");
var config = new RunConfiguration(runConfigurationPath);

var results = scanner.Scan(config);

Assert.That(results.Results.Count, Is.EqualTo(8));
}

[Test]
[GitTokenSkip]
public void TestScanOutputsResults()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ public AssetsResultSet(List<AssetsResult> input)
CalculateObjects();
}

public AssetsResultSet(List<AssetsResult> input, AssetsResultSet? existingSet)
{
Results = input;

// todo: coalesce input + existing set

CalculateObjects();
}
// Currently we already honor previous results in AssetsScanner::ScanRepo()L#119
// leaving this final resolution point in place between the two sets just in case.
// This eliminates the need for a constructor that coalesces a previous result set.

public List<AssetsResult> Results { get; set; } = new List<AssetsResult>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace Azure.Sdk.Tools.Assets.MaintenanceTool.Model
Expand All @@ -18,7 +19,24 @@ public RunConfiguration() {

public RunConfiguration(string configPath)
{
if (File.Exists(configPath))
{
Repos = new List<RepoConfiguration>();

using var stream = System.IO.File.OpenRead(configPath);
using var doc = JsonDocument.Parse(stream);

var results = JsonSerializer.Deserialize<RunConfiguration>(doc);

if (results != null)
{
Repos = results.Repos;
}
}
else
{
throw new ArgumentException($"The configuration file path \"{configPath}\" does not exist.");
}
}

public List<RepoConfiguration> Repos { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public AssetsResultSet Scan(RunConfiguration config)
resultSet.AddRange(ScanRepo(repoConfig, existingResults));
});

var newResults = new AssetsResultSet(resultSet, existingResults);
var newResults = new AssetsResultSet(resultSet);

Save(newResults);

Expand Down

0 comments on commit e8ffd7a

Please sign in to comment.