diff --git a/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/AllLogViewerControllerTests.cs b/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/AllLogViewerControllerTests.cs index 9e8c1844aea2..dc3fea308187 100644 --- a/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/AllLogViewerControllerTests.cs +++ b/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/AllLogViewerControllerTests.cs @@ -5,11 +5,10 @@ namespace Umbraco.Cms.Tests.Integration.ManagementApi.LogViewer; -public class AllLogViewerControllerTests : ManagementApiUserGroupTestBase +public class AllLogViewerControllerTests : LogViewerTestBase { protected override Expression> MethodSelector => x => x.AllLogs(CancellationToken.None, 0, 100, Direction.Descending, null, null, null, null); - // We get the InternalServerError for the admin because it has access, but there is no log file to view protected override UserGroupAssertionModel AdminUserGroupAssertionModel => new() { ExpectedStatusCode = HttpStatusCode.OK diff --git a/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/AllMessageTemplateLogViewerControllerTests.cs b/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/AllMessageTemplateLogViewerControllerTests.cs index 71df00279432..7d4cf61b9395 100644 --- a/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/AllMessageTemplateLogViewerControllerTests.cs +++ b/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/AllMessageTemplateLogViewerControllerTests.cs @@ -4,11 +4,10 @@ namespace Umbraco.Cms.Tests.Integration.ManagementApi.LogViewer; -public class AllMessageTemplateLogViewerControllerTests : ManagementApiUserGroupTestBase +public class AllMessageTemplateLogViewerControllerTests : LogViewerTestBase { protected override Expression> MethodSelector => x => x.AllMessageTemplates(CancellationToken.None, 0, 100, null, null); - // We get the InternalServerError for the admin because it has access, but there is no log file to view protected override UserGroupAssertionModel AdminUserGroupAssertionModel => new() { ExpectedStatusCode = HttpStatusCode.OK diff --git a/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/AllSinkLevelLogViewerControllerTests.cs b/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/AllSinkLevelLogViewerControllerTests.cs index ffb7bc6d5c87..4d786c8a7458 100644 --- a/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/AllSinkLevelLogViewerControllerTests.cs +++ b/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/AllSinkLevelLogViewerControllerTests.cs @@ -4,7 +4,7 @@ namespace Umbraco.Cms.Tests.Integration.ManagementApi.LogViewer; -public class AllSinkLevelLogViewerControllerTests : ManagementApiUserGroupTestBase +public class AllSinkLevelLogViewerControllerTests : LogViewerTestBase { protected override Expression> MethodSelector => x => x.AllLogLevels(CancellationToken.None, 0, 100); diff --git a/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/LogLevelCountLogViewerControllerTests.cs b/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/LogLevelCountLogViewerControllerTests.cs index 4fd81272814e..63656130b5ea 100644 --- a/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/LogLevelCountLogViewerControllerTests.cs +++ b/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/LogLevelCountLogViewerControllerTests.cs @@ -4,11 +4,10 @@ namespace Umbraco.Cms.Tests.Integration.ManagementApi.LogViewer; -public class LogLevelCountLogViewerControllerTests : ManagementApiUserGroupTestBase +public class LogLevelCountLogViewerControllerTests : LogViewerTestBase { protected override Expression> MethodSelector => x => x.LogLevelCounts(CancellationToken.None, null, null); - // We get the InternalServerError for the admin because it has access, but there is no log file to view protected override UserGroupAssertionModel AdminUserGroupAssertionModel => new() { ExpectedStatusCode = HttpStatusCode.OK diff --git a/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/LogViewerTestBase.cs b/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/LogViewerTestBase.cs new file mode 100644 index 000000000000..6c4a0d0894c2 --- /dev/null +++ b/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/LogViewerTestBase.cs @@ -0,0 +1,22 @@ +using NUnit.Framework; +using Umbraco.Cms.Api.Management.Controllers; +using Umbraco.Cms.Core.Logging; + +namespace Umbraco.Cms.Tests.Integration.ManagementApi.LogViewer; + +/// +/// Base class for LogViewer integration tests that ensures the log directory exists. +/// +public abstract class LogViewerTestBase : ManagementApiUserGroupTestBase + where T : ManagementApiControllerBase +{ + [SetUp] + public void EnsureLogDirectoryExists() + { + var loggingConfiguration = GetRequiredService(); + if (!Directory.Exists(loggingConfiguration.LogDirectory)) + { + Directory.CreateDirectory(loggingConfiguration.LogDirectory); + } + } +} diff --git a/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/ValidateLogFileSizeLogViewerControllerTests.cs b/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/ValidateLogFileSizeLogViewerControllerTests.cs index 56622b6db678..d5e7d3fc1d22 100644 --- a/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/ValidateLogFileSizeLogViewerControllerTests.cs +++ b/tests/Umbraco.Tests.Integration/ManagementApi/LogViewer/ValidateLogFileSizeLogViewerControllerTests.cs @@ -4,11 +4,10 @@ namespace Umbraco.Cms.Tests.Integration.ManagementApi.LogViewer; -public class ValidateLogFileSizeLogViewerControllerTests: ManagementApiUserGroupTestBase +public class ValidateLogFileSizeLogViewerControllerTests: LogViewerTestBase { protected override Expression> MethodSelector => x => x.CanViewLogs(CancellationToken.None, null, null); - // We get the InternalServerError for the admin because it has access, but there is no log file to view protected override UserGroupAssertionModel AdminUserGroupAssertionModel => new() { ExpectedStatusCode = HttpStatusCode.OK diff --git a/tests/Umbraco.Tests.Integration/ManagementApi/MemberType/Tree/RootMemberTypeTreeControllerTree.cs b/tests/Umbraco.Tests.Integration/ManagementApi/MemberType/Tree/RootMemberTypeTreeControllerTree.cs index 4944a018b85d..64806941509f 100644 --- a/tests/Umbraco.Tests.Integration/ManagementApi/MemberType/Tree/RootMemberTypeTreeControllerTree.cs +++ b/tests/Umbraco.Tests.Integration/ManagementApi/MemberType/Tree/RootMemberTypeTreeControllerTree.cs @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Tests.Integration.ManagementApi.MemberType.Tree; public class RootMemberTypeTreeControllerTests : ManagementApiUserGroupTestBase { protected override Expression> MethodSelector => - x => x.Root(CancellationToken.None, 0, 100); + x => x.Root(CancellationToken.None, 0, 100, false); protected override UserGroupAssertionModel AdminUserGroupAssertionModel => new() { diff --git a/tests/Umbraco.Tests.Integration/ManagementApi/Services/Trees/FileSystemTreeServiceTestsBase.cs b/tests/Umbraco.Tests.Integration/ManagementApi/Services/Trees/FileSystemTreeServiceTestsBase.cs index 9e9c3af00fd0..535513d0efbc 100644 --- a/tests/Umbraco.Tests.Integration/ManagementApi/Services/Trees/FileSystemTreeServiceTestsBase.cs +++ b/tests/Umbraco.Tests.Integration/ManagementApi/Services/Trees/FileSystemTreeServiceTestsBase.cs @@ -74,14 +74,28 @@ private static void Purge(IFileSystem fs, string path) var files = fs.GetFiles(path, "*"); foreach (var file in files) { - fs.DeleteFile(file); + try + { + fs.DeleteFile(file); + } + catch (IOException) + { + // Ignore locked files during cleanup + } } var dirs = fs.GetDirectories(path); foreach (var dir in dirs) { Purge(fs, dir); - fs.DeleteDirectory(dir); + try + { + fs.DeleteDirectory(dir); + } + catch (IOException) + { + // Ignore locked directories during cleanup + } } } }