using System; using System.IO; using GeoVLog.Core.Hdf5; using GeoVLog.Core.Manifests; using Xunit; namespace GeoVLog.Tests.Helpers; public class StartupScanTests { // Fail fast after 30 s instead of hanging indefinitely [Fact(Timeout = 30_000)] [Trait("Category", "Core")] public void EncryptsLeftoverFilesOnConstruction() { var dir = CreateTempDir(); try { // ─── Arrange ──────────────────────────────────────────────── var oldPath = Path.Combine(dir, "old.h5"); File.WriteAllText(oldPath, "data"); var manifest = new FlightManifest(); var manifestPath = Path.Combine(dir, "manifest.bin"); var key = new byte[32]; var serializer = new FlightManifestProtoSerializer(); // Use a 100 ms flush interval (irrelevant in no-thread mode, // but makes the worker ultra-responsive if startThread = true) var flushOpts = new H5LogFlushOptions { EnableAutoFlush = true, FlushInterval = TimeSpan.FromMilliseconds(100) }; // ─── Act ─── Constructor should sweep & encrypt immediately // startThread: false ⇒ no background thread is spawned var worker = new H5LogQueueWorker( dir, manifest, manifestPath, key, serializer, flushOpts, startThread: false); // Nothing else to do: encryption happened inside the ctor. worker.Dispose(); // ─── Assert ──────────────────────────────────────────────── Assert.False(File.Exists(oldPath)); // plaintext gone Assert.True(File.Exists(oldPath + ".enc")); // cipher present } finally { Directory.Delete(dir, recursive: true); } } private static string CreateTempDir() { var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); Directory.CreateDirectory(path); return path; } }