refactor: Move app path creation to DefaultAppDataSetup

integration-tests
Robert Dailey 5 months ago
parent 2327d224fe
commit 39f0070317

@ -100,7 +100,6 @@ public static class CompositionRoot
private static void CommandRegistrations(ContainerBuilder builder)
{
builder.RegisterTypes(
typeof(AppPathSetupTask),
typeof(JanitorCleanupTask))
.As<IBaseCommandSetupTask>()
.OrderByRegistration();

@ -1,22 +0,0 @@
using Recyclarr.Platform;
namespace Recyclarr.Cli.Console.Setup;
public class AppPathSetupTask(ILogger log, IAppPaths paths) : IBaseCommandSetupTask
{
public void OnStart()
{
log.Debug("App Data Dir: {AppData}", paths.AppDataDirectory);
// Initialize other directories used throughout the application
// Do not initialize the repo directory here; the GitRepositoryFactory handles that later.
paths.CacheDirectory.Create();
paths.LogDirectory.Create();
paths.ConfigsDirectory.Create();
}
public void OnFinish()
{
// No work to do for this event
}
}

@ -1,8 +1,10 @@
using System.IO.Abstractions;
using Serilog;
namespace Recyclarr.Platform;
public class DefaultAppDataSetup(
ILogger log,
IEnvironment env,
IFileSystem fs,
IRuntimeInformation runtimeInfo)
@ -10,7 +12,17 @@ public class DefaultAppDataSetup(
public IAppPaths CreateAppPaths(string? appDataDirectoryOverride = null)
{
var appDir = GetAppDataDirectory(appDataDirectoryOverride);
return new AppPaths(fs.DirectoryInfo.New(appDir));
var paths = new AppPaths(fs.DirectoryInfo.New(appDir));
log.Debug("App Data Dir: {AppData}", paths.AppDataDirectory);
// Initialize other directories used throughout the application
// Do not initialize the repo directory here; the GitRepositoryFactory handles that later.
paths.CacheDirectory.Create();
paths.LogDirectory.Create();
paths.ConfigsDirectory.Create();
return paths;
}
private string GetAppDataDirectory(string? appDataDirectoryOverride)

@ -14,8 +14,7 @@ internal class BaseCommandSetupIntegrationTest : CliIntegrationFixture
var registrations = Resolve<IEnumerable<IBaseCommandSetupTask>>();
registrations.Select(x => x.GetType()).Should().BeEquivalentTo(new[]
{
typeof(JanitorCleanupTask),
typeof(AppPathSetupTask)
typeof(JanitorCleanupTask)
});
}
@ -60,25 +59,4 @@ internal class BaseCommandSetupIntegrationTest : CliIntegrationFixture
Fs.AllFiles.Where(x => x.StartsWith(Paths.LogDirectory.FullName))
.Should().HaveCount(maxFiles);
}
[Test]
public void App_paths_setup_creates_initial_directories()
{
for (var i = 0; i < 50; ++i)
{
Fs.AddFile(Paths.LogDirectory.File($"logfile-{i}.log").FullName, new MockFileData(""));
}
var sut = Resolve<AppPathSetupTask>();
sut.OnStart();
var expectedDirs = new[]
{
Paths.CacheDirectory.FullName,
Paths.LogDirectory.FullName,
Paths.ConfigsDirectory.FullName
};
Fs.LeafDirectories().Should().BeEquivalentTo(expectedDirs);
}
}

Loading…
Cancel
Save