Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -2,11 +2,13 @@ using System;
|
||||
using StellaOps.Concelier.Exporter.TrivyDb;
|
||||
using StellaOps.Concelier.Storage.Exporting;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Concelier.Exporter.TrivyDb.Tests;
|
||||
|
||||
public sealed class TrivyDbExportPlannerTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void CreatePlan_ReturnsFullWhenStateMissing()
|
||||
{
|
||||
var planner = new TrivyDbExportPlanner();
|
||||
@@ -21,7 +23,8 @@ public sealed class TrivyDbExportPlannerTests
|
||||
Assert.Equal(manifest, plan.Manifest);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void CreatePlan_ReturnsSkipWhenCursorMatches()
|
||||
{
|
||||
var planner = new TrivyDbExportPlanner();
|
||||
@@ -49,7 +52,8 @@ public sealed class TrivyDbExportPlannerTests
|
||||
Assert.Empty(plan.RemovedPaths);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void CreatePlan_ReturnsFullWhenCursorDiffers()
|
||||
{
|
||||
var planner = new TrivyDbExportPlanner();
|
||||
|
||||
@@ -30,7 +30,8 @@ public sealed class TrivyDbFeedExporterTests : IDisposable
|
||||
_jsonRoot = Path.Combine(_root, "tree");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ExportAsync_SortsAdvisoriesByKeyDeterministically()
|
||||
{
|
||||
var advisoryB = CreateSampleAdvisory("CVE-2024-1002", "Second advisory");
|
||||
@@ -98,7 +99,8 @@ public sealed class TrivyDbFeedExporterTests : IDisposable
|
||||
Assert.Single(recordingBuilder.ManifestDigests);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ExportAsync_SmallDatasetProducesDeterministicOciLayout()
|
||||
{
|
||||
var advisories = new[]
|
||||
@@ -134,7 +136,8 @@ public sealed class TrivyDbFeedExporterTests : IDisposable
|
||||
Assert.Equal(TrivyDbMediaTypes.TrivyLayer, layer.GetProperty("mediaType").GetString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ExportOptions_GetExportRoot_NormalizesRelativeRoot()
|
||||
{
|
||||
var options = new TrivyDbExportOptions
|
||||
@@ -149,7 +152,8 @@ public sealed class TrivyDbFeedExporterTests : IDisposable
|
||||
Assert.EndsWith(Path.Combine("exports", "trivy-test", exportId), path, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ExportAsync_PersistsStateAndSkipsWhenDigestUnchanged()
|
||||
{
|
||||
var advisory = CreateSampleAdvisory();
|
||||
@@ -222,7 +226,8 @@ public sealed class TrivyDbFeedExporterTests : IDisposable
|
||||
Assert.Empty(orasPusher.Pushes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ExportAsync_CreatesOfflineBundle()
|
||||
{
|
||||
var advisory = CreateSampleAdvisory();
|
||||
@@ -282,7 +287,8 @@ public sealed class TrivyDbFeedExporterTests : IDisposable
|
||||
Assert.Empty(orasPusher.Pushes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ExportAsync_WritesMirrorBundlesWhenConfigured()
|
||||
{
|
||||
var advisoryOne = CreateSampleAdvisory("CVE-2025-1001", "Mirror Advisory One");
|
||||
@@ -431,7 +437,8 @@ public sealed class TrivyDbFeedExporterTests : IDisposable
|
||||
Assert.Empty(orasPusher.Pushes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ExportAsync_SkipsOrasPushWhenDeltaPublishingDisabled()
|
||||
{
|
||||
var initial = CreateSampleAdvisory("CVE-2024-7100", "Publish toggles");
|
||||
@@ -492,7 +499,8 @@ public sealed class TrivyDbFeedExporterTests : IDisposable
|
||||
Assert.Empty(orasPusher.Pushes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ExportAsync_SkipsOfflineBundleForDeltaWhenDisabled()
|
||||
{
|
||||
var initial = CreateSampleAdvisory("CVE-2024-7200", "Offline delta toggles");
|
||||
@@ -562,7 +570,8 @@ public sealed class TrivyDbFeedExporterTests : IDisposable
|
||||
Assert.False(File.Exists(deltaBundlePath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ExportAsync_ResetsBaselineWhenDeltaChainExists()
|
||||
{
|
||||
var advisory = CreateSampleAdvisory("CVE-2024-5000", "Baseline reset");
|
||||
@@ -635,7 +644,8 @@ public sealed class TrivyDbFeedExporterTests : IDisposable
|
||||
Assert.NotEmpty(updated.Files);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ExportAsync_DeltaSequencePromotesBaselineReset()
|
||||
{
|
||||
var baseline = CreateSampleAdvisory("CVE-2024-8100", "Baseline advisory");
|
||||
@@ -725,7 +735,8 @@ public sealed class TrivyDbFeedExporterTests : IDisposable
|
||||
Assert.Equal(finalExportId, state.BaseExportId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ExportAsync_DeltaReusesBaseLayerOnDisk()
|
||||
{
|
||||
var baseline = CreateSampleAdvisory("CVE-2024-8300", "Layer reuse baseline");
|
||||
@@ -1185,6 +1196,7 @@ public sealed class TrivyDbFeedExporterTests : IDisposable
|
||||
var archivePath = Path.Combine(workingDirectory, "db.tar.gz");
|
||||
File.WriteAllBytes(archivePath, _payload);
|
||||
using var sha256 = SHA256.Create();
|
||||
using StellaOps.TestKit;
|
||||
var digest = "sha256:" + Convert.ToHexString(sha256.ComputeHash(_payload)).ToLowerInvariant();
|
||||
|
||||
return Task.FromResult(new TrivyDbBuilderResult(
|
||||
|
||||
@@ -10,6 +10,7 @@ using System.Threading.Tasks;
|
||||
using StellaOps.Concelier.Storage.Exporting;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Concelier.Exporter.TrivyDb.Tests;
|
||||
|
||||
public sealed class TrivyDbOciWriterTests : IDisposable
|
||||
@@ -21,7 +22,8 @@ public sealed class TrivyDbOciWriterTests : IDisposable
|
||||
_root = Directory.CreateTempSubdirectory("trivy-writer-tests").FullName;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task WriteAsync_ReusesBlobsFromBaseLayout_WhenDigestMatches()
|
||||
{
|
||||
var baseLayout = Path.Combine(_root, "base");
|
||||
|
||||
@@ -6,11 +6,13 @@ using System.Text;
|
||||
using System.Text.Json;
|
||||
using StellaOps.Concelier.Exporter.TrivyDb;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Concelier.Exporter.TrivyDb.Tests;
|
||||
|
||||
public sealed class TrivyDbPackageBuilderTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void BuildsOciManifestWithExpectedMediaTypes()
|
||||
{
|
||||
var metadata = Encoding.UTF8.GetBytes("{\"generatedAt\":\"2024-07-15T12:00:00Z\"}");
|
||||
@@ -56,7 +58,8 @@ public sealed class TrivyDbPackageBuilderTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ThrowsWhenMetadataMissing()
|
||||
{
|
||||
var builder = new TrivyDbPackageBuilder();
|
||||
|
||||
Reference in New Issue
Block a user