refactor: Make InstanceName non-nullable

pull/201/head
Robert Dailey 2 years ago
parent fe9f98e435
commit 96a278b06f

@ -9,21 +9,7 @@ namespace Recyclarr.Cli.Tests.Console.Helpers;
public class CacheStoragePathTest public class CacheStoragePathTest
{ {
[Test, AutoMockData] [Test, AutoMockData]
public void Use_guid_when_no_name(CacheStoragePath sut) public void Use_instance_name_in_path(CacheStoragePath sut)
{
var config = new SonarrConfiguration
{
BaseUrl = new Uri("http://something"),
InstanceName = null
};
var result = sut.CalculatePath(config, "obj");
result.FullName.Should().MatchRegex(@".*[/\\][a-f0-9]+[/\\]obj\.json$");
}
[Test, AutoMockData]
public void Use_name_when_not_null(CacheStoragePath sut)
{ {
var config = new SonarrConfiguration var config = new SonarrConfiguration
{ {

@ -21,7 +21,7 @@ public class CustomFormatConfigPhaseTest
NewCf.Data("two", "cf2") NewCf.Data("two", "cf2")
}); });
var config = new RadarrConfiguration var config = NewConfig.Radarr() with
{ {
CustomFormats = new List<CustomFormatConfig> CustomFormats = new List<CustomFormatConfig>
{ {
@ -55,7 +55,7 @@ public class CustomFormatConfigPhaseTest
NewCf.Data("", "cf4") NewCf.Data("", "cf4")
}); });
var config = new RadarrConfiguration var config = NewConfig.Radarr() with
{ {
CustomFormats = new List<CustomFormatConfig> CustomFormats = new List<CustomFormatConfig>
{ {

@ -3,7 +3,6 @@ using Recyclarr.Cli.Pipelines.CustomFormat.Models;
using Recyclarr.Cli.Pipelines.CustomFormat.PipelinePhases; using Recyclarr.Cli.Pipelines.CustomFormat.PipelinePhases;
using Recyclarr.Cli.TestLibrary; using Recyclarr.Cli.TestLibrary;
using Recyclarr.TrashLib.Cache; using Recyclarr.TrashLib.Cache;
using Recyclarr.TrashLib.Config.Services;
using Recyclarr.TrashLib.Models; using Recyclarr.TrashLib.Models;
using Recyclarr.TrashLib.TestLibrary; using Recyclarr.TrashLib.TestLibrary;
@ -27,7 +26,7 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
var cache = new CustomFormatCache(); var cache = new CustomFormatCache();
var config = new RadarrConfiguration(); var config = NewConfig.Radarr();
var result = sut.Execute(config, guideCfs, serviceData, cache); var result = sut.Execute(config, guideCfs, serviceData, cache);
@ -63,7 +62,7 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
var cache = new CustomFormatCache(); var cache = new CustomFormatCache();
var config = new RadarrConfiguration(); var config = NewConfig.Radarr();
var result = sut.Execute(config, guideCfs, serviceData, cache); var result = sut.Execute(config, guideCfs, serviceData, cache);
@ -108,7 +107,7 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
} }
}; };
var config = new RadarrConfiguration(); var config = NewConfig.Radarr();
var result = sut.Execute(config, guideCfs, serviceData, cache); var result = sut.Execute(config, guideCfs, serviceData, cache);
@ -147,7 +146,7 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
var cache = new CustomFormatCache(); var cache = new CustomFormatCache();
var config = new RadarrConfiguration var config = NewConfig.Radarr() with
{ {
ReplaceExistingCustomFormats = true ReplaceExistingCustomFormats = true
}; };
@ -184,7 +183,7 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
var cache = new CustomFormatCache(); var cache = new CustomFormatCache();
var config = new RadarrConfiguration var config = NewConfig.Radarr() with
{ {
ReplaceExistingCustomFormats = false ReplaceExistingCustomFormats = false
}; };
@ -224,7 +223,7 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
} }
}; };
var config = new RadarrConfiguration var config = NewConfig.Radarr() with
{ {
ReplaceExistingCustomFormats = false ReplaceExistingCustomFormats = false
}; };
@ -270,7 +269,7 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
} }
}; };
var config = new RadarrConfiguration var config = NewConfig.Radarr() with
{ {
ReplaceExistingCustomFormats = false ReplaceExistingCustomFormats = false
}; };
@ -303,7 +302,7 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
var cache = new CustomFormatCache(); var cache = new CustomFormatCache();
var config = new RadarrConfiguration var config = NewConfig.Radarr() with
{ {
ReplaceExistingCustomFormats = true ReplaceExistingCustomFormats = true
}; };
@ -339,7 +338,7 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
} }
}; };
var config = new RadarrConfiguration var config = NewConfig.Radarr() with
{ {
ReplaceExistingCustomFormats = false ReplaceExistingCustomFormats = false
}; };
@ -372,7 +371,7 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
} }
}; };
var config = new RadarrConfiguration(); var config = NewConfig.Radarr();
var result = sut.Execute(config, guideCfs, serviceData, cache); var result = sut.Execute(config, guideCfs, serviceData, cache);
@ -408,7 +407,7 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
} }
}; };
var config = new RadarrConfiguration(); var config = NewConfig.Radarr();
var result = sut.Execute(config, guideCfs, serviceData, cache); var result = sut.Execute(config, guideCfs, serviceData, cache);

