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:
Родитель
d4ca976992
Коммит
ce76f5df26
|
@ -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>()));
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче