Adds an entry point for the sbom-tool use the ScanCommand class. (#936)

* Add Author/License to LinuxComponent

* Add method to scan that returns a ScanResult Object

* Revert "Add Author/License to LinuxComponent"

This reverts commit 643dc09393.

* Add unit tests

---------

Co-authored-by: Sebastian Gomez <segomez@microsoft.com>
This commit is contained in:
Sebastian Gomez 2023-12-19 14:17:37 -05:00 коммит произвёл GitHub
Родитель d4ca976992
Коммит ce76f5df26
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 44 добавлений и 0 удалений

Просмотреть файл

@ -45,6 +45,19 @@ public sealed class ScanCommand : AsyncCommand<ScanSettings>
return 0;
}
/// <summary>
/// Method to provide a way to execute the scan command and obtain the ScanResult object.
/// </summary>
/// <param name="settings">ScanSettings object specifying the parameters for the scan execution.</param>
/// <returns>A ScanResult object.</returns>
public async Task<ScanResult> ExecuteScanCommandAsync(ScanSettings settings)
{
this.fileWritingService.Init(settings.Output);
var result = await this.scanExecutionService.ExecuteScanAsync(settings);
this.WriteComponentManifest(settings, result);
return result;
}
private void WriteComponentManifest(ScanSettings settings, ScanResult scanResult)
{
FileInfo userRequestedManifestPath = null;

Просмотреть файл

@ -82,4 +82,35 @@ public class ScanCommandTests
await tw.FlushAsync();
ms.Position.Should().BePositive();
}
[TestMethod]
public async Task ExecuteScanCommandAsync_PrintsManifestAsync()
{
var settings = new ScanSettings { Output = "output", PrintManifest = true };
using var ms = new MemoryStream();
await using var tw = new StreamWriter(ms);
Console.SetOut(tw);
var result = await this.command.ExecuteScanCommandAsync(settings);
this.fileWritingServiceMock.Verify(x => x.Init(settings.Output), Times.Once);
this.scanExecutionServiceMock.Verify(x => x.ExecuteScanAsync(settings), Times.Once);
this.fileWritingServiceMock.Verify(x => x.ResolveFilePath(It.IsAny<string>()), Times.Once);
this.fileWritingServiceMock.Verify(x => x.AppendToFile(It.IsAny<string>(), It.IsAny<ScanResult>()));
await tw.FlushAsync();
ms.Position.Should().BePositive();
}
[TestMethod]
public async Task ExecuteScanCommandAsync_WritesUserManifestAsync()
{
var settings = new ScanSettings { Output = "output", ManifestFile = new FileInfo("manifest.json") };
var result = await this.command.ExecuteScanCommandAsync(settings);
this.fileWritingServiceMock.Verify(x => x.Init(settings.Output), Times.Once);
this.scanExecutionServiceMock.Verify(x => x.ExecuteScanAsync(settings), Times.Once);
this.fileWritingServiceMock.Verify(x => x.WriteFile(It.Is<FileInfo>(x => x == settings.ManifestFile), It.IsAny<ScanResult>()));
}
}