Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-990111 easy logging driver directory + Mono.Unix #868

Merged
merged 8 commits into from
Feb 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void Setup()
t_environmentOperations = new Mock<EnvironmentOperations>();
t_finder = new EasyLoggingConfigFinder(t_fileOperations.Object, t_unixOperations.Object, t_environmentOperations.Object);
MockHomeDirectory();
MockExecutionDirectory();
}

[Test]
Expand Down Expand Up @@ -213,6 +214,13 @@ private static void MockHomeDirectoryFails()
.Throws(() => new Exception("No home directory"));
}

private static void MockExecutionDirectory()
{
t_environmentOperations
.Setup(e => e.GetExecutionDirectory())
.Returns(DriverDirectory);
}

private static void MockFileOnHomePathDoesNotExist()
{
t_fileOperations
Expand Down
4 changes: 2 additions & 2 deletions Snowflake.Data/Configuration/EasyLoggingConfigFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ private string GetFilePathFromInputParameter(string filePath, string inputDescri

private string GetHomeDirectory() => HomeDirectoryProvider.HomeDirectory(_environmentOperations);

private string GetFilePathFromDriverLocation() => SearchForConfigInDirectory(() => ".", "driver");

private string GetFilePathFromDriverLocation() => SearchForConfigInDirectory(() => _environmentOperations.GetExecutionDirectory(), "driver");
private string SearchForConfigInDirectory(Func<string> directoryProvider, string directoryDescription)
{
try
Expand Down
7 changes: 7 additions & 0 deletions Snowflake.Data/Core/Tools/EnvironmentOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

using System;
using System.IO;

namespace Snowflake.Data.Core.Tools
{
Expand All @@ -19,5 +20,11 @@ public virtual string GetFolderPath(Environment.SpecialFolder folder)
{
return Environment.GetFolderPath(folder);
}

public virtual string GetExecutionDirectory()
{
var executablePath = Environment.GetCommandLineArgs()[0];
sfc-gh-knozderko marked this conversation as resolved.
Show resolved Hide resolved
return string.IsNullOrEmpty(executablePath) ? null : Path.GetDirectoryName(executablePath);
}
}
}
2 changes: 1 addition & 1 deletion Snowflake.Data/Snowflake.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="Google.Cloud.Storage.V1" Version="4.6.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.0" />
<PackageReference Include="Azure.Storage.Common" Version="12.12.0" />
<PackageReference Include="Mono.Posix" Version="7.1.0-final.1.21458.1" />
<PackageReference Include="Mono.Unix" Version="7.1.0-final.1.21458.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="log4net" Version="2.0.12" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.2.1" />
Expand Down
Loading