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.
recyclarr/src/Recyclarr.Cli.Tests/LogJanitorTest.cs

36 lines
1.1 KiB

using System.IO.Abstractions;
using MoreLinq.Extensions;
using Recyclarr.Cli.Logging;
using Recyclarr.TestLibrary.AutoFixture;
using Recyclarr.TrashLib.TestLibrary;
namespace Recyclarr.Cli.Tests;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class LogJanitorTest
{
[Test, AutoMockData]
public void Keep_correct_number_of_newest_log_files(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
[Frozen(Matching.ImplementedInterfaces)] TestAppPaths paths,
LogJanitor janitor)
{
var testFiles = new[]
{
paths.LogDirectory.File("trash_2021-05-15_19-00-00.log"),
paths.LogDirectory.File("trash_2021-05-15_20-00-00.log"),
paths.LogDirectory.File("trash_2021-05-15_21-00-00.log"),
paths.LogDirectory.File("trash_2021-05-15_22-00-00.log")
};
testFiles.ForEach(x => fs.AddFile(x.FullName, new MockFileData("")));
janitor.DeleteOldestLogFiles(2);
fs.AllFiles.Should().BeEquivalentTo(
testFiles[2].FullName,
testFiles[3].FullName);
}
}