feat: Debug diagnostics for migrate subcommand

pull/76/head
Robert Dailey 2 years ago
parent c593675f3d
commit 37d52b583a

@ -36,10 +36,10 @@ public class MigrationExecutorTest
step.CheckIfNeeded().Returns(false);
executor.PerformAllMigrationSteps();
executor.PerformAllMigrationSteps(false);
step.Received().CheckIfNeeded();
step.DidNotReceive().Execute();
step.DidNotReceive().Execute(null);
}
[Test]
@ -51,10 +51,10 @@ public class MigrationExecutorTest
step.CheckIfNeeded().Returns(true);
executor.PerformAllMigrationSteps();
executor.PerformAllMigrationSteps(false);
step.Received().CheckIfNeeded();
step.Received().Execute();
step.Received().Execute(null);
}
[Test]
@ -75,7 +75,7 @@ public class MigrationExecutorTest
var executor = new MigrationExecutor(steps, console);
executor.PerformAllMigrationSteps();
executor.PerformAllMigrationSteps(false);
Received.InOrder(() =>
{
@ -93,9 +93,9 @@ public class MigrationExecutorTest
var executor = new MigrationExecutor(new[] {step}, console);
step.CheckIfNeeded().Returns(true);
step.When(x => x.Execute()).Throw(new ArgumentException("test message"));
step.When(x => x.Execute(null)).Throw(new ArgumentException("test message"));
var act = () => executor.PerformAllMigrationSteps();
var act = () => executor.PerformAllMigrationSteps(false);
act.Should().Throw<MigrationException>().Which.OriginalException.Message.Should().Be("test message");
}
@ -109,9 +109,9 @@ public class MigrationExecutorTest
var exception = new MigrationException(new Exception(), "a", new[] {"b"});
step.CheckIfNeeded().Returns(true);
step.When(x => x.Execute()).Throw(exception);
step.When(x => x.Execute(null)).Throw(exception);
var act = () => executor.PerformAllMigrationSteps();
var act = () => executor.PerformAllMigrationSteps(false);
act.Should().Throw<MigrationException>().Which.Should().Be(exception);
}

@ -40,7 +40,7 @@ public class MigrateTrashUpdaterAppDataDirTest
fs.AddDirectory(Path.Combine(BasePath, "trash-updater"));
fs.AddDirectory(Path.Combine(BasePath, "recyclarr"));
var act = sut.Execute;
var act = () => sut.Execute(null);
act.Should().Throw<IOException>();
}
@ -54,7 +54,7 @@ public class MigrateTrashUpdaterAppDataDirTest
// Add file instead of directory since the migration step only operates on files
fs.AddFile(fs.Path.Combine(paths.BasePath, "trash-updater", "1", "2", "test.txt"), new MockFileData(""));
sut.Execute();
sut.Execute(null);
fs.AllDirectories.Should().NotContain(x => x.Contains("trash-updater"));
fs.AllFiles.Should().Contain(x => Regex.IsMatch(x, @"[/\\]recyclarr[/\\]1[/\\]2[/\\]test.txt$"));

@ -38,7 +38,7 @@ public class MigrateTrashYmlTest
{
fs.AddFile(Path.Combine(BasePath, "recyclarr.yml"), MockFileData.NullObject);
var act = () => sut.Execute();
var act = () => sut.Execute(null);
act.Should().Throw<IOException>();
}
@ -51,7 +51,7 @@ public class MigrateTrashYmlTest
const string expectedData = "fake contents";
fs.AddFile(Path.Combine(BasePath, "trash.yml"), expectedData);
sut.Execute();
sut.Execute(null);
fs.AllFiles.Should().ContainSingle(x => Regex.IsMatch(x, @"[/\\]recyclarr\.yml$"));
}

@ -16,6 +16,10 @@ public class MigrateCommand : ICommand
private readonly IMigrationExecutor _migration;
private readonly IDefaultAppDataSetup _appDataSetup;
[CommandOption("debug", 'd', Description =
"Display additional logs useful for development/debug purposes.")]
public bool Debug { get; [UsedImplicitly] set; } = false;
public MigrateCommand(IMigrationExecutor migration, IDefaultAppDataSetup appDataSetup)
{
_migration = migration;
@ -33,7 +37,7 @@ public class MigrateCommand : ICommand
{
try
{
_migration.PerformAllMigrationSteps();
_migration.PerformAllMigrationSteps(Debug);
}
catch (MigrationException e)
{

@ -2,6 +2,6 @@ namespace Recyclarr.Migration;
public interface IMigrationExecutor
{
void PerformAllMigrationSteps();
void PerformAllMigrationSteps(bool withDiagnostics);
void CheckNeededMigrations();
}

@ -1,3 +1,5 @@
using CliFx.Infrastructure;
namespace Recyclarr.Migration;
public interface IMigrationStep
@ -7,5 +9,5 @@ public interface IMigrationStep
IReadOnlyCollection<string> Remediation { get; }
bool Required { get; }
bool CheckIfNeeded();
void Execute();
void Execute(IConsole? console);
}

@ -14,7 +14,7 @@ public class MigrationExecutor : IMigrationExecutor
_migrationSteps = migrationSteps.OrderBy(x => x.Order).ToList();
}
public void PerformAllMigrationSteps()
public void PerformAllMigrationSteps(bool withDiagnostics)
{
_console.Output.WriteLine("Performing migration steps...");
@ -31,7 +31,7 @@ public class MigrationExecutor : IMigrationExecutor
try
{
step.Execute();
step.Execute(withDiagnostics ? _console : null);
}
catch (Exception e) when (e is not MigrationException)
{

@ -1,4 +1,5 @@
using System.IO.Abstractions;
using CliFx.Infrastructure;
using Common.Extensions;
using JetBrains.Annotations;
using TrashLib;
@ -41,5 +42,5 @@ public class MigrateTrashUpdaterAppDataDir : IMigrationStep
public bool CheckIfNeeded() => _fs.Directory.Exists(GetOldPath());
public void Execute() => _fs.MergeDirectory(GetOldPath(), GetNewPath());
public void Execute(IConsole? console) => _fs.MergeDirectory(GetOldPath(), GetNewPath());
}

@ -1,4 +1,5 @@
using System.IO.Abstractions;
using CliFx.Infrastructure;
using JetBrains.Annotations;
namespace Recyclarr.Migration.Steps;
@ -35,7 +36,7 @@ public class MigrateTrashYml : IMigrationStep
public bool CheckIfNeeded() => _fileSystem.File.Exists(_oldConfigPath);
public void Execute()
public void Execute(IConsole? console)
{
_fileSystem.File.Move(_oldConfigPath, _newConfigPath);
}

Loading…
Cancel
Save