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.
79 lines
2.1 KiB
79 lines
2.1 KiB
2 years ago
|
using System.IO.Abstractions;
|
||
1 year ago
|
using Recyclarr.Json;
|
||
1 year ago
|
using Recyclarr.TestLibrary;
|
||
2 years ago
|
|
||
1 year ago
|
namespace Recyclarr.Tests.Json;
|
||
2 years ago
|
|
||
|
[TestFixture]
|
||
|
public class JsonUtilsTest
|
||
|
{
|
||
|
[Test]
|
||
|
public void Log_files_that_do_not_exist()
|
||
|
{
|
||
|
var fs = new MockFileSystem();
|
||
1 year ago
|
var log = new TestableLogger();
|
||
2 years ago
|
|
||
|
var path = fs.CurrentDirectory().SubDirectory("doesnt_exist");
|
||
|
|
||
|
var result = JsonUtils.GetJsonFilesInDirectories(new[] {path}, log);
|
||
|
|
||
|
result.Should().BeEmpty();
|
||
1 year ago
|
log.Messages.Should().ContainSingle()
|
||
|
.Which.Should().Match("*doesnt_exist*");
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Log_files_that_only_exist()
|
||
|
{
|
||
|
var fs = new MockFileSystem();
|
||
1 year ago
|
var log = new TestableLogger();
|
||
2 years ago
|
|
||
|
var path = fs.CurrentDirectory().SubDirectory("exists").File("test.json");
|
||
|
fs.AddFile(path.FullName, new MockFileData(""));
|
||
|
|
||
|
var result = JsonUtils.GetJsonFilesInDirectories(new[] {path.Directory}, log);
|
||
|
|
||
|
result.Should().ContainSingle()
|
||
|
.Which.FullName
|
||
|
.Should().Be(path.FullName);
|
||
|
|
||
1 year ago
|
log.Messages.Should().BeEmpty();
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Log_files_that_both_exist_and_do_not_exist()
|
||
|
{
|
||
|
var fs = new MockFileSystem();
|
||
1 year ago
|
var log = new TestableLogger();
|
||
2 years ago
|
var paths = new[]
|
||
|
{
|
||
|
fs.CurrentDirectory().SubDirectory("does_not_exist"),
|
||
|
fs.CurrentDirectory().SubDirectory("exists")
|
||
|
};
|
||
|
|
||
|
var existingFile = paths[1].File("test.json").FullName;
|
||
|
|
||
|
fs.AddFile(existingFile, new MockFileData(""));
|
||
|
paths[1].Refresh();
|
||
|
|
||
|
var result = JsonUtils.GetJsonFilesInDirectories(paths, log);
|
||
|
|
||
|
result.Should().ContainSingle()
|
||
|
.Which.FullName
|
||
|
.Should().Be(existingFile);
|
||
|
|
||
1 year ago
|
log.Messages.Should().ContainSingle()
|
||
|
.Which.Should().Match("*does_not_exist*");
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
[Test]
|
||
|
public void Null_paths_are_ignored()
|
||
|
{
|
||
|
var result = JsonUtils.GetJsonFilesInDirectories(
|
||
|
new IDirectoryInfo?[] {null, null},
|
||
|
Substitute.For<ILogger>());
|
||
|
|
||
|
result.Should().BeEmpty();
|
||
|
}
|
||
2 years ago
|
}
|