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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.54
2.1.55
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,46 @@ public void SetupTest()
this.mockFixture.Dependencies.RemoveAll<IEnumerable<IBlobManager>>();
}


[Test]
[TestCase("<Any Toolset?>", "ComponentlogfolderName", "anytoolset")]
[TestCase(null, "ComponentlogfolderName", "componentlogfoldername")]
[TestCase(null, null, "testexecutor")]
public void GetLogDirectoryNameReturnsSafeNameAndPrefersToolNameOverComponentValues(string toolName, string logFolderName, string expected)
{
TestExecutor component = new TestExecutor(this.mockFixture);

component.Parameters[nameof(component.LogFolderName)] = logFolderName;
string actual = component.GetLogDirectoryName(toolName);

Assert.AreEqual(expected, actual, "ToolName should be preferred and sanitized into a safe folder name.");
}

[Test]
[TestCase("<Any Toolset?>", PlatformID.Unix, "/home/user/tools/VirtualClient/logs/anytoolset")]
[TestCase(null, PlatformID.Unix, "/home/user/tools/VirtualClient/logs/testexecutor")]
[TestCase("<Any Toolset?>", PlatformID.Win32NT, "C:\\users\\any\\tools\\VirtualClient\\logs\\anytoolset")]
[TestCase(null, PlatformID.Win32NT, "C:\\users\\any\\tools\\VirtualClient\\logs\\testexecutor")]
public void GetLogDirectoryReturnsSafeNameAndPrefersToolNameOverComponentValues(string toolName, PlatformID platformID, string expected)
{
this.mockFixture = new MockFixture();
this.mockFixture.Setup(platformID);
this.mockLogger = new Mock<ILogger>();
this.mockEventContext = new EventContext(Guid.NewGuid());

this.mockFixture.Parameters[nameof(TestExecutor.LogToFile)] = true;

// When there is a content manager, the application will also write a file
// upload notification file (e.g. upload.json). We validate this separately.
this.mockFixture.Dependencies.RemoveAll<IEnumerable<IBlobManager>>();
TestExecutor component = new TestExecutor(this.mockFixture);

string actual = component.GetLogDirectory(toolName);

Assert.AreEqual(expected, actual, "ToolName should be preferred and sanitized into a safe folder name.");
}


[Test]
[TestCase(0, null, null, null, null, null)]
[TestCase(0, "", "", "", "", "")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public static class VirtualClientLoggingExtensions
private static readonly Semaphore FileAccessLock = new Semaphore(1, 1);

/// <summary>
/// Returns the target log directory for the component and tool name.
/// Returns the target log directory name for the component.
/// </summary>
/// <param name="component">The component requesting the logging.</param>
/// <param name="toolName">The name of the toolset running in the process.</param>
public static string GetLogDirectory(this VirtualClientComponent component, string toolName = null)
public static string GetLogDirectoryName(this VirtualClientComponent component, string toolName = null)
{
string[] possibleLogFolderNames = new string[]
{
Expand All @@ -41,8 +41,20 @@ public static string GetLogDirectory(this VirtualClientComponent component, stri
component.TypeName
};

string logFolderName = VirtualClientLoggingExtensions.GetSafeFileName(possibleLogFolderNames.First(name => !string.IsNullOrWhiteSpace(name)), false);
string logDirectory = component.PlatformSpecifics.GetLogsPath(logFolderName.ToLowerInvariant().RemoveWhitespace());
string logDirectoryName = VirtualClientLoggingExtensions.GetSafeFileName(possibleLogFolderNames.First(name => !string.IsNullOrWhiteSpace(name)), false);

return logDirectoryName;
}

/// <summary>
/// Returns the target log directory for the component.
/// </summary>
/// <param name="component">The component requesting the logging.</param>
/// <param name="toolName">The name of the toolset running in the process.</param>
public static string GetLogDirectory(this VirtualClientComponent component, string toolName = null)
{
string logDirectoryName = component.GetLogDirectoryName(toolName);
string logDirectory = component.PlatformSpecifics.GetLogsPath(logDirectoryName.ToLowerInvariant().RemoveWhitespace());

return logDirectory;
}
Expand Down Expand Up @@ -397,7 +409,7 @@ await RetryPolicies.FileOperations.ExecuteAsync(async () =>

if (upload && component.TryGetContentStoreManager(out IBlobManager blobManager))
{
string effectiveToolName = fileSystem.Path.GetDirectoryName(logDirectory);
string effectiveToolName = component.GetLogDirectoryName(processDetails.ToolName);

FileContext fileContext = new FileContext(
fileSystem.FileInfo.New(logFilePath),
Expand Down
Loading