@ -13,7 +13,7 @@ public class QualityProfileConfigPhaseTest
{ {
private static RadarrConfiguration SetupCfs(params CustomFormatConfig[] cfConfigs) private static RadarrConfiguration SetupCfs(params CustomFormatConfig[] cfConfigs)
{ {
return new RadarrConfiguration return NewConfig.Radarr() with
{ {
CustomFormats = cfConfigs CustomFormats = cfConfigs
}; };

@ -1,6 +1,7 @@
using Recyclarr.Cli.Pipelines.Tags.PipelinePhases; using Recyclarr.Cli.Pipelines.Tags.PipelinePhases;
using Recyclarr.TestLibrary.AutoFixture; using Recyclarr.TestLibrary.AutoFixture;
using Recyclarr.TrashLib.Config.Services; using Recyclarr.TrashLib.Config.Services;
using Recyclarr.TrashLib.TestLibrary;
namespace Recyclarr.Cli.Tests.Pipelines.Tags.PipelinePhases; namespace Recyclarr.Cli.Tests.Pipelines.Tags.PipelinePhases;
@ -11,7 +12,7 @@ public class TagConfigPhaseTest
[Test, AutoMockData] [Test, AutoMockData]
public void Return_null_when_list_empty(TagConfigPhase sut) public void Return_null_when_list_empty(TagConfigPhase sut)
{ {
var config = new SonarrConfiguration var config = NewConfig.Sonarr() with
{ {
ReleaseProfiles = Array.Empty<ReleaseProfileConfig>() ReleaseProfiles = Array.Empty<ReleaseProfileConfig>()
}; };
@ -23,7 +24,7 @@ public class TagConfigPhaseTest
[Test, AutoMockData] [Test, AutoMockData]
public void Return_tags(TagConfigPhase sut) public void Return_tags(TagConfigPhase sut)
{ {
var config = new SonarrConfiguration var config = NewConfig.Sonarr() with
{ {
ReleaseProfiles = new[] ReleaseProfiles = new[]
{ {

@ -22,18 +22,9 @@ public class CacheStoragePath : ICacheStoragePath
private string BuildUniqueServiceDir(IServiceConfiguration config) private string BuildUniqueServiceDir(IServiceConfiguration config)
{ {
// In the future, once array-style configurations are removed, the service name will no longer be optional
// and the below condition can be removed and the logic simplified.
var dirName = new StringBuilder();
if (config.InstanceName is not null)
{
dirName.Append($"{config.InstanceName}_");
}
var url = config.BaseUrl.OriginalString; var url = config.BaseUrl.OriginalString;
var guid = _hash.ComputeHash(Encoding.ASCII.GetBytes(url)).AsHexString(); var guid = _hash.ComputeHash(Encoding.ASCII.GetBytes(url)).AsHexString();
dirName.Append(guid); return $"{config.InstanceName}_{guid}";
return dirName.ToString();
} }
public IFileInfo CalculatePath(IServiceConfiguration config, string cacheObjectName) public IFileInfo CalculatePath(IServiceConfiguration config, string cacheObjectName)

@ -105,7 +105,7 @@ public class SyncProcessor : ISyncProcessor
private void PrintProcessingHeader(SupportedServices serviceType, IServiceConfiguration config) private void PrintProcessingHeader(SupportedServices serviceType, IServiceConfiguration config)
{ {
var instanceName = config.InstanceName ?? FlurlLogging.SanitizeUrl(config.BaseUrl); var instanceName = config.InstanceName;
_console.WriteLine($@" _console.WriteLine($@"
=========================================== ===========================================

@ -0,0 +1,22 @@
using Recyclarr.TrashLib.Config.Services;
namespace Recyclarr.TrashLib.TestLibrary;
public static class NewConfig
{
public static RadarrConfiguration Radarr()
{
return new RadarrConfiguration
{
InstanceName = ""
};
}
public static SonarrConfiguration Sonarr()
{
return new SonarrConfiguration
{
InstanceName = ""
};
}
}

@ -1,6 +1,7 @@
using Recyclarr.TrashLib.Compatibility.Sonarr; using Recyclarr.TrashLib.Compatibility.Sonarr;
using Recyclarr.TrashLib.Config.Services; using Recyclarr.TrashLib.Config.Services;
using Recyclarr.TrashLib.ExceptionTypes; using Recyclarr.TrashLib.ExceptionTypes;
using Recyclarr.TrashLib.TestLibrary;
namespace Recyclarr.TrashLib.Tests.Compatibility.Sonarr; namespace Recyclarr.TrashLib.Tests.Compatibility.Sonarr;
@ -13,7 +14,7 @@ public class SonarrCapabilityEnforcerTest
[Frozen] ISonarrCapabilityChecker checker, [Frozen] ISonarrCapabilityChecker checker,
SonarrCapabilityEnforcer sut) SonarrCapabilityEnforcer sut)
{ {
var config = new SonarrConfiguration(); var config = NewConfig.Sonarr();
checker.GetCapabilities(default!).ReturnsForAnyArgs((SonarrCapabilities?) null); checker.GetCapabilities(default!).ReturnsForAnyArgs((SonarrCapabilities?) null);
@ -27,7 +28,7 @@ public class SonarrCapabilityEnforcerTest
[Frozen] ISonarrCapabilityChecker checker, [Frozen] ISonarrCapabilityChecker checker,
SonarrCapabilityEnforcer sut) SonarrCapabilityEnforcer sut)
{ {
var config = new SonarrConfiguration(); var config = NewConfig.Sonarr();
checker.GetCapabilities(default!).ReturnsForAnyArgs(new SonarrCapabilities(new Version()) checker.GetCapabilities(default!).ReturnsForAnyArgs(new SonarrCapabilities(new Version())
{ {
@ -44,7 +45,7 @@ public class SonarrCapabilityEnforcerTest
[Frozen] ISonarrCapabilityChecker checker, [Frozen] ISonarrCapabilityChecker checker,
SonarrCapabilityEnforcer sut) SonarrCapabilityEnforcer sut)
{ {
var config = new SonarrConfiguration var config = NewConfig.Sonarr() with
{ {
ReleaseProfiles = new List<ReleaseProfileConfig> ReleaseProfiles = new List<ReleaseProfileConfig>
{ {
@ -68,7 +69,7 @@ public class SonarrCapabilityEnforcerTest
[Frozen] ISonarrCapabilityChecker checker, [Frozen] ISonarrCapabilityChecker checker,
SonarrCapabilityEnforcer sut) SonarrCapabilityEnforcer sut)
{ {
var config = new SonarrConfiguration var config = NewConfig.Sonarr() with
{ {
CustomFormats = new List<CustomFormatConfig> CustomFormats = new List<CustomFormatConfig>
{ {

@ -2,7 +2,7 @@ using FluentValidation;
using FluentValidation.Results; using FluentValidation.Results;
using Recyclarr.Common.FluentValidation; using Recyclarr.Common.FluentValidation;
using Recyclarr.TrashLib.Config.Parsing; using Recyclarr.TrashLib.Config.Parsing;
using Recyclarr.TrashLib.Config.Services; using Recyclarr.TrashLib.TestLibrary;
namespace Recyclarr.TrashLib.Tests.Config.Parsing; namespace Recyclarr.TrashLib.Tests.Config.Parsing;
@ -20,7 +20,7 @@ public class ConfigValidationExecutorTest
new ValidationFailure("property", "message") new ValidationFailure("property", "message")
})); }));
var result = sut.Validate(new RadarrConfiguration()); var result = sut.Validate(NewConfig.Radarr());
result.Should().BeFalse(); result.Should().BeFalse();
} }
@ -35,7 +35,7 @@ public class ConfigValidationExecutorTest
new ValidationFailure("property", "message") {Severity = Severity.Warning} new ValidationFailure("property", "message") {Severity = Severity.Warning}
})); }));
var result = sut.Validate(new RadarrConfiguration()); var result = sut.Validate(NewConfig.Radarr());
result.Should().BeTrue(); result.Should().BeTrue();
} }
@ -47,7 +47,7 @@ public class ConfigValidationExecutorTest
{ {
validationService.Validate(default!).ReturnsForAnyArgs(new ValidationResult()); validationService.Validate(default!).ReturnsForAnyArgs(new ValidationResult());
var result = sut.Validate(new RadarrConfiguration()); var result = sut.Validate(NewConfig.Radarr());
result.Should().BeTrue(); result.Should().BeTrue();
} }

@ -77,7 +77,7 @@ public class ConfigLocalLister : IConfigLister
var tree = new Tree(Markup.FromInterpolated($"[red]{service}[/]")); var tree = new Tree(Markup.FromInterpolated($"[red]{service}[/]"));
tree.AddNodes(configs.Select(c => tree.AddNodes(configs.Select(c =>
Markup.FromInterpolated($"[blue]{c.InstanceName ?? c.BaseUrl.ToString()}[/]"))); Markup.FromInterpolated($"[blue]{c.InstanceName}[/]")));
rows.Add(tree); rows.Add(tree);
} }

@ -3,7 +3,7 @@ namespace Recyclarr.TrashLib.Config.Services;
public interface IServiceConfiguration public interface IServiceConfiguration
{ {
SupportedServices ServiceType { get; } SupportedServices ServiceType { get; }
string? InstanceName { get; } string InstanceName { get; }
Uri BaseUrl { get; } Uri BaseUrl { get; }
string ApiKey { get; } string ApiKey { get; }
bool DeleteOldCustomFormats { get; } bool DeleteOldCustomFormats { get; }

@ -5,7 +5,7 @@ namespace Recyclarr.TrashLib.Config.Services;
public abstract record ServiceConfiguration : IServiceConfiguration public abstract record ServiceConfiguration : IServiceConfiguration
{ {
public abstract SupportedServices ServiceType { get; } public abstract SupportedServices ServiceType { get; }
public string? InstanceName { get; set; } public required string InstanceName { get; init; }
public Uri BaseUrl { get; set; } = new("about:empty"); public Uri BaseUrl { get; set; } = new("about:empty");
public string ApiKey { get; init; } = ""; public string ApiKey { get; init; } = "";

Loading…
Cancel
Save