You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.1 KiB
102 lines
3.1 KiB
using System.IO.Abstractions;
|
|
using Recyclarr.TrashLib.Config.Parsing.PostProcessing.ConfigMerging;
|
|
using Recyclarr.TrashLib.Startup;
|
|
|
|
namespace Recyclarr.TrashLib.Tests.Config.Parsing.PostProcessing.ConfigMerging;
|
|
|
|
[TestFixture]
|
|
[Parallelizable(ParallelScope.All)]
|
|
public class ConfigIncludeProcessorTest
|
|
{
|
|
[Test, AutoMockData]
|
|
public void Can_process_expected_type(
|
|
ConfigIncludeProcessor sut)
|
|
{
|
|
var result = sut.CanProcess(new ConfigYamlInclude());
|
|
result.Should().BeTrue();
|
|
}
|
|
|
|
[Test, AutoMockData]
|
|
public void Throw_when_null_include_path(
|
|
ConfigIncludeProcessor sut)
|
|
{
|
|
var includeDirective = new ConfigYamlInclude
|
|
{
|
|
Config = null
|
|
};
|
|
|
|
var act = () => sut.GetPathToConfig(includeDirective, default);
|
|
|
|
act.Should().Throw<YamlIncludeException>();
|
|
}
|
|
|
|
[Test, AutoMockData]
|
|
public void Get_relative_config_include_path(
|
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
|
[Frozen] IAppPaths paths,
|
|
ConfigIncludeProcessor sut)
|
|
{
|
|
fs.AddEmptyFile(paths.ConfigsDirectory.File("foo/bar/config.yml"));
|
|
|
|
var includeDirective = new ConfigYamlInclude
|
|
{
|
|
Config = "foo/bar/config.yml"
|
|
};
|
|
|
|
var path = sut.GetPathToConfig(includeDirective, default);
|
|
|
|
path.FullName.Should().Be(paths.ConfigsDirectory.File("foo/bar/config.yml").FullName);
|
|
}
|
|
|
|
[Test, AutoMockData]
|
|
public void Get_absolute_config_include_path(
|
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
|
ConfigIncludeProcessor sut)
|
|
{
|
|
var absolutePath = fs.CurrentDirectory().File("foo/bar/config.yml");
|
|
fs.AddEmptyFile(absolutePath);
|
|
|
|
var includeDirective = new ConfigYamlInclude
|
|
{
|
|
Config = absolutePath.FullName
|
|
};
|
|
|
|
var path = sut.GetPathToConfig(includeDirective, default);
|
|
|
|
path.FullName.Should().Be(absolutePath.FullName);
|
|
}
|
|
|
|
[Test, AutoMockData]
|
|
public void Throw_when_relative_config_include_path_does_not_exist(
|
|
// Freeze the mock FS even though we don't use it so that the "Exists" check works right.
|
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
|
ConfigIncludeProcessor sut)
|
|
{
|
|
var includeDirective = new ConfigYamlInclude
|
|
{
|
|
Config = "foo/bar/config.yml"
|
|
};
|
|
|
|
var act = () => sut.GetPathToConfig(includeDirective, default);
|
|
|
|
act.Should().Throw<YamlIncludeException>().WithMessage("Relative*not exist*");
|
|
}
|
|
|
|
[Test, AutoMockData]
|
|
public void Throw_when_absolute_config_include_path_does_not_exist(
|
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
|
ConfigIncludeProcessor sut)
|
|
{
|
|
var absolutePath = fs.CurrentDirectory().File("foo/bar/config.yml");
|
|
|
|
var includeDirective = new ConfigYamlInclude
|
|
{
|
|
Config = absolutePath.FullName
|
|
};
|
|
|
|
var act = () => sut.GetPathToConfig(includeDirective, default);
|
|
|
|
act.Should().Throw<YamlIncludeException>().WithMessage("Absolute*not exist*");
|
|
}
|
|
}
|