Improve root folder health check
This commit is contained in:
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
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class RootFolderServiceFixture : CoreTest<RootFolderService>
|
||||
{
|
||||
[SetUp]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System.Linq;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Tv.Events;
|
||||
|
||||
|
@ -14,20 +15,23 @@ namespace NzbDrone.Core.HealthCheck.Checks
|
|||
{
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IRootFolderService _rootFolderService;
|
||||
|
||||
public RootFolderCheck(ISeriesService seriesService, IDiskProvider diskProvider)
|
||||
public RootFolderCheck(ISeriesService seriesService, IDiskProvider diskProvider, IRootFolderService rootFolderService)
|
||||
{
|
||||
_seriesService = seriesService;
|
||||
_diskProvider = diskProvider;
|
||||
_rootFolderService = rootFolderService;
|
||||
}
|
||||
|
||||
public override HealthCheck Check()
|
||||
{
|
||||
var missingRootFolders = _seriesService.GetAllSeries()
|
||||
.Select(s => _diskProvider.GetParentFolder(s.Path))
|
||||
.Distinct()
|
||||
.Where(s => !_diskProvider.FolderExists(s))
|
||||
.ToList();
|
||||
var rootFolders = _seriesService.GetAllSeries()
|
||||
.Select(s => _rootFolderService.GetBestRootFolderPath(s.Path))
|
||||
.Distinct();
|
||||
|
||||
var missingRootFolders = rootFolders.Where(s => !_diskProvider.FolderExists(s))
|
||||
.ToList();
|
||||
|
||||
if (missingRootFolders.Any())
|
||||
{
|
||||
|
|
|
@ -171,7 +171,7 @@ namespace NzbDrone.Core.RootFolders
|
|||
|
||||
if (possibleRootFolder == null)
|
||||
{
|
||||
return Path.GetDirectoryName(path);
|
||||
return _diskProvider.GetParentFolder(path);
|
||||
}
|
||||
|
||||
return possibleRootFolder.Path;
|
||||
|
|
Loading…
Reference in New Issue