using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.Logging.Abstractions; using StellaOps.Scheduler.ImpactIndex; using StellaOps.Scheduler.Models; using Xunit; namespace StellaOps.Scheduler.WebService.Tests; public sealed class ImpactIndexFixtureTests { [Fact] public void FixtureDirectoryExists() { var fixtureDirectory = GetFixtureDirectory(); Assert.True(Directory.Exists(fixtureDirectory), $"Fixture directory not found: {fixtureDirectory}"); var files = Directory.EnumerateFiles(fixtureDirectory, "bom-index.json", SearchOption.AllDirectories).ToArray(); Assert.NotEmpty(files); var sampleFile = Path.Combine(fixtureDirectory, "sample", "bom-index.json"); Assert.Contains(sampleFile, files); } [Fact] public async Task FixtureImpactIndexLoadsSampleImage() { var fixtureDirectory = GetFixtureDirectory(); var options = new ImpactIndexStubOptions { FixtureDirectory = fixtureDirectory, SnapshotId = "tests/impact-index-stub" }; var index = new FixtureImpactIndex(options, TimeProvider.System, NullLogger.Instance); var selector = new Selector(SelectorScope.AllImages); var impactSet = await index.ResolveAllAsync(selector, usageOnly: false); Assert.True(impactSet.Total > 0, "Expected the fixture impact index to load at least one image."); } private static string GetFixtureDirectory() { var assemblyLocation = typeof(SchedulerWebApplicationFactory).Assembly.Location; var assemblyDirectory = Path.GetDirectoryName(assemblyLocation) ?? AppContext.BaseDirectory; return Path.GetFullPath(Path.Combine(assemblyDirectory, "seed-data", "impact-index")); } }