diff --git a/tests/CapySR.Tests/FlowTests.cs b/tests/CapySR.Tests/FlowTests.cs index aa5c640..557db7a 100644 --- a/tests/CapySR.Tests/FlowTests.cs +++ b/tests/CapySR.Tests/FlowTests.cs @@ -13,7 +13,7 @@ namespace CapySR.Tests; // the whole pipeline through a real gateway: login, teams, overworld fights, a MOC floor public class FlowTests(ITestOutputHelper output) { - private static readonly GameWorld World = new(TestConfig(), NullLogger.Instance); + private static GameWorld World => TestWorld.Current; // the default harness plays real stages so an assertion about a fight is about the data, // not about whatever freesr-data.json happens to hold @@ -66,7 +66,7 @@ public class FlowTests(ITestOutputHelper output) } } - private static bool HasData => new DataConfig().ResolvedSources.Any(Directory.Exists); + private static bool HasData => TestWorld.Available; [Fact] public async Task RosterAndTeamsLoad() @@ -283,9 +283,14 @@ public class FlowTests(ITestOutputHelper output) [Fact] public async Task CalyxPlaysTheConfiguredBattle() { + if (!HasData) + { + return; + } + var configured = World.Player.BattleConfig; - if (!HasData || configured.StageId == 0) + if (configured.StageId == 0) { output.WriteLine("no srtools battle_config; skipping"); return; @@ -489,6 +494,11 @@ public class FlowTests(ITestOutputHelper output) return; } + if (!HasData) + { + return; + } + var floor = World.Data.Challenges.Values .Where(c => c.Kind == Data.Excel.ChallengeKind.MemoryOfChaos && c.NodeCount == 2) .OrderBy(c => c.ID) diff --git a/tests/CapySR.Tests/GatewayIntegrationTests.cs b/tests/CapySR.Tests/GatewayIntegrationTests.cs index 59494be..77cd9af 100644 --- a/tests/CapySR.Tests/GatewayIntegrationTests.cs +++ b/tests/CapySR.Tests/GatewayIntegrationTests.cs @@ -12,12 +12,16 @@ namespace CapySR.Tests; public class GatewayIntegrationTests { // one world for the whole class; loading the tables is the slow part - private static readonly GameWorld World = - new(new ServerConfig(), NullLogger.Instance); + private static GameWorld World => TestWorld.Current; [Fact] public async Task ClientCompletesHandshakeAndLogin() { + if (!TestWorld.Available) + { + return; + } + var port = FreeUdpPort(); // Persist off: a test must not read or write the machine's saved profile var config = new ServerConfig { GameServer = { Host = "127.0.0.1", Port = port, Nickname = "Capybara", Persist = false } }; @@ -54,6 +58,11 @@ public class GatewayIntegrationTests [Fact] public async Task UnmodelledRequestStillGetsAnswered() { + if (!TestWorld.Available) + { + return; + } + var port = FreeUdpPort(); var config = new ServerConfig { GameServer = { Host = "127.0.0.1", Port = port, Persist = false } }; var handlers = HandlerRegistry.Build(NullLogger.Instance); diff --git a/tests/CapySR.Tests/TestWorld.cs b/tests/CapySR.Tests/TestWorld.cs new file mode 100644 index 0000000..08828a6 --- /dev/null +++ b/tests/CapySR.Tests/TestWorld.cs @@ -0,0 +1,18 @@ +using CapySR.Common; +using CapySR.GameServer.Game; +using Microsoft.Extensions.Logging.Abstractions; + +namespace CapySR.Tests; + +// The game data is a separate checkout, so a fresh clone has none. Tests that need it check +// Available and return instead of failing. Building the world is deferred for the same +// reason, and shared because loading the tables is the slow part of the suite. +internal static class TestWorld +{ + private static readonly Lazy Instance = + new(() => new GameWorld(new ServerConfig(), NullLogger.Instance)); + + public static bool Available { get; } = new DataConfig().ResolvedSources.Any(Directory.Exists); + + public static GameWorld Current => Instance.Value; +}