Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

namespace Umbraco.Cms.Tests.Integration.ManagementApi.LogViewer;

public class AllLogViewerControllerTests : ManagementApiUserGroupTestBase<AllLogViewerController>
public class AllLogViewerControllerTests : LogViewerTestBase<AllLogViewerController>
{
protected override Expression<Func<AllLogViewerController, object>> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

namespace Umbraco.Cms.Tests.Integration.ManagementApi.LogViewer;

public class AllMessageTemplateLogViewerControllerTests : ManagementApiUserGroupTestBase<AllMessageTemplateLogViewerController>
public class AllMessageTemplateLogViewerControllerTests : LogViewerTestBase<AllMessageTemplateLogViewerController>
{
protected override Expression<Func<AllMessageTemplateLogViewerController, object>> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Umbraco.Cms.Tests.Integration.ManagementApi.LogViewer;

public class AllSinkLevelLogViewerControllerTests : ManagementApiUserGroupTestBase<AllSinkLevelLogViewerController>
public class AllSinkLevelLogViewerControllerTests : LogViewerTestBase<AllSinkLevelLogViewerController>
{
protected override Expression<Func<AllSinkLevelLogViewerController, object>> MethodSelector => x => x.AllLogLevels(CancellationToken.None, 0, 100);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

namespace Umbraco.Cms.Tests.Integration.ManagementApi.LogViewer;

public class LogLevelCountLogViewerControllerTests : ManagementApiUserGroupTestBase<LogLevelCountLogViewerController>
public class LogLevelCountLogViewerControllerTests : LogViewerTestBase<LogLevelCountLogViewerController>
{
protected override Expression<Func<LogLevelCountLogViewerController, object>> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Base class for LogViewer integration tests that ensures the log directory exists.
/// </summary>
public abstract class LogViewerTestBase<T> : ManagementApiUserGroupTestBase<T>
where T : ManagementApiControllerBase
{
[SetUp]
public void EnsureLogDirectoryExists()
{
var loggingConfiguration = GetRequiredService<ILoggingConfiguration>();
if (!Directory.Exists(loggingConfiguration.LogDirectory))
{
Directory.CreateDirectory(loggingConfiguration.LogDirectory);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

namespace Umbraco.Cms.Tests.Integration.ManagementApi.LogViewer;

public class ValidateLogFileSizeLogViewerControllerTests: ManagementApiUserGroupTestBase<ValidateLogFileSizeLogViewerController>
public class ValidateLogFileSizeLogViewerControllerTests: LogViewerTestBase<ValidateLogFileSizeLogViewerController>
{
protected override Expression<Func<ValidateLogFileSizeLogViewerController, object>> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Tests.Integration.ManagementApi.MemberType.Tree;
public class RootMemberTypeTreeControllerTests : ManagementApiUserGroupTestBase<RootMemberTypeTreeController>
{
protected override Expression<Func<RootMemberTypeTreeController, object>> MethodSelector =>
x => x.Root(CancellationToken.None, 0, 100);
x => x.Root(CancellationToken.None, 0, 100, false);

protected override UserGroupAssertionModel AdminUserGroupAssertionModel => new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Loading