Fix a couple of remaining cases of tests not using the new temporary file location for storage

This commit is contained in:
Dean Herbert 2021-12-24 20:17:47 +09:00
parent 4b88e257e5
commit be02c3f9f8
2 changed files with 10 additions and 45 deletions

View File

@ -2,10 +2,11 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.IO; using System.IO;
using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Tests; using osu.Game.Tests;
using osu.Game.Tournament.Configuration; using osu.Game.Tournament.Configuration;
@ -36,9 +37,9 @@ namespace osu.Game.Tournament.Tests.NonVisual
[Test] [Test]
public void TestCustomDirectory() public void TestCustomDirectory()
{ {
using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestCustomDirectory))) // don't use clean run as we are writing a config file. using (HeadlessGameHost host = new TestRunHeadlessGameHost(nameof(TestCustomDirectory))) // don't use clean run as we are writing a config file.
{ {
string osuDesktopStorage = PrepareBasePath(nameof(TestCustomDirectory)); string osuDesktopStorage = Path.Combine(host.UserStoragePaths.First(), nameof(TestCustomDirectory));
const string custom_tournament = "custom"; const string custom_tournament = "custom";
// need access before the game has constructed its own storage yet. // need access before the game has constructed its own storage yet.
@ -60,15 +61,6 @@ namespace osu.Game.Tournament.Tests.NonVisual
finally finally
{ {
host.Exit(); host.Exit();
try
{
if (Directory.Exists(osuDesktopStorage))
Directory.Delete(osuDesktopStorage, true);
}
catch
{
}
} }
} }
} }
@ -76,9 +68,9 @@ namespace osu.Game.Tournament.Tests.NonVisual
[Test] [Test]
public void TestMigration() public void TestMigration()
{ {
using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestMigration))) // don't use clean run as we are writing test files for migration. using (HeadlessGameHost host = new TestRunHeadlessGameHost(nameof(TestMigration))) // don't use clean run as we are writing test files for migration.
{ {
string osuRoot = PrepareBasePath(nameof(TestMigration)); string osuRoot = Path.Combine(host.UserStoragePaths.First(), nameof(TestMigration));
string configFile = Path.Combine(osuRoot, "tournament.ini"); string configFile = Path.Combine(osuRoot, "tournament.ini");
if (File.Exists(configFile)) if (File.Exists(configFile))
@ -146,28 +138,8 @@ namespace osu.Game.Tournament.Tests.NonVisual
finally finally
{ {
host.Exit(); host.Exit();
try
{
if (Directory.Exists(osuRoot))
Directory.Delete(osuRoot, true);
}
catch
{
}
} }
} }
} }
public static string PrepareBasePath(string testInstance)
{
string basePath = Path.Combine(RuntimeInfo.StartupDirectory, "headless", testInstance);
// manually clean before starting in case there are left-over files at the test site.
if (Directory.Exists(basePath))
Directory.Delete(basePath, true);
return basePath;
}
} }
} }

View File

@ -2,9 +2,11 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.IO; using System.IO;
using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Tournament.IO; using osu.Game.Tournament.IO;
using osu.Game.Tournament.IPC; using osu.Game.Tournament.IPC;
@ -17,9 +19,9 @@ namespace osu.Game.Tournament.Tests.NonVisual
public void CheckIPCLocation() public void CheckIPCLocation()
{ {
// don't use clean run because files are being written before osu! launches. // don't use clean run because files are being written before osu! launches.
using (HeadlessGameHost host = new HeadlessGameHost(nameof(CheckIPCLocation))) using (var host = new TestRunHeadlessGameHost(nameof(CheckIPCLocation)))
{ {
string basePath = CustomTourneyDirectoryTest.PrepareBasePath(nameof(CheckIPCLocation)); string basePath = Path.Combine(host.UserStoragePaths.First(), nameof(CheckIPCLocation));
// Set up a fake IPC client for the IPC Storage to switch to. // Set up a fake IPC client for the IPC Storage to switch to.
string testStableInstallDirectory = Path.Combine(basePath, "stable-ce"); string testStableInstallDirectory = Path.Combine(basePath, "stable-ce");
@ -42,15 +44,6 @@ namespace osu.Game.Tournament.Tests.NonVisual
finally finally
{ {
host.Exit(); host.Exit();
try
{
if (Directory.Exists(basePath))
Directory.Delete(basePath, true);
}
catch
{
}
} }
} }
} }