mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Fixes file system browser Presentation Api integration tests failing on Unix systems
This commit is contained in:
1 parent
b94c299180
commit
309a8cb5c1
4 files changed
+38
-13
No files matched your search
+23
-6
@@ -11,6 +11,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -33,6 +34,7 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
PropertyNameCaseInsensitive = true,
|
PropertyNameCaseInsensitive = true,
|
||||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||||
};
|
};
|
||||||
|
private static readonly bool s_isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ====================================================================== CTOR =====================================================================================
|
#region ====================================================================== CTOR =====================================================================================
|
||||||
@@ -83,7 +85,8 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
treeNodes!.Should().NotBeEmpty();
|
treeNodes!.Should().NotBeEmpty();
|
||||||
|
|
||||||
string[] pathSegments = testPath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
|
string[] pathSegments = testPath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (s_isLinux) // on UNIX, the leading slash is considered "the drive", the root location - add it!
|
||||||
|
pathSegments = new string[] { "/" }.Concat(pathSegments).ToArray();
|
||||||
// recursively validate the tree structure
|
// recursively validate the tree structure
|
||||||
void ValidateNode(FileSystemTreeNodeResponse node, int depth)
|
void ValidateNode(FileSystemTreeNodeResponse node, int depth)
|
||||||
{
|
{
|
||||||
@@ -97,6 +100,8 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
node.Name.Should().Be(expectedSegment);
|
node.Name.Should().Be(expectedSegment);
|
||||||
|
|
||||||
string expectedPath = string.Join(Path.DirectorySeparatorChar.ToString(), pathSegments.Take(depth + 1));
|
string expectedPath = string.Join(Path.DirectorySeparatorChar.ToString(), pathSegments.Take(depth + 1));
|
||||||
|
if (expectedPath.StartsWith("//"))
|
||||||
|
expectedPath = expectedPath.Substring(1);
|
||||||
if (!expectedPath.EndsWith(Path.DirectorySeparatorChar))
|
if (!expectedPath.EndsWith(Path.DirectorySeparatorChar))
|
||||||
expectedPath += Path.DirectorySeparatorChar;
|
expectedPath += Path.DirectorySeparatorChar;
|
||||||
node.Path.Should().EndWith(expectedPath);
|
node.Path.Should().EndWith(expectedPath);
|
||||||
@@ -162,6 +167,8 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
treeNodes!.Should().NotBeEmpty();
|
treeNodes!.Should().NotBeEmpty();
|
||||||
|
|
||||||
string[] pathSegments = testPath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
|
string[] pathSegments = testPath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (s_isLinux) // on UNIX, the leading slash is considered "the drive", the root location - add it!
|
||||||
|
pathSegments = new string[] { "/" }.Concat(pathSegments).ToArray();
|
||||||
|
|
||||||
// recursively validate the tree structure
|
// recursively validate the tree structure
|
||||||
void ValidateNode(FileSystemTreeNodeResponse node, int depth)
|
void ValidateNode(FileSystemTreeNodeResponse node, int depth)
|
||||||
@@ -178,6 +185,8 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
string expectedPath = string.Join(Path.DirectorySeparatorChar.ToString(), pathSegments.Take(depth + 1));
|
string expectedPath = string.Join(Path.DirectorySeparatorChar.ToString(), pathSegments.Take(depth + 1));
|
||||||
if (!expectedPath.EndsWith(Path.DirectorySeparatorChar))
|
if (!expectedPath.EndsWith(Path.DirectorySeparatorChar))
|
||||||
expectedPath += Path.DirectorySeparatorChar;
|
expectedPath += Path.DirectorySeparatorChar;
|
||||||
|
if (expectedPath.StartsWith("//"))
|
||||||
|
expectedPath = expectedPath.Substring(1);
|
||||||
node.Path.Should().EndWith(expectedPath);
|
node.Path.Should().EndWith(expectedPath);
|
||||||
|
|
||||||
// if the node is a drive or directory, check its children recursively
|
// if the node is a drive or directory, check its children recursively
|
||||||
@@ -191,7 +200,7 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
else if (childNode.ItemType is FileSystemItemType.File)
|
else if (childNode.ItemType is FileSystemItemType.File)
|
||||||
{
|
{
|
||||||
childNode.Children.Should().BeEmpty(); // files should not have children
|
childNode.Children.Should().BeEmpty(); // files should not have children
|
||||||
childNode.Name.Should().BeOneOf("TestFile_1.txt", "TestFile_2.txt");
|
childNode.Name.Should().BeOneOf((s_isLinux ? "." : string.Empty) + "TestFile_1.txt", "TestFile_2.txt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,6 +253,8 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
treeNodes.Should().AllSatisfy(node => node.ItemType.Should().BeOneOf(FileSystemItemType.Directory, FileSystemItemType.Root));
|
treeNodes.Should().AllSatisfy(node => node.ItemType.Should().BeOneOf(FileSystemItemType.Directory, FileSystemItemType.Root));
|
||||||
|
|
||||||
string[] pathSegments = testPath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
|
string[] pathSegments = testPath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (s_isLinux) // on UNIX, the leading slash is considered "the drive", the root location - add it!
|
||||||
|
pathSegments = new string[] { "/" }.Concat(pathSegments).ToArray();
|
||||||
|
|
||||||
// recursively validate the tree structure
|
// recursively validate the tree structure
|
||||||
void ValidateNode(FileSystemTreeNodeResponse node, int depth)
|
void ValidateNode(FileSystemTreeNodeResponse node, int depth)
|
||||||
@@ -260,6 +271,8 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
string expectedPath = string.Join(Path.DirectorySeparatorChar.ToString(), pathSegments.Take(depth + 1));
|
string expectedPath = string.Join(Path.DirectorySeparatorChar.ToString(), pathSegments.Take(depth + 1));
|
||||||
if (!expectedPath.EndsWith(Path.DirectorySeparatorChar))
|
if (!expectedPath.EndsWith(Path.DirectorySeparatorChar))
|
||||||
expectedPath += Path.DirectorySeparatorChar;
|
expectedPath += Path.DirectorySeparatorChar;
|
||||||
|
if (expectedPath.StartsWith("//"))
|
||||||
|
expectedPath = expectedPath.Substring(1);
|
||||||
node.Path.Should().EndWith(expectedPath);
|
node.Path.Should().EndWith(expectedPath);
|
||||||
|
|
||||||
node.Children.Should().NotBeNull();
|
node.Children.Should().NotBeNull();
|
||||||
@@ -314,6 +327,8 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
treeNodes.Should().AllSatisfy(node => node.ItemType.Should().BeOneOf(FileSystemItemType.Directory, FileSystemItemType.Root));
|
treeNodes.Should().AllSatisfy(node => node.ItemType.Should().BeOneOf(FileSystemItemType.Directory, FileSystemItemType.Root));
|
||||||
|
|
||||||
string[] pathSegments = testPath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
|
string[] pathSegments = testPath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (s_isLinux) // on UNIX, the leading slash is considered "the drive", the root location - add it!
|
||||||
|
pathSegments = new string[] { "/" }.Concat(pathSegments).ToArray();
|
||||||
|
|
||||||
// recursively validate the tree structure
|
// recursively validate the tree structure
|
||||||
void ValidateNode(FileSystemTreeNodeResponse node, int depth)
|
void ValidateNode(FileSystemTreeNodeResponse node, int depth)
|
||||||
@@ -330,6 +345,8 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
string expectedPath = string.Join(Path.DirectorySeparatorChar.ToString(), pathSegments.Take(depth + 1));
|
string expectedPath = string.Join(Path.DirectorySeparatorChar.ToString(), pathSegments.Take(depth + 1));
|
||||||
if (!expectedPath.EndsWith(Path.DirectorySeparatorChar))
|
if (!expectedPath.EndsWith(Path.DirectorySeparatorChar))
|
||||||
expectedPath += Path.DirectorySeparatorChar;
|
expectedPath += Path.DirectorySeparatorChar;
|
||||||
|
if (expectedPath.StartsWith("//"))
|
||||||
|
expectedPath = expectedPath.Substring(1);
|
||||||
node.Path.Should().EndWith(expectedPath);
|
node.Path.Should().EndWith(expectedPath);
|
||||||
|
|
||||||
node.Children.Should().NotBeNull();
|
node.Children.Should().NotBeNull();
|
||||||
@@ -521,8 +538,8 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
|
|
||||||
|
|
||||||
FileSystemTreeNodeResponse firstNode = treeNodes.First();
|
FileSystemTreeNodeResponse firstNode = treeNodes.First();
|
||||||
firstNode.Name.Should().Be("NestedDirectory_2");
|
firstNode.Name.Should().Be((s_isLinux ? "." : string.Empty) + "NestedDirectory_2");
|
||||||
firstNode.Path.Should().Be(Path.Combine(testPath, "NestedDirectory_2" + Path.DirectorySeparatorChar));
|
firstNode.Path.Should().Be(Path.Combine(testPath, (s_isLinux ? "." : string.Empty) + "NestedDirectory_2" + Path.DirectorySeparatorChar));
|
||||||
firstNode.ItemType.Should().Be(FileSystemItemType.Directory);
|
firstNode.ItemType.Should().Be(FileSystemItemType.Directory);
|
||||||
treeNodes.Should().AllSatisfy(n => n.ItemType.Should().Be(FileSystemItemType.Directory));
|
treeNodes.Should().AllSatisfy(n => n.ItemType.Should().Be(FileSystemItemType.Directory));
|
||||||
treeNodes.Count.Should().Be(1); // only directories
|
treeNodes.Count.Should().Be(1); // only directories
|
||||||
@@ -706,8 +723,8 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
|
|
||||||
|
|
||||||
DirectoryResponse firstDirectory = directories.First();
|
DirectoryResponse firstDirectory = directories.First();
|
||||||
firstDirectory.Name.Should().Be("NestedDirectory_2");
|
firstDirectory.Name.Should().Be((s_isLinux ? "." : string.Empty) + "NestedDirectory_2");
|
||||||
firstDirectory.Path.Should().Be(Path.Combine(testPath, "NestedDirectory_2" + Path.DirectorySeparatorChar));
|
firstDirectory.Path.Should().Be(Path.Combine(testPath, (s_isLinux ? "." : string.Empty) + "NestedDirectory_2" + Path.DirectorySeparatorChar));
|
||||||
directories.Count.Should().Be(1); // only directories
|
directories.Count.Should().Be(1); // only directories
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|||||||
+6
-4
@@ -10,6 +10,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -32,6 +33,7 @@ public class FilesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
PropertyNameCaseInsensitive = true,
|
PropertyNameCaseInsensitive = true,
|
||||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||||
};
|
};
|
||||||
|
private static readonly bool s_isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ====================================================================== CTOR =====================================================================================
|
#region ====================================================================== CTOR =====================================================================================
|
||||||
@@ -175,8 +177,8 @@ public class FilesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
string[] pathSegments = testPath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
|
string[] pathSegments = testPath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
FileSystemTreeNodeResponse firstDirectory = files.First();
|
FileSystemTreeNodeResponse firstDirectory = files.First();
|
||||||
firstDirectory.Name.Should().Be("TestFile_1.txt");
|
firstDirectory.Name.Should().Be((s_isLinux ? "." : string.Empty) + "TestFile_1.txt");
|
||||||
firstDirectory.Path.Should().Be(Path.Combine(testPath, "TestFile_1.txt"));
|
firstDirectory.Path.Should().Be(Path.Combine(testPath, (s_isLinux ? "." : string.Empty) + "TestFile_1.txt"));
|
||||||
FileSystemTreeNodeResponse secondDirectory = files.Last();
|
FileSystemTreeNodeResponse secondDirectory = files.Last();
|
||||||
secondDirectory.Name.Should().Be("TestFile_2.txt");
|
secondDirectory.Name.Should().Be("TestFile_2.txt");
|
||||||
secondDirectory.Path.Should().Be(Path.Combine(testPath, "TestFile_2.txt"));
|
secondDirectory.Path.Should().Be(Path.Combine(testPath, "TestFile_2.txt"));
|
||||||
@@ -362,8 +364,8 @@ public class FilesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
string[] pathSegments = testPath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
|
string[] pathSegments = testPath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
FileResponse firstDirectory = files.First();
|
FileResponse firstDirectory = files.First();
|
||||||
firstDirectory.Name.Should().Be("TestFile_1.txt");
|
firstDirectory.Name.Should().Be( (s_isLinux ? "." : string.Empty) + "TestFile_1.txt");
|
||||||
firstDirectory.Path.Should().Be(Path.Combine(testPath, "TestFile_1.txt"));
|
firstDirectory.Path.Should().Be(Path.Combine(testPath, (s_isLinux ? "." : string.Empty) + "TestFile_1.txt"));
|
||||||
FileResponse secondDirectory = files.Last();
|
FileResponse secondDirectory = files.Last();
|
||||||
secondDirectory.Name.Should().Be("TestFile_2.txt");
|
secondDirectory.Name.Should().Be("TestFile_2.txt");
|
||||||
secondDirectory.Path.Should().Be(Path.Combine(testPath, "TestFile_2.txt"));
|
secondDirectory.Path.Should().Be(Path.Combine(testPath, "TestFile_2.txt"));
|
||||||
|
|||||||
+4
-2
@@ -57,7 +57,7 @@ public class FileSystemStructureFixture
|
|||||||
}
|
}
|
||||||
// make the second nested directory hidden
|
// make the second nested directory hidden
|
||||||
if (i == 2)
|
if (i == 2)
|
||||||
SetHidden(currentPath);
|
currentPath = SetHidden(currentPath);
|
||||||
}
|
}
|
||||||
return currentPath;
|
return currentPath;
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ public class FileSystemStructureFixture
|
|||||||
/// Sets the hidden attribute for a file or directory.
|
/// Sets the hidden attribute for a file or directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The path to the file or directory.</param>
|
/// <param name="path">The path to the file or directory.</param>
|
||||||
private static void SetHidden(string path)
|
private static string SetHidden(string path)
|
||||||
{
|
{
|
||||||
if (OperatingSystem.IsWindows())
|
if (OperatingSystem.IsWindows())
|
||||||
File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
|
File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
|
||||||
@@ -80,7 +80,9 @@ public class FileSystemStructureFixture
|
|||||||
Directory.Move(path, newPath);
|
Directory.Move(path, newPath);
|
||||||
else if (File.Exists(path))
|
else if (File.Exists(path))
|
||||||
File.Move(path, newPath);
|
File.Move(path, newPath);
|
||||||
|
path = newPath;
|
||||||
}
|
}
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+5
-1
@@ -1,14 +1,17 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Lumina.Contracts.Responses.FileManagement;
|
using Lumina.Contracts.Responses.FileManagement;
|
||||||
|
using Lumina.Presentation.Api.Core.Controllers.FileManagement;
|
||||||
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -31,6 +34,7 @@ public class PathControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
PropertyNameCaseInsensitive = true,
|
PropertyNameCaseInsensitive = true,
|
||||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||||
};
|
};
|
||||||
|
private static readonly bool s_isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ====================================================================== CTOR =====================================================================================
|
#region ====================================================================== CTOR =====================================================================================
|
||||||
@@ -220,7 +224,7 @@ public class PathControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
string path = System.IO.Path.GetDirectoryName(testPath)!;
|
string path = System.IO.Path.GetDirectoryName(testPath)!;
|
||||||
while (!string.IsNullOrEmpty(path))
|
while (!string.IsNullOrEmpty(path))
|
||||||
{
|
{
|
||||||
string segment = System.IO.Path.GetFileName(path);
|
string segment = s_isLinux && path == Path.DirectorySeparatorChar.ToString() ? path : System.IO.Path.GetFileName(path);
|
||||||
if (string.IsNullOrEmpty(segment))
|
if (string.IsNullOrEmpty(segment))
|
||||||
{
|
{
|
||||||
hierarchy.Add(System.IO.Path.GetPathRoot(path)!.TrimEnd(System.IO.Path.DirectorySeparatorChar));
|
hierarchy.Add(System.IO.Path.GetPathRoot(path)!.TrimEnd(System.IO.Path.DirectorySeparatorChar));
|
||||||
|
|||||||
Reference in new issue
Block a user