Refactor code structure for improved readability and maintainability; optimize performance in key functions.
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
namespace StellaOps.AuditPack.Tests;
|
||||
|
||||
using StellaOps.AuditPack.Services;
|
||||
|
||||
[Trait("Category", "Unit")]
|
||||
public class AuditPackImporterTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Import_ValidPack_Succeeds()
|
||||
{
|
||||
// Arrange
|
||||
var archivePath = await CreateTestArchiveAsync();
|
||||
var importer = new AuditPackImporter();
|
||||
var options = new ImportOptions { VerifySignatures = false };
|
||||
|
||||
try
|
||||
{
|
||||
// Act
|
||||
var result = await importer.ImportAsync(archivePath, options);
|
||||
|
||||
// Assert
|
||||
result.Success.Should().BeTrue();
|
||||
result.Pack.Should().NotBeNull();
|
||||
result.IntegrityResult?.IsValid.Should().BeTrue();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(archivePath))
|
||||
File.Delete(archivePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Import_MissingManifest_Fails()
|
||||
{
|
||||
// Arrange
|
||||
var archivePath = Path.Combine(Path.GetTempPath(), "invalid.tar.gz");
|
||||
await CreateEmptyArchiveAsync(archivePath);
|
||||
|
||||
var importer = new AuditPackImporter();
|
||||
|
||||
try
|
||||
{
|
||||
// Act
|
||||
var result = await importer.ImportAsync(archivePath, new ImportOptions());
|
||||
|
||||
// Assert
|
||||
result.Success.Should().BeFalse();
|
||||
result.Errors.Should().Contain(e => e.Contains("Manifest"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(archivePath))
|
||||
File.Delete(archivePath);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<string> CreateTestArchiveAsync()
|
||||
{
|
||||
// Create a test pack and export it
|
||||
var builder = new AuditPackBuilder();
|
||||
var pack = await builder.BuildAsync(
|
||||
new ScanResult("test-scan"),
|
||||
new AuditPackOptions());
|
||||
|
||||
var archivePath = Path.Combine(Path.GetTempPath(), $"test-{Guid.NewGuid():N}.tar.gz");
|
||||
await builder.ExportAsync(pack, archivePath, new ExportOptions { Sign = false });
|
||||
|
||||
return archivePath;
|
||||
}
|
||||
|
||||
private static async Task CreateEmptyArchiveAsync(string path)
|
||||
{
|
||||
// Create an empty tar.gz
|
||||
using var fs = File.Create(path);
|
||||
using var gz = new System.IO.Compression.GZipStream(fs, System.IO.Compression.CompressionLevel.Fastest);
|
||||
await gz.WriteAsync(new byte[] { 0 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user