Skip to content

Commit

Permalink
Handle an edge case of root node being null in conan.lock file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashokgowtham committed Aug 4, 2023
1 parent ff6ce34 commit 4e8851b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID
if (packagesDictionary.ContainsKey("0"))
{
packagesDictionary.Remove("0", out var rootNode);
if (rootNode.Requires != null)
if (rootNode?.Requires != null)
{
explicitReferencedDependencies = new HashSet<string>(rootNode.Requires);
}

if (rootNode.BuildRequires != null)
if (rootNode?.BuildRequires != null)
{
developmentDependencies = new HashSet<string>(rootNode.BuildRequires);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ public class ConanLockComponentDetectorTests : BaseDetectorTest<ConanLockCompone
""profile_host"": ""someLongProfileHostSettingsString\n"",
""profile_build"": ""someLongProfileBuildSettingsString\n""
}
";

private readonly string testConanLockStringWithNullValueForRootNode = @"{
""graph_lock"": {
""nodes"": {
""0"": null,
""1"": {
""ref"": ""libabc/1.2.12#someHashOfLibAbc"",
""options"": ""someOptionsString"",
""package_id"": ""packageIdOfLibAbc"",
""prev"": ""someHashOfLibAbc"",
""context"": ""host""
}
},
""revisions_enabled"": true
},
""version"": ""0.4"",
""profile_host"": ""someLongProfileHostSettingsString\n"",
""profile_build"": ""someLongProfileBuildSettingsString\n""
}
";

private readonly string testConanLockNoDependenciesString = @"{
Expand Down Expand Up @@ -163,6 +183,20 @@ public async Task TestGraphIsCorrectAsync()
graph.GetDependenciesForComponent("libanotherlibrary2 3.4.5#someHashOfLibAnotherLibrary2 - Conan").Should().BeEquivalentTo(new[] { "libanotherlibrary3 4.5.6#someHashOfLibAnotherLibrary3 - Conan" });
}

[TestMethod]
public async Task TestDetectionForConanLockFileWithNullValuesForRootNodeAsync()
{
var (result, componentRecorder) = await this.DetectorTestUtility
.WithFile("Conan.lock", this.testConanLockStringWithNullValueForRootNode)
.ExecuteDetectorAsync();

result.ResultCode.Should().Be(ProcessingResultCode.Success);
componentRecorder.GetDetectedComponents().Count().Should().Be(1);

(componentRecorder.GetDetectedComponents().First().Component as ConanComponent).Name.Should().Be("libabc");
(componentRecorder.GetDetectedComponents().First().Component as ConanComponent).Version.Should().Be("1.2.12#someHashOfLibAbc");
}

[TestMethod]
public async Task TestConanDetectorAsync()
{
Expand Down

0 comments on commit 4e8851b

Please sign in to comment.