Code refactored to allow easier testing at the command level. The initial test added verifies the custom-format list behavior.pull/356/head
parent
06a00cdfef
commit
1ae34f9e4d
@ -0,0 +1,55 @@
|
||||
using System.IO.Abstractions;
|
||||
using Recyclarr.Cli.Console;
|
||||
using Recyclarr.Cli.TestLibrary;
|
||||
using Recyclarr.Repo;
|
||||
using Recyclarr.TestLibrary;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Recyclarr.Cli.IntegrationTests;
|
||||
|
||||
internal class CliCommandIntegrationTest : CliIntegrationFixture
|
||||
{
|
||||
private static readonly TrashRepoFileMapper Mapper = new();
|
||||
|
||||
[OneTimeSetUp]
|
||||
public static async Task OneTimeSetup()
|
||||
{
|
||||
await Mapper.DownloadFiles(
|
||||
"metadata.json",
|
||||
"docs/Radarr/Radarr-collection-of-custom-formats.md");
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void MapFiles()
|
||||
{
|
||||
Mapper.AddToFilesystem(Fs, Resolve<ITrashGuidesRepo>().Path);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task List_custom_format_radarr_score_sets()
|
||||
{
|
||||
var repo = Resolve<ITrashGuidesRepo>();
|
||||
var cfPath = repo.Path.SubDirectory("docs/json/radarr/cf");
|
||||
string[] cfs = ["4k-remaster.json", "10bit.json"];
|
||||
|
||||
foreach (var cf in cfs)
|
||||
{
|
||||
Fs.AddFileFromEmbeddedResource(
|
||||
cfPath.File(cf),
|
||||
typeof(CliCommandIntegrationTest),
|
||||
$"Data/RadarrCustomFormats/{cf}");
|
||||
}
|
||||
|
||||
var exitCode = await CliSetup.Run(Container, ["list", "custom-formats", "radarr", "--score-sets"]);
|
||||
|
||||
exitCode.Should().Be(0);
|
||||
Console.Output.Should().ContainAll("default", "sqp-1-1080p", "sqp-1-2160p");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task List_custom_format_score_sets_fails_without_service_type()
|
||||
{
|
||||
var act = () => CliSetup.Run(Container, ["list", "custom-formats", "--score-sets"]);
|
||||
await act.Should().ThrowAsync<CommandRuntimeException>();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
{
|
||||
"trash_id": "a5d148168c4506b55cf53984107c396e",
|
||||
"trash_scores": {
|
||||
"sqp-1-1080p": -10000,
|
||||
"sqp-1-2160p": -10000
|
||||
},
|
||||
"name": "10bit",
|
||||
"includeCustomFormatWhenRenaming": false,
|
||||
"specifications": [
|
||||
{
|
||||
"name": "10bit",
|
||||
"implementation": "ReleaseTitleSpecification",
|
||||
"negate": false,
|
||||
"required": false,
|
||||
"fields": {
|
||||
"value": "10[.-]?bit"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "hi10p",
|
||||
"implementation": "ReleaseTitleSpecification",
|
||||
"negate": false,
|
||||
"required": false,
|
||||
"fields": {
|
||||
"value": "hi10p"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
{
|
||||
"trash_id": "eca37840c13c6ef2dd0262b141a5482f",
|
||||
"trash_scores": {
|
||||
"default": 25
|
||||
},
|
||||
"name": "4K Remaster",
|
||||
"includeCustomFormatWhenRenaming": true,
|
||||
"specifications": [
|
||||
{
|
||||
"name": "Remaster",
|
||||
"implementation": "ReleaseTitleSpecification",
|
||||
"negate": false,
|
||||
"required": true,
|
||||
"fields": {
|
||||
"value": "Remaster"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "4K",
|
||||
"implementation": "ReleaseTitleSpecification",
|
||||
"negate": false,
|
||||
"required": true,
|
||||
"fields": {
|
||||
"value": "4k"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Not 4K Resolution",
|
||||
"implementation": "ResolutionSpecification",
|
||||
"negate": true,
|
||||
"required": true,
|
||||
"fields": {
|
||||
"value": 2160
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO.Abstractions;
|
||||
using System.Reactive.Linq;
|
||||
using Flurl.Http;
|
||||
|
||||
namespace Recyclarr.Cli.TestLibrary;
|
||||
|
||||
public class RemoteRepoFileMapper
|
||||
{
|
||||
private Dictionary<string, string>? _guideDataCache;
|
||||
|
||||
[SuppressMessage("Design", "CA1054:URI-like parameters should not be strings")]
|
||||
public async Task DownloadFiles(string urlPrefix, params string[] repoFilePaths)
|
||||
{
|
||||
var dictionary = await repoFilePaths.ToObservable()
|
||||
.Select(x => Observable.FromAsync(async ct =>
|
||||
{
|
||||
var content = await $"{urlPrefix}/{x}".GetStringAsync(cancellationToken: ct);
|
||||
return (file: x, content);
|
||||
}))
|
||||
.Merge(8)
|
||||
.ToList();
|
||||
|
||||
_guideDataCache = dictionary.ToDictionary(x => x.file, x => x.content);
|
||||
}
|
||||
|
||||
public void AddToFilesystem(MockFileSystem fs, IDirectoryInfo containingDir)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(_guideDataCache);
|
||||
|
||||
foreach (var (file, content) in _guideDataCache)
|
||||
{
|
||||
fs.AddFile(containingDir.File(file), new MockFileData(content));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
namespace Recyclarr.Cli.TestLibrary;
|
||||
|
||||
public class TrashRepoFileMapper : RemoteRepoFileMapper
|
||||
{
|
||||
private const string RepoUrlPrefix = "https://raw.githubusercontent.com/TRaSH-Guides/Guides/refs/heads/master";
|
||||
|
||||
public async Task DownloadFiles(params string[] repoFilePaths)
|
||||
{
|
||||
await base.DownloadFiles(RepoUrlPrefix, repoFilePaths);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue