mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
Improve root folder health check
Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
This commit is contained in:
parent
e71973b16c
commit
d4817e9ff2
@ -0,0 +1,48 @@
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
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\Movies".AsOsAgnostic(), @"D:\Test\Movies".AsOsAgnostic());
|
||||
Subject.GetBestRootFolderPath(@"C:\Test\Movies\Movie Title".AsOsAgnostic()).Should().Be(@"C:\Test\Movies".AsOsAgnostic());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_root_folder_that_is_grandparent_path()
|
||||
{
|
||||
GivenRootFolders(@"C:\Test\Movies".AsOsAgnostic(), @"D:\Test\Movies".AsOsAgnostic());
|
||||
Subject.GetBestRootFolderPath(@"C:\Test\Movies\M\Movie Title".AsOsAgnostic()).Should().Be(@"C:\Test\Movies".AsOsAgnostic());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_parent_path_from_diskProvider_if_matching_root_folder_is_not_found()
|
||||
{
|
||||
var moviePath = @"T:\Test\Movies\Movie Title".AsOsAgnostic();
|
||||
|
||||
GivenRootFolders(@"C:\Test\Movies".AsOsAgnostic(), @"D:\Test\Movies".AsOsAgnostic());
|
||||
Subject.GetBestRootFolderPath(moviePath);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.GetParentFolder(moviePath), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,6 @@
|
||||
namespace NzbDrone.Core.Test.RootFolderTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class RootFolderServiceFixture : CoreTest<RootFolderService>
|
||||
{
|
||||
[SetUp]
|
||||
|
@ -3,6 +3,7 @@
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Movies.Events;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
|
||||
namespace NzbDrone.Core.HealthCheck.Checks
|
||||
{
|
||||
@ -14,20 +15,23 @@ public class RootFolderCheck : HealthCheckBase
|
||||
{
|
||||
private readonly IMovieService _movieService;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IRootFolderService _rootFolderService;
|
||||
|
||||
public RootFolderCheck(IMovieService movieService, IDiskProvider diskProvider)
|
||||
public RootFolderCheck(IMovieService movieService, IDiskProvider diskProvider, IRootFolderService rootFolderService)
|
||||
{
|
||||
_movieService = movieService;
|
||||
_diskProvider = diskProvider;
|
||||
_rootFolderService = rootFolderService;
|
||||
}
|
||||
|
||||
public override HealthCheck Check()
|
||||
{
|
||||
var missingRootFolders = _movieService.AllMoviePaths()
|
||||
.Select(s => _diskProvider.GetParentFolder(s))
|
||||
.Distinct()
|
||||
.Where(s => !_diskProvider.FolderExists(s))
|
||||
.ToList();
|
||||
var rootFolders = _movieService.GetAllMovies()
|
||||
.Select(s => _rootFolderService.GetBestRootFolderPath(s.Path))
|
||||
.Distinct();
|
||||
|
||||
var missingRootFolders = rootFolders.Where(s => !_diskProvider.FolderExists(s))
|
||||
.ToList();
|
||||
|
||||
if (missingRootFolders.Any())
|
||||
{
|
||||
|
@ -177,7 +177,7 @@ public string GetBestRootFolderPath(string path)
|
||||
|
||||
if (possibleRootFolder == null)
|
||||
{
|
||||
return Path.GetDirectoryName(path);
|
||||
return _diskProvider.GetParentFolder(path);
|
||||
}
|
||||
|
||||
return possibleRootFolder.Path;
|
||||
|
Loading…
Reference in New Issue
Block a user