Improve root folder health check

pull/3660/head
Mark McDowall 4 years ago
parent 618c611a59
commit ed28f94f02

@ -0,0 +1,47 @@
using System.Linq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.RootFolderTests
{
[TestFixture]
public class GetBestRootFolderPathFixture : CoreTest<RootFolderService>
{
private void GivenRootFolders(params string[] paths)
{
Mocker.GetMock<IRootFolderRepository>()
.Setup(s => s.All())
.Returns(paths.Select(p => new RootFolder { Path = p }));
}
[Test]
public void should_return_root_folder_that_is_parent_path()
{
GivenRootFolders(@"C:\Test\TV", @"D:\Test\TV");
Subject.GetBestRootFolderPath(@"C:\Test\TV\Series Title").Should().Be(@"C:\Test\TV");
}
[Test]
public void should_return_root_folder_that_is_grandparent_path()
{
GivenRootFolders(@"C:\Test\TV", @"D:\Test\TV");
Subject.GetBestRootFolderPath(@"C:\Test\TV\S\Series Title").Should().Be(@"C:\Test\TV");
}
[Test]
public void should_get_parent_path_from_diskProvider_if_matching_root_folder_is_not_found()
{
var seriesPath = @"T:\Test\TV\Series Title";
GivenRootFolders(@"C:\Test\TV", @"D:\Test\TV");
Subject.GetBestRootFolderPath(seriesPath);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.GetParentFolder(seriesPath), Times.Once);
}
}
}

@ -15,7 +15,6 @@ using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.RootFolderTests namespace NzbDrone.Core.Test.RootFolderTests
{ {
[TestFixture] [TestFixture]
public class RootFolderServiceFixture : CoreTest<RootFolderService> public class RootFolderServiceFixture : CoreTest<RootFolderService>
{ {
[SetUp] [SetUp]

@ -1,6 +1,7 @@
using System.Linq; using System.Linq;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Tv.Events; using NzbDrone.Core.Tv.Events;
@ -14,20 +15,23 @@ namespace NzbDrone.Core.HealthCheck.Checks
{ {
private readonly ISeriesService _seriesService; private readonly ISeriesService _seriesService;
private readonly IDiskProvider _diskProvider; private readonly IDiskProvider _diskProvider;
private readonly IRootFolderService _rootFolderService;
public RootFolderCheck(ISeriesService seriesService, IDiskProvider diskProvider) public RootFolderCheck(ISeriesService seriesService, IDiskProvider diskProvider, IRootFolderService rootFolderService)
{ {
_seriesService = seriesService; _seriesService = seriesService;
_diskProvider = diskProvider; _diskProvider = diskProvider;
_rootFolderService = rootFolderService;
} }
public override HealthCheck Check() public override HealthCheck Check()
{ {
var missingRootFolders = _seriesService.GetAllSeries() var rootFolders = _seriesService.GetAllSeries()
.Select(s => _diskProvider.GetParentFolder(s.Path)) .Select(s => _rootFolderService.GetBestRootFolderPath(s.Path))
.Distinct() .Distinct();
.Where(s => !_diskProvider.FolderExists(s))
.ToList(); var missingRootFolders = rootFolders.Where(s => !_diskProvider.FolderExists(s))
.ToList();
if (missingRootFolders.Any()) if (missingRootFolders.Any())
{ {

@ -171,7 +171,7 @@ namespace NzbDrone.Core.RootFolders
if (possibleRootFolder == null) if (possibleRootFolder == null)
{ {
return Path.GetDirectoryName(path); return _diskProvider.GetParentFolder(path);
} }
return possibleRootFolder.Path; return possibleRootFolder.Path;

Loading…
Cancel
Save