The fixture resolves GameData/Mods through ShipModCatalog.ResolveCatalog once per test process and throws on any excluded package, so a broken first-party package fails the suite. With no GameData/Mods it is the shipped catalog, unchanged. Builds and tests not yet run on this commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
2.4 KiB
C#
64 lines
2.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using GameCult.Caching;
|
|
using Xunit;
|
|
|
|
// TestCatalog.Resolve: the catalog every RunStartTests partial stages from is the one the game boots.
|
|
public sealed class TestCatalogTests : IDisposable
|
|
{
|
|
private readonly TempDirectory _directory = new TempDirectory();
|
|
private string Shipped => Path.Combine(_directory.Path, "Aetheria.cc");
|
|
private string Mods => Path.Combine(_directory.Path, "Mods");
|
|
private string Work => Path.Combine(_directory.Path, "Work");
|
|
|
|
public TestCatalogTests()
|
|
{
|
|
Directory.CreateDirectory(Mods);
|
|
using var cache = AetheriaStores.Open(Shipped, catalogWritable: true);
|
|
// The test assembly registers TestCatalogGlobal (AetheriaStoresTests), so any populated catalog must hold one.
|
|
cache.Upsert(new TestCatalogGlobal { Name = "Temperament" });
|
|
cache.Upsert(new HullData { Name = "Wasp", Shape = ShipAuthoringTests.Fixture().Hull.Shape });
|
|
cache.FlushAsync().Wait();
|
|
}
|
|
|
|
public void Dispose() => _directory.Dispose();
|
|
|
|
[Fact]
|
|
public void NoModsMeansTheShippedCatalog()
|
|
{
|
|
var before = File.ReadAllBytes(Shipped);
|
|
|
|
Assert.Equal(Shipped, TestCatalog.Resolve(Shipped, Path.Combine(_directory.Path, "absent"), Work));
|
|
Assert.Equal(Shipped, TestCatalog.Resolve(Shipped, Mods, Work));
|
|
|
|
Assert.Equal(SHA256.HashData(before), SHA256.HashData(File.ReadAllBytes(Shipped)));
|
|
}
|
|
|
|
[Fact]
|
|
public void APackageReachesTheFixture()
|
|
{
|
|
ShipFixture.WritePackage(Mods, "mod.skiff");
|
|
|
|
var catalog = TestCatalog.Resolve(Shipped, Mods, Work);
|
|
|
|
Assert.NotEqual(Shipped, catalog);
|
|
using var cache = AetheriaStores.Open(catalog);
|
|
Assert.Equal("Skiff", cache.Get<HullData>(ShipModCatalog.HullKey("mod.skiff")).Name);
|
|
Assert.Contains("Wasp", cache.GetAll<HullData>().Select(hull => hull.Name));
|
|
}
|
|
|
|
[Fact]
|
|
public void ABrokenPackageFailsLoudly()
|
|
{
|
|
ShipFixture.WritePackage(Mods, "mod.good", hullName: "Good");
|
|
ShipFixture.WritePackage(Mods, "mod.broken", hullName: "Broken");
|
|
File.Delete(Path.Combine(Mods, "mod.broken", "skiff.glb"));
|
|
|
|
var error = Assert.Throws<InvalidOperationException>(() => TestCatalog.Resolve(Shipped, Mods, Work));
|
|
|
|
Assert.Contains("mod.broken", error.Message);
|
|
Assert.DoesNotContain("mod.good", error.Message);
|
|
}
|
|
}
|