mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-06-23 15:30:56 -04:00
Add tests for ManagedFileSystem.MoveDirectory (#14065)
This commit is contained in:
parent
dec5814a6a
commit
28e2f5bb08
@ -5,10 +5,11 @@ using System.Runtime.InteropServices;
|
|||||||
using AutoFixture;
|
using AutoFixture;
|
||||||
using AutoFixture.AutoMoq;
|
using AutoFixture.AutoMoq;
|
||||||
using Emby.Server.Implementations.IO;
|
using Emby.Server.Implementations.IO;
|
||||||
|
using Jellyfin.Extensions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Jellyfin.Server.Implementations.Tests.IO
|
namespace Jellyfin.Server.Implementations.Tests.IO;
|
||||||
{
|
|
||||||
public class ManagedFileSystemTests
|
public class ManagedFileSystemTests
|
||||||
{
|
{
|
||||||
private readonly IFixture _fixture;
|
private readonly IFixture _fixture;
|
||||||
@ -20,6 +21,42 @@ namespace Jellyfin.Server.Implementations.Tests.IO
|
|||||||
_sut = _fixture.Create<ManagedFileSystem>();
|
_sut = _fixture.Create<ManagedFileSystem>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MoveDirectory_SameFileSystem_Correct()
|
||||||
|
=> MoveDirectoryInternal();
|
||||||
|
|
||||||
|
[SkippableFact]
|
||||||
|
public void MoveDirectory_DifferentFileSystem_Correct()
|
||||||
|
{
|
||||||
|
const string DestinationParent = "/dev/shm";
|
||||||
|
|
||||||
|
Skip.IfNot(Directory.Exists(DestinationParent));
|
||||||
|
|
||||||
|
MoveDirectoryInternal(DestinationParent);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void MoveDirectoryInternal(string? destinationParent = null)
|
||||||
|
{
|
||||||
|
const string TempFile0 = "tempfile0";
|
||||||
|
const string TempFile1 = "tempfile1";
|
||||||
|
|
||||||
|
destinationParent ??= Path.GetTempPath();
|
||||||
|
|
||||||
|
var sourceDir = Directory.CreateTempSubdirectory();
|
||||||
|
var destinationDir = Path.Join(destinationParent, Path.GetRandomFileName());
|
||||||
|
FileHelper.CreateEmpty(Path.Join(sourceDir.FullName, TempFile0));
|
||||||
|
FileHelper.CreateEmpty(Path.Join(sourceDir.FullName, TempFile1));
|
||||||
|
|
||||||
|
_sut.MoveDirectory(sourceDir.FullName, destinationDir);
|
||||||
|
|
||||||
|
Assert.True(Directory.Exists(destinationDir));
|
||||||
|
Assert.True(File.Exists(Path.Join(destinationDir, TempFile0)));
|
||||||
|
Assert.True(File.Exists(Path.Join(destinationDir, TempFile1)));
|
||||||
|
Assert.False(Directory.Exists(sourceDir.FullName));
|
||||||
|
|
||||||
|
Directory.Delete(destinationDir, true);
|
||||||
|
}
|
||||||
|
|
||||||
[SkippableTheory]
|
[SkippableTheory]
|
||||||
[InlineData("/Volumes/Library/Sample/Music/Playlists/", "../Beethoven/Misc/Moonlight Sonata.mp3", "/Volumes/Library/Sample/Music/Beethoven/Misc/Moonlight Sonata.mp3")]
|
[InlineData("/Volumes/Library/Sample/Music/Playlists/", "../Beethoven/Misc/Moonlight Sonata.mp3", "/Volumes/Library/Sample/Music/Beethoven/Misc/Moonlight Sonata.mp3")]
|
||||||
[InlineData("/Volumes/Library/Sample/Music/Playlists/", "../../Beethoven/Misc/Moonlight Sonata.mp3", "/Volumes/Library/Sample/Beethoven/Misc/Moonlight Sonata.mp3")]
|
[InlineData("/Volumes/Library/Sample/Music/Playlists/", "../../Beethoven/Misc/Moonlight Sonata.mp3", "/Volumes/Library/Sample/Beethoven/Misc/Moonlight Sonata.mp3")]
|
||||||
@ -46,7 +83,7 @@ namespace Jellyfin.Server.Implementations.Tests.IO
|
|||||||
string filePath,
|
string filePath,
|
||||||
string expectedAbsolutePath)
|
string expectedAbsolutePath)
|
||||||
{
|
{
|
||||||
Skip.If(!OperatingSystem.IsWindows());
|
Skip.IfNot(OperatingSystem.IsWindows());
|
||||||
|
|
||||||
var generatedPath = _sut.MakeAbsolutePath(folderPath, filePath);
|
var generatedPath = _sut.MakeAbsolutePath(folderPath, filePath);
|
||||||
|
|
||||||
@ -84,4 +121,3 @@ namespace Jellyfin.Server.Implementations.Tests.IO
|
|||||||
[DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)]
|
[DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)]
|
||||||
private static extern int symlink(string target, string linkpath);
|
private static extern int symlink(string target, string linkpath);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user