mirror of
https://github.com/Readarr/Readarr
synced 2026-01-05 15:14:04 +01:00
Fix GetBestRootFolderPath tests
(cherry picked from commit 63a911a9a549749b5460c2b9fea48a25e78c52a4)
This commit is contained in:
parent
cc70d61735
commit
60f6ed030b
2 changed files with 30 additions and 13 deletions
|
|
@ -1,8 +1,6 @@
|
|||
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;
|
||||
|
|
@ -22,27 +20,46 @@ private void GivenRootFolders(params string[] paths)
|
|||
[Test]
|
||||
public void should_return_root_folder_that_is_parent_path()
|
||||
{
|
||||
GivenRootFolders(@"C:\Test\Music".AsOsAgnostic(), @"D:\Test\Music".AsOsAgnostic());
|
||||
Subject.GetBestRootFolderPath(@"C:\Test\Music\Series Title".AsOsAgnostic()).Should().Be(@"C:\Test\Music".AsOsAgnostic());
|
||||
GivenRootFolders(@"C:\Test\Books".AsOsAgnostic(), @"D:\Test\Books".AsOsAgnostic());
|
||||
Subject.GetBestRootFolderPath(@"C:\Test\Books\Author Title".AsOsAgnostic()).Should().Be(@"C:\Test\Books".AsOsAgnostic());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_root_folder_that_is_grandparent_path()
|
||||
{
|
||||
GivenRootFolders(@"C:\Test\Music".AsOsAgnostic(), @"D:\Test\Music".AsOsAgnostic());
|
||||
Subject.GetBestRootFolderPath(@"C:\Test\Music\S\Series Title".AsOsAgnostic()).Should().Be(@"C:\Test\Music".AsOsAgnostic());
|
||||
GivenRootFolders(@"C:\Test\Books".AsOsAgnostic(), @"D:\Test\Books".AsOsAgnostic());
|
||||
Subject.GetBestRootFolderPath(@"C:\Test\Books\S\Author Title".AsOsAgnostic()).Should().Be(@"C:\Test\Books".AsOsAgnostic());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_parent_path_from_diskProvider_if_matching_root_folder_is_not_found()
|
||||
public void should_get_parent_path_from_os_path_if_matching_root_folder_is_not_found()
|
||||
{
|
||||
var seriesPath = @"T:\Test\Music\Series Title".AsOsAgnostic();
|
||||
var artistPath = @"T:\Test\Books\Author Title".AsOsAgnostic();
|
||||
|
||||
GivenRootFolders(@"C:\Test\Music".AsOsAgnostic(), @"D:\Test\Music".AsOsAgnostic());
|
||||
Subject.GetBestRootFolderPath(seriesPath);
|
||||
GivenRootFolders(@"C:\Test\Books".AsOsAgnostic(), @"D:\Test\Books".AsOsAgnostic());
|
||||
Subject.GetBestRootFolderPath(artistPath).Should().Be(@"T:\Test\Books".AsOsAgnostic());
|
||||
}
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.GetParentFolder(seriesPath), Times.Once);
|
||||
[Test]
|
||||
public void should_get_parent_path_from_os_path_if_matching_root_folder_is_not_found_for_posix_path()
|
||||
{
|
||||
WindowsOnly();
|
||||
|
||||
var artistPath = "/mnt/books/Author Title";
|
||||
|
||||
GivenRootFolders(@"C:\Test\Books".AsOsAgnostic(), @"D:\Test\Books".AsOsAgnostic());
|
||||
Subject.GetBestRootFolderPath(artistPath).Should().Be(@"/mnt/books");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_parent_path_from_os_path_if_matching_root_folder_is_not_found_for_windows_path()
|
||||
{
|
||||
PosixOnly();
|
||||
|
||||
var artistPath = @"T:\Test\Books\Author Title";
|
||||
|
||||
GivenRootFolders(@"C:\Test\Books".AsOsAgnostic(), @"D:\Test\Books".AsOsAgnostic());
|
||||
Subject.GetBestRootFolderPath(artistPath).Should().Be(@"T:\Test\Books");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ public string GetBestRootFolderPath(string path, List<RootFolder> allRootFolders
|
|||
{
|
||||
var osPath = new OsPath(path);
|
||||
|
||||
return osPath.Directory.ToString();
|
||||
return osPath.Directory.ToString().TrimEnd(osPath.IsUnixPath ? '/' : '\\');
|
||||
}
|
||||
|
||||
return possibleRootFolder?.Path;
|
||||
|
|
|
|||
Loading…
Reference in a new issue