mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-19 21:13:28 -07:00
A remote path mapping health check (#617)
This commit is contained in:
parent
0762805572
commit
e27369686b
12 changed files with 360 additions and 15 deletions
|
@ -0,0 +1,171 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.HealthCheck.Checks;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.HealthCheck.Checks
|
||||
{
|
||||
[TestFixture]
|
||||
public class RemotePathMappingCheckFixture : CoreTest<RemotePathMappingCheck>
|
||||
{
|
||||
private string downloadRootPath = @"c:\Test".AsOsAgnostic();
|
||||
private string downloadItemPath = @"c:\Test\item".AsOsAgnostic();
|
||||
|
||||
private DownloadClientInfo clientStatus;
|
||||
private DownloadClientItem downloadItem;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
downloadItem = new DownloadClientItem {
|
||||
DownloadClient = "Test",
|
||||
DownloadId = "TestId",
|
||||
OutputPath = new OsPath(downloadItemPath)
|
||||
};
|
||||
|
||||
clientStatus = new DownloadClientInfo {
|
||||
IsLocalhost = true,
|
||||
OutputRootFolders = new List<OsPath> { new OsPath(downloadRootPath) }
|
||||
};
|
||||
|
||||
var downloadClient = Mocker.GetMock<IDownloadClient>();
|
||||
downloadClient.Setup(s => s.Definition)
|
||||
.Returns(new DownloadClientDefinition { Name = "Test" });
|
||||
|
||||
downloadClient.Setup(s => s.GetItems())
|
||||
.Returns(new List<DownloadClientItem> { downloadItem });
|
||||
|
||||
downloadClient.Setup(s => s.GetStatus())
|
||||
.Returns(clientStatus);
|
||||
|
||||
Mocker.GetMock<IProvideDownloadClient>()
|
||||
.Setup(s => s.GetDownloadClients())
|
||||
.Returns(new IDownloadClient[] { downloadClient.Object });
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(x => x.FolderExists(It.IsAny<string>()))
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(x => x.FileExists(It.IsAny<string>()))
|
||||
.Returns(false);
|
||||
}
|
||||
|
||||
private void GivenFolderExists(string folder)
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(x => x.FolderExists(folder))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
private void GivenFileExists(string file)
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(x => x.FileExists(file))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
|
||||
private void GivenDocker()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_ok_if_setup_correctly()
|
||||
{
|
||||
GivenFolderExists(downloadRootPath);
|
||||
|
||||
Subject.Check().ShouldBeOk();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_permissions_error_if_local_client_download_root_missing()
|
||||
{
|
||||
Subject.Check().ShouldBeError(wikiFragment: "permissions-error");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_path_mapping_error_if_remote_client_download_root_missing()
|
||||
{
|
||||
clientStatus.IsLocalhost = false;
|
||||
|
||||
Subject.Check().ShouldBeError(wikiFragment: "bad-remote-path-mapping");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Explicit("Only works if running inside a docker container")]
|
||||
public void should_return_docker_path_mapping_error_if_on_docker_and_root_missing()
|
||||
{
|
||||
Subject.Check().ShouldBeError(wikiFragment: "docker-bad-remote-path-mapping");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_ok_on_track_imported_event()
|
||||
{
|
||||
GivenFolderExists(downloadRootPath);
|
||||
var importEvent = new TrackImportedEvent(new LocalTrack(), new TrackFile(), new List<TrackFile>(), true, new DownloadClientItem());
|
||||
|
||||
Subject.Check(importEvent).ShouldBeOk();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_permissions_error_on_track_import_failed_event_if_file_exists()
|
||||
{
|
||||
var localTrack = new LocalTrack {
|
||||
Path = Path.Combine(downloadItemPath, "file.mp3")
|
||||
};
|
||||
GivenFileExists(localTrack.Path);
|
||||
|
||||
var importEvent = new TrackImportFailedEvent(new Exception(), localTrack, true, new DownloadClientItem());
|
||||
|
||||
Subject.Check(importEvent).ShouldBeError(wikiFragment: "permissions-error");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_permissions_error_on_track_import_failed_event_if_folder_exists()
|
||||
{
|
||||
GivenFolderExists(downloadItemPath);
|
||||
|
||||
var importEvent = new TrackImportFailedEvent(null, null, true, downloadItem);
|
||||
|
||||
Subject.Check(importEvent).ShouldBeError(wikiFragment: "permissions-error");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_permissions_error_on_track_import_failed_event_for_local_client_if_folder_does_not_exist()
|
||||
{
|
||||
var importEvent = new TrackImportFailedEvent(null, null, true, downloadItem);
|
||||
|
||||
Subject.Check(importEvent).ShouldBeError(wikiFragment: "permissions-error");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_mapping_error_on_track_import_failed_event_for_remote_client_if_folder_does_not_exist()
|
||||
{
|
||||
clientStatus.IsLocalhost = false;
|
||||
var importEvent = new TrackImportFailedEvent(null, null, true, downloadItem);
|
||||
|
||||
Subject.Check(importEvent).ShouldBeError(wikiFragment: "bad-remote-path-mapping");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Explicit("Only works if running inside a docker container")]
|
||||
public void should_return_docker_mapping_error_on_track_import_failed_event_inside_docker_if_folder_does_not_exist()
|
||||
{
|
||||
clientStatus.IsLocalhost = false;
|
||||
var importEvent = new TrackImportFailedEvent(null, null, true, downloadItem);
|
||||
|
||||
Subject.Check(importEvent).ShouldBeError(wikiFragment: "docker-bad-remote-path-mapping");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue