mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-18 21:34:28 -04:00
New: Release Profiles, Frontend updates (#580)
* New: Release Profiles - UI Updates * New: Release Profiles - API Changes * New: Release Profiles - Test Updates * New: Release Profiles - Backend Updates * New: Interactive Artist Search * New: Change Montiored on Album Details Page * New: Show Duration on Album Details Page * Fixed: Manual Import not working if no albums are Missing * Fixed: Sort search input by sortTitle * Fixed: Queue columnLabel throwing JS error
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Test.Common;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace NzbDrone.Common.Test.DiskTests
|
||||
{
|
||||
@@ -485,10 +487,10 @@ namespace NzbDrone.Common.Test.DiskTests
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.CopyFile(_sourcePath, _tempTargetPath, false))
|
||||
.Callback(() =>
|
||||
{
|
||||
WithExistingFile(_tempTargetPath, true, 900);
|
||||
if (retry++ == 1) WithExistingFile(_tempTargetPath, true, 1000);
|
||||
});
|
||||
{
|
||||
WithExistingFile(_tempTargetPath, true, 900);
|
||||
if (retry++ == 1) WithExistingFile(_tempTargetPath, true, 1000);
|
||||
});
|
||||
|
||||
var result = Subject.TransferFile(_sourcePath, _targetPath, TransferMode.Copy);
|
||||
|
||||
@@ -504,10 +506,10 @@ namespace NzbDrone.Common.Test.DiskTests
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.CopyFile(_sourcePath, _tempTargetPath, false))
|
||||
.Callback(() =>
|
||||
{
|
||||
WithExistingFile(_tempTargetPath, true, 900);
|
||||
if (retry++ == 3) throw new Exception("Test Failed, retried too many times.");
|
||||
});
|
||||
{
|
||||
WithExistingFile(_tempTargetPath, true, 900);
|
||||
if (retry++ == 3) throw new Exception("Test Failed, retried too many times.");
|
||||
});
|
||||
|
||||
Assert.Throws<IOException>(() => Subject.TransferFile(_sourcePath, _targetPath, TransferMode.Copy));
|
||||
|
||||
@@ -794,6 +796,75 @@ namespace NzbDrone.Common.Test.DiskTests
|
||||
VerifyCopyFolder(original.FullName, destination.FullName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TransferFolder_should_use_movefolder_if_on_same_mount()
|
||||
{
|
||||
WithEmulatedDiskProvider();
|
||||
|
||||
var src = @"C:\Base1\TestDir1".AsOsAgnostic();
|
||||
var dst = @"C:\Base1\TestDir2".AsOsAgnostic();
|
||||
|
||||
WithMockMount(@"C:\Base1".AsOsAgnostic());
|
||||
WithExistingFile(@"C:\Base1\TestDir1\test.file.txt".AsOsAgnostic());
|
||||
|
||||
Subject.TransferFolder(src, dst, TransferMode.Move);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.MoveFolder(src, dst), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TransferFolder_should_not_use_movefolder_if_on_same_mount_but_target_already_exists()
|
||||
{
|
||||
WithEmulatedDiskProvider();
|
||||
|
||||
var src = @"C:\Base1\TestDir1".AsOsAgnostic();
|
||||
var dst = @"C:\Base1\TestDir2".AsOsAgnostic();
|
||||
|
||||
WithMockMount(@"C:\Base1".AsOsAgnostic());
|
||||
WithExistingFile(@"C:\Base1\TestDir1\test.file.txt".AsOsAgnostic());
|
||||
WithExistingFolder(dst);
|
||||
|
||||
Subject.TransferFolder(src, dst, TransferMode.Move);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.MoveFolder(src, dst), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TransferFolder_should_not_use_movefolder_if_on_same_mount_but_transactional()
|
||||
{
|
||||
WithEmulatedDiskProvider();
|
||||
|
||||
var src = @"C:\Base1\TestDir1".AsOsAgnostic();
|
||||
var dst = @"C:\Base1\TestDir2".AsOsAgnostic();
|
||||
|
||||
WithMockMount(@"C:\Base1".AsOsAgnostic());
|
||||
WithExistingFile(@"C:\Base1\TestDir1\test.file.txt".AsOsAgnostic());
|
||||
|
||||
Subject.TransferFolder(src, dst, TransferMode.Move, DiskTransferVerificationMode.Transactional);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.MoveFolder(src, dst), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TransferFolder_should_not_use_movefolder_if_on_different_mount()
|
||||
{
|
||||
WithEmulatedDiskProvider();
|
||||
|
||||
var src = @"C:\Base1\TestDir1".AsOsAgnostic();
|
||||
var dst = @"C:\Base2\TestDir2".AsOsAgnostic();
|
||||
|
||||
WithMockMount(@"C:\Base1".AsOsAgnostic());
|
||||
WithMockMount(@"C:\Base2".AsOsAgnostic());
|
||||
|
||||
Subject.TransferFolder(src, dst, TransferMode.Move);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.MoveFolder(src, dst), Times.Never());
|
||||
}
|
||||
|
||||
public DirectoryInfo GetFilledTempFolder()
|
||||
{
|
||||
var tempFolder = GetTempFilePath();
|
||||
@@ -810,8 +881,23 @@ namespace NzbDrone.Common.Test.DiskTests
|
||||
return new DirectoryInfo(tempFolder);
|
||||
}
|
||||
|
||||
private void WithExistingFolder(string path, bool exists = true)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(path);
|
||||
if (exists && dir.IsNotNullOrWhiteSpace())
|
||||
WithExistingFolder(dir);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.FolderExists(path))
|
||||
.Returns(exists);
|
||||
}
|
||||
|
||||
private void WithExistingFile(string path, bool exists = true, int size = 1000)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(path);
|
||||
if (exists && dir.IsNotNullOrWhiteSpace())
|
||||
WithExistingFolder(dir);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.FileExists(path))
|
||||
.Returns(exists);
|
||||
@@ -863,6 +949,45 @@ namespace NzbDrone.Common.Test.DiskTests
|
||||
{
|
||||
WithExistingFile(v, false);
|
||||
});
|
||||
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.FolderExists(It.IsAny<string>()))
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.CreateFolder(It.IsAny<string>()))
|
||||
.Callback<string>((f) =>
|
||||
{
|
||||
WithExistingFolder(f);
|
||||
});
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.MoveFolder(It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Callback<string, string>((s, d) =>
|
||||
{
|
||||
WithExistingFolder(s, false);
|
||||
WithExistingFolder(d);
|
||||
// Note: Should also deal with the files.
|
||||
});
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.DeleteFolder(It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Callback<string, bool>((f, r) =>
|
||||
{
|
||||
WithExistingFolder(f, false);
|
||||
// Note: Should also deal with the files.
|
||||
});
|
||||
|
||||
// Note: never returns anything.
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.GetDirectoryInfos(It.IsAny<string>()))
|
||||
.Returns(new List<DirectoryInfo>());
|
||||
|
||||
// Note: never returns anything.
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.GetFileInfos(It.IsAny<string>()))
|
||||
.Returns(new List<FileInfo>());
|
||||
}
|
||||
|
||||
private void WithRealDiskProvider()
|
||||
@@ -881,7 +1006,7 @@ namespace NzbDrone.Common.Test.DiskTests
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.DeleteFolder(It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Callback<string, bool>((v,r) => Directory.Delete(v, r));
|
||||
.Callback<string, bool>((v, r) => Directory.Delete(v, r));
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.DeleteFile(It.IsAny<string>()))
|
||||
@@ -909,7 +1034,7 @@ namespace NzbDrone.Common.Test.DiskTests
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.MoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Callback<string, string, bool>((s,d,o) => {
|
||||
.Callback<string, string, bool>((s, d, o) => {
|
||||
if (File.Exists(d) && o) File.Delete(d);
|
||||
File.Move(s, d);
|
||||
});
|
||||
@@ -919,6 +1044,18 @@ namespace NzbDrone.Common.Test.DiskTests
|
||||
.Returns<string>(s => new FileStream(s, FileMode.Open, FileAccess.Read));
|
||||
}
|
||||
|
||||
private void WithMockMount(string root)
|
||||
{
|
||||
var rootDir = root;
|
||||
var mock = new Mock<IMount>();
|
||||
mock.SetupGet(v => v.RootDirectory)
|
||||
.Returns(rootDir);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.GetMount(It.Is<string>(s => s.StartsWith(rootDir))))
|
||||
.Returns(mock.Object);
|
||||
}
|
||||
|
||||
private void VerifyCopyFolder(string source, string destination)
|
||||
{
|
||||
var sourceFiles = Directory.GetFileSystemEntries(source, "*", SearchOption.AllDirectories).Select(v => v.Substring(source.Length + 1)).ToArray();
|
||||
|
||||
@@ -138,18 +138,34 @@ namespace NzbDrone.Common.Test
|
||||
}
|
||||
|
||||
[TestCase(@"C:\Test\mydir", @"C:\Test")]
|
||||
[TestCase(@"C:\Test\", @"C:")]
|
||||
[TestCase(@"C:\Test\", @"C:\")]
|
||||
[TestCase(@"C:\", null)]
|
||||
public void path_should_return_parent(string path, string parentPath)
|
||||
[TestCase(@"\\server\share", null)]
|
||||
[TestCase(@"\\server\share\test", @"\\server\share")]
|
||||
public void path_should_return_parent_windows(string path, string parentPath)
|
||||
{
|
||||
WindowsOnly();
|
||||
path.GetParentPath().Should().Be(parentPath);
|
||||
}
|
||||
|
||||
[TestCase(@"/", null)]
|
||||
[TestCase(@"/test", "/")]
|
||||
public void path_should_return_parent_mono(string path, string parentPath)
|
||||
{
|
||||
MonoOnly();
|
||||
path.GetParentPath().Should().Be(parentPath);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void path_should_return_parent_for_oversized_path()
|
||||
{
|
||||
var path = @"/media/2e168617-f2ae-43fb-b88c-3663af1c8eea/downloads/sabnzbd/lidarr/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories";
|
||||
var parentPath = @"/media/2e168617-f2ae-43fb-b88c-3663af1c8eea/downloads/sabnzbd/lidarr/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing";
|
||||
MonoOnly();
|
||||
|
||||
// This test will fail on Windows if long path support is not enabled: https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/
|
||||
// It will also fail if the app isn't configured to use long path (such as resharper): https://blogs.msdn.microsoft.com/jeremykuhne/2016/07/30/net-4-6-2-and-long-paths-on-windows-10/
|
||||
|
||||
var path = @"C:\media\2e168617-f2ae-43fb-b88c-3663af1c8eea\downloads\sabnzbd\lidarr\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories".AsOsAgnostic();
|
||||
var parentPath = @"C:\media\2e168617-f2ae-43fb-b88c-3663af1c8eea\downloads\sabnzbd\lidarr\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing".AsOsAgnostic();
|
||||
|
||||
path.GetParentPath().Should().Be(parentPath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user