parent
72c4596347
commit
6a00888c85
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,105 @@
|
||||
using System.IO.Abstractions;
|
||||
using Autofac;
|
||||
using Autofac.Features.ResolveAnything;
|
||||
using Recyclarr.Compatibility;
|
||||
using Recyclarr.Platform;
|
||||
using Recyclarr.Repo;
|
||||
using Recyclarr.TestLibrary;
|
||||
using Recyclarr.TestLibrary.Autofac;
|
||||
using Recyclarr.VersionControl;
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Testing;
|
||||
|
||||
namespace Recyclarr.Cli.IntegrationTests;
|
||||
|
||||
public abstract class IntegrationTestFixture2 : IDisposable
|
||||
{
|
||||
private readonly Lazy<ILifetimeScope> _container;
|
||||
|
||||
protected ILifetimeScope Container => _container.Value;
|
||||
protected MockFileSystem Fs { get; }
|
||||
protected TestConsole Console { get; } = new();
|
||||
protected TestableLogger Logger { get; } = new();
|
||||
|
||||
protected IntegrationTestFixture2()
|
||||
{
|
||||
Fs = new MockFileSystem(new MockFileSystemOptions
|
||||
{
|
||||
CreateDefaultTempDir = false
|
||||
});
|
||||
|
||||
// Use Lazy because we shouldn't invoke virtual methods at construction time
|
||||
_container = new Lazy<ILifetimeScope>(() =>
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
RegisterTypes(builder);
|
||||
RegisterStubsAndMocks(builder);
|
||||
builder.RegisterSource<AnyConcreteTypeNotAlreadyRegisteredSource>();
|
||||
return builder.Build();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register "real" types (usually Module-derived classes from other projects). This call happens
|
||||
/// before
|
||||
/// RegisterStubsAndMocks().
|
||||
/// </summary>
|
||||
protected virtual void RegisterTypes(ContainerBuilder builder)
|
||||
{
|
||||
CompositionRoot.Setup(builder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override registrations made in the RegisterTypes() method. This method is called after
|
||||
/// RegisterTypes().
|
||||
/// </summary>
|
||||
protected virtual void RegisterStubsAndMocks(ContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterType<StubEnvironment>().As<IEnvironment>();
|
||||
|
||||
builder.RegisterInstance(Fs).As<IFileSystem>().AsSelf();
|
||||
builder.RegisterInstance(Console).As<IAnsiConsole>();
|
||||
builder.RegisterInstance(Logger).As<ILogger>();
|
||||
|
||||
builder.RegisterMockFor<IGitRepository>();
|
||||
builder.RegisterMockFor<IGitRepositoryFactory>();
|
||||
builder.RegisterMockFor<IServiceInformation>(m =>
|
||||
{
|
||||
// By default, choose some extremely high number so that all the newest features are enabled.
|
||||
m.GetVersion().ReturnsForAnyArgs(_ => new Version("99.0.0.0"));
|
||||
});
|
||||
|
||||
builder.RegisterDecorator<StubTrashRepoMetadataBuilder, IRepoMetadataBuilder>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void DumpLogsToConsole()
|
||||
{
|
||||
foreach (var line in Console.Lines)
|
||||
{
|
||||
System.Console.WriteLine(line);
|
||||
}
|
||||
}
|
||||
|
||||
protected T Resolve<T>() where T : notnull
|
||||
{
|
||||
return Container.Resolve<T>();
|
||||
}
|
||||
|
||||
// ReSharper disable once VirtualMemberNeverOverridden.Global
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposing || !_container.IsValueCreated)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_container.Value.Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
using System.IO.Abstractions;
|
||||
using Recyclarr.Common.Extensions;
|
||||
using Recyclarr.Platform;
|
||||
|
||||
namespace Recyclarr.Cli.IntegrationTests;
|
||||
|
||||
public class StubEnvironment(IFileSystem fs) : IEnvironment
|
||||
{
|
||||
private readonly Dictionary<string, string> _env = new();
|
||||
|
||||
private IDirectoryInfo BuildSpecialFolderPath(Environment.SpecialFolder folder)
|
||||
{
|
||||
return fs.CurrentDirectory().SubDirectory("special_folder", folder.ToString());
|
||||
}
|
||||
|
||||
public string GetFolderPath(Environment.SpecialFolder folder)
|
||||
{
|
||||
return BuildSpecialFolderPath(folder).FullName;
|
||||
}
|
||||
|
||||
public string GetFolderPath(Environment.SpecialFolder folder, Environment.SpecialFolderOption folderOption)
|
||||
{
|
||||
var path = BuildSpecialFolderPath(folder);
|
||||
if (folderOption == Environment.SpecialFolderOption.Create)
|
||||
{
|
||||
path.Create();
|
||||
}
|
||||
|
||||
return path.FullName;
|
||||
}
|
||||
|
||||
public void AddEnvironmentVariable(string variable, string value)
|
||||
{
|
||||
_env.Add(variable, value);
|
||||
}
|
||||
|
||||
public string? GetEnvironmentVariable(string variable)
|
||||
{
|
||||
return _env.GetValueOrDefault(variable);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
using System.IO.Abstractions;
|
||||
using Recyclarr.Repo;
|
||||
using Recyclarr.TestLibrary;
|
||||
|
||||
namespace Recyclarr.Cli.IntegrationTests;
|
||||
|
||||
public class StubTrashRepoMetadataBuilder : IRepoMetadataBuilder
|
||||
{
|
||||
private readonly IRepoMetadataBuilder _metadata;
|
||||
|
||||
private const string MetadataJson =
|
||||
"""
|
||||
{
|
||||
"json_paths": {
|
||||
"radarr": {
|
||||
"custom_formats": ["docs/json/radarr/cf"],
|
||||
"qualities": ["docs/json/radarr/quality-size"],
|
||||
"naming": ["docs/json/radarr/naming"]
|
||||
},
|
||||
"sonarr": {
|
||||
"release_profiles": ["docs/json/sonarr/rp"],
|
||||
"custom_formats": ["docs/json/sonarr/cf"],
|
||||
"qualities": ["docs/json/sonarr/quality-size"],
|
||||
"naming": ["docs/json/sonarr/naming"]
|
||||
}
|
||||
},
|
||||
"recyclarr": {
|
||||
"templates": "docs/recyclarr-configs"
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
public StubTrashRepoMetadataBuilder(MockFileSystem fs, IRepoMetadataBuilder metadata)
|
||||
{
|
||||
_metadata = metadata;
|
||||
fs.AddFile(MetadataPath, new MockFileData(MetadataJson));
|
||||
fs.AddSameFileFromEmbeddedResource(
|
||||
DocsDirectory.SubDirectory("Radarr").File("Radarr-collection-of-custom-formats.md"),
|
||||
typeof(StubTrashRepoMetadataBuilder));
|
||||
fs.AddSameFileFromEmbeddedResource(
|
||||
DocsDirectory.SubDirectory("Sonarr").File("sonarr-collection-of-custom-formats.md"),
|
||||
typeof(StubTrashRepoMetadataBuilder));
|
||||
}
|
||||
|
||||
public IDirectoryInfo DocsDirectory => _metadata.DocsDirectory;
|
||||
public IFileInfo MetadataPath => _metadata.MetadataPath;
|
||||
|
||||
public RepoMetadata GetMetadata() => _metadata.GetMetadata();
|
||||
|
||||
public IReadOnlyList<IDirectoryInfo> ToDirectoryInfoList(IEnumerable<string> listOfDirectories)
|
||||
=> _metadata.ToDirectoryInfoList(listOfDirectories);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace Recyclarr.Cli.IntegrationTests;
|
||||
namespace Recyclarr.Cli.IntegrationTests.Tests;
|
||||
|
||||
[TestFixture]
|
||||
internal class AutoMapperConfigurationTest : CliIntegrationFixture
|
@ -1,7 +1,7 @@
|
||||
using System.IO.Abstractions;
|
||||
using Recyclarr.Cli.Processors.Config;
|
||||
|
||||
namespace Recyclarr.Cli.IntegrationTests;
|
||||
namespace Recyclarr.Cli.IntegrationTests.Tests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ConfigManipulatorTest : CliIntegrationFixture
|
@ -0,0 +1,55 @@
|
||||
using System.IO.Abstractions;
|
||||
using Autofac;
|
||||
using Recyclarr.Cli.Console.Commands;
|
||||
using Recyclarr.Common.Extensions;
|
||||
using Recyclarr.Platform;
|
||||
using Recyclarr.TestLibrary.Autofac;
|
||||
using Recyclarr.TestLibrary.AutoFixture;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Recyclarr.Cli.IntegrationTests.Tests;
|
||||
|
||||
[TestFixture]
|
||||
public class PlatformIntegrationTest : IntegrationTestFixture2
|
||||
{
|
||||
protected override void RegisterStubsAndMocks(ContainerBuilder builder)
|
||||
{
|
||||
base.RegisterStubsAndMocks(builder);
|
||||
builder.RegisterMockFor<IRuntimeInformation>();
|
||||
}
|
||||
|
||||
[Test, AutoMockData]
|
||||
public async Task Migrate_app_data_on_mac_os_dotnet8(CommandContext ctx)
|
||||
{
|
||||
// The "old" app data directory has to be in place before we create SyncCommand, since we want the
|
||||
// automatic/transparent move of that directory to happen before the migration system checks it.
|
||||
var env = Resolve<IEnvironment>();
|
||||
|
||||
var oldPath = new AppPaths(Fs.DirectoryInfo
|
||||
.New(env.GetFolderPath(Environment.SpecialFolder.UserProfile))
|
||||
.SubDirectory(".config", AppPaths.DefaultAppDataDirectoryName));
|
||||
|
||||
Fs.AddFile(oldPath.ConfigsDirectory.File("test.yml"), new MockFileData(
|
||||
"""
|
||||
radarr:
|
||||
test_instance:
|
||||
base_url: http://localhost:1000
|
||||
api_key: key
|
||||
"""));
|
||||
|
||||
// Fs.AddEmptyFile(oldPath.File("test.yml"));
|
||||
|
||||
// The runtime info mocking has to happen before the instantiation of SyncCommand.
|
||||
var runtimeInfo = Resolve<IRuntimeInformation>();
|
||||
runtimeInfo.IsPlatformOsx().Returns(true);
|
||||
|
||||
var cmd = Resolve<SyncCommand>();
|
||||
var settings = new SyncCommand.CliSettings();
|
||||
var newPath = Resolve<IAppPaths>();
|
||||
|
||||
var returnCode = await cmd.ExecuteAsync(ctx, settings);
|
||||
|
||||
returnCode.Should().Be(0);
|
||||
Fs.AllFiles.Should().Contain(newPath.ConfigsDirectory.SubDirectory("configs").File("test.yml").FullName);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using System.IO.Abstractions;
|
||||
using Recyclarr.Settings;
|
||||
|
||||
namespace Recyclarr.Cli.IntegrationTests;
|
||||
namespace Recyclarr.Cli.IntegrationTests.Tests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ServiceCompatibilityIntegrationTest : CliIntegrationFixture
|
Loading…
Reference in new issue