A migration step has been added to rename it for the user.pull/63/head
parent
bede26c213
commit
5e118cf07c
@ -0,0 +1,60 @@
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using System.Text.RegularExpressions;
|
||||
using AutoFixture.NUnit3;
|
||||
using FluentAssertions;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using Recyclarr.Migration;
|
||||
using Recyclarr.Migration.Steps;
|
||||
using Serilog;
|
||||
using TestLibrary.AutoFixture;
|
||||
|
||||
namespace Recyclarr.Tests.Migration.Steps;
|
||||
|
||||
[TestFixture]
|
||||
[Parallelizable(ParallelScope.All)]
|
||||
public class MigrateTrashUpdaterAppDataDirTest
|
||||
{
|
||||
private static readonly string BasePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||
|
||||
[Test, AutoMockData]
|
||||
public void Migration_check_returns_true_if_trash_updater_dir_exists(
|
||||
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||||
MigrateTrashUpdaterAppDataDir sut)
|
||||
{
|
||||
fs.AddDirectory(Path.Combine(BasePath, "trash-updater"));
|
||||
sut.CheckIfNeeded().Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test, AutoMockData]
|
||||
public void Migration_check_returns_false_if_trash_updater_dir_doesnt_exists(
|
||||
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||||
MigrateTrashUpdaterAppDataDir sut)
|
||||
{
|
||||
sut.CheckIfNeeded().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test, AutoMockData]
|
||||
public void Migration_throws_if_recyclarr_dir_already_exists(
|
||||
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||||
MigrateTrashUpdaterAppDataDir sut)
|
||||
{
|
||||
fs.AddDirectory(Path.Combine(BasePath, "recyclarr"));
|
||||
|
||||
var act = () => sut.Execute(Substitute.For<ILogger>());
|
||||
|
||||
act.Should().Throw<MigrationException>().WithMessage("*already exist*");
|
||||
}
|
||||
|
||||
[Test, AutoMockData]
|
||||
public void Migration_success(
|
||||
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||||
MigrateTrashUpdaterAppDataDir sut)
|
||||
{
|
||||
fs.AddDirectory(Path.Combine(BasePath, "trash-updater"));
|
||||
|
||||
sut.Execute(Substitute.For<ILogger>());
|
||||
|
||||
fs.AllDirectories.Should().ContainSingle(x => Regex.IsMatch(x, @"[/\\]recyclarr$"));
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
using System.IO.Abstractions;
|
||||
using JetBrains.Annotations;
|
||||
using Serilog;
|
||||
|
||||
namespace Recyclarr.Migration.Steps;
|
||||
|
||||
/// <summary>
|
||||
/// Rename `trash.yml` to `recyclarr.yml`.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implemented on 4/30/2022.
|
||||
/// </remarks>
|
||||
[UsedImplicitly]
|
||||
public class MigrateTrashUpdaterAppDataDir : IMigrationStep
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
private readonly string _oldPath =
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "trash-updater");
|
||||
|
||||
// Do not use AppPaths class here since that may change yet again in the future and break this migration step.
|
||||
private readonly string _newPath =
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "recyclarr");
|
||||
|
||||
public MigrateTrashUpdaterAppDataDir(IFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
|
||||
public int Order => 20;
|
||||
|
||||
public string Description => "Rename app data directory from 'trash-updater' to 'recyclarr'";
|
||||
|
||||
public bool CheckIfNeeded() => _fileSystem.Directory.Exists(_oldPath);
|
||||
|
||||
public void Execute(ILogger log)
|
||||
{
|
||||
try
|
||||
{
|
||||
_fileSystem.Directory.Move(_oldPath, _newPath);
|
||||
log.Information("Migration: App data directory renamed from {Old} to {New}", _oldPath, _newPath);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
throw new MigrationException(Description,
|
||||
$"Unable to move due to IO Exception (does the '${_newPath}' directory already exist?)");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue