1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 19:42:55 +08:00

Add drawings to the migration test

This commit is contained in:
Shivam 2020-06-11 20:11:44 +02:00
parent 592e3bf4c9
commit 56a40e616b
2 changed files with 30 additions and 12 deletions

View File

@ -3,7 +3,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using NUnit.Framework; using NUnit.Framework;
@ -48,7 +47,7 @@ namespace osu.Game.Tournament.Tests.NonVisual
{ {
using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestCustomDirectory))) using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestCustomDirectory)))
{ {
string osuDesktopStorage = Path.Combine(RuntimeInfo.StartupDirectory, "headless", nameof(TestCustomDirectory)); string osuDesktopStorage = basePath(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.
@ -80,23 +79,34 @@ namespace osu.Game.Tournament.Tests.NonVisual
using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestMigration))) using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestMigration)))
{ {
// Recreate the old setup that uses "tournament" as the base path. // Recreate the old setup that uses "tournament" as the base path.
string basePath = Path.Combine(RuntimeInfo.StartupDirectory, "headless", nameof(TestMigration), "tournament"); string osuRoot = basePath(nameof(TestMigration));
string videosPath = Path.Combine(basePath, "videos"); // Define all the paths for the old scenario
string modsPath = Path.Combine(basePath, "mods"); string oldPath = Path.Combine(osuRoot, "tournament");
string flagsPath = Path.Combine(basePath, "flags"); string videosPath = Path.Combine(oldPath, "videos");
string modsPath = Path.Combine(oldPath, "mods");
string flagsPath = Path.Combine(oldPath, "flags");
Directory.CreateDirectory(videosPath); Directory.CreateDirectory(videosPath);
Directory.CreateDirectory(modsPath); Directory.CreateDirectory(modsPath);
Directory.CreateDirectory(flagsPath); Directory.CreateDirectory(flagsPath);
string bracketFile = Path.Combine(RuntimeInfo.StartupDirectory, "headless", nameof(TestMigration), "bracket.json"); // Define testing files corresponding to the specific file migrations that are needed
string bracketFile = Path.Combine(osuRoot, "bracket.json");
string drawingsConfig = Path.Combine(osuRoot, "drawings.ini");
string drawingsFile = Path.Combine(osuRoot, "drawings.txt");
string drawingsResult = Path.Combine(osuRoot, "drawings_results.txt");
// Define sample files to test recursive copying
string videoFile = Path.Combine(videosPath, "video.mp4"); string videoFile = Path.Combine(videosPath, "video.mp4");
string modFile = Path.Combine(modsPath, "mod.png"); string modFile = Path.Combine(modsPath, "mod.png");
string flagFile = Path.Combine(flagsPath, "flag.png"); string flagFile = Path.Combine(flagsPath, "flag.png");
File.WriteAllText(bracketFile, "{}"); File.WriteAllText(bracketFile, "{}");
File.WriteAllText(drawingsConfig, "test");
File.WriteAllText(drawingsFile, "test");
File.WriteAllText(drawingsResult, "test");
File.WriteAllText(videoFile, "test"); File.WriteAllText(videoFile, "test");
File.WriteAllText(modFile, "test"); File.WriteAllText(modFile, "test");
File.WriteAllText(flagFile, "test"); File.WriteAllText(flagFile, "test");
@ -118,7 +128,13 @@ namespace osu.Game.Tournament.Tests.NonVisual
flagFile = Path.Combine(flagsPath, "flag.png"); flagFile = Path.Combine(flagsPath, "flag.png");
Assert.That(storage.GetFullPath("."), Is.EqualTo(migratedPath)); Assert.That(storage.GetFullPath("."), Is.EqualTo(migratedPath));
Assert.That(storage.GetFiles(".", "bracket.json").Single(), Is.EqualTo("bracket.json"));
Assert.True(storage.Exists("bracket.json"));
Assert.True(storage.Exists("drawings.txt"));
Assert.True(storage.Exists("drawings_results.txt"));
Assert.True(storage.ConfigurationStorage.Exists("drawings.ini"));
Assert.True(storage.Exists(videoFile)); Assert.True(storage.Exists(videoFile));
Assert.True(storage.Exists(modFile)); Assert.True(storage.Exists(modFile));
Assert.True(storage.Exists(flagFile)); Assert.True(storage.Exists(flagFile));
@ -128,7 +144,6 @@ namespace osu.Game.Tournament.Tests.NonVisual
// Cleaning up after ourselves. // Cleaning up after ourselves.
host.Storage.Delete("tournament.ini"); host.Storage.Delete("tournament.ini");
host.Storage.DeleteDirectory("tournaments"); host.Storage.DeleteDirectory("tournaments");
host.Exit(); host.Exit();
} }
} }
@ -151,6 +166,9 @@ namespace osu.Game.Tournament.Tests.NonVisual
Assert.IsTrue(task.Wait(timeout), failureMessage); Assert.IsTrue(task.Wait(timeout), failureMessage);
} }
private string tournamentBasePath(string testInstance) => Path.Combine(RuntimeInfo.StartupDirectory, "headless", testInstance, "tournaments");
private string basePath(string testInstance) => Path.Combine(RuntimeInfo.StartupDirectory, "headless", testInstance);
private string tournamentBasePath(string testInstance) => Path.Combine(basePath(testInstance), "tournaments");
} }
} }