Skip to content

Commit

Permalink
SNOW-990111: Add easy logging improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-lf committed Jan 16, 2024
1 parent 387ab55 commit 9383efc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
30 changes: 29 additions & 1 deletion Snowflake.Data.Tests/UnitTests/Session/EasyLoggingStarterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public class EasyLoggingStarterTest
}
};

private static readonly ClientConfig s_configWithNoLogPath = new ClientConfig
{
CommonProps = new ClientConfigCommonProps
{
LogLevel = "Info"
}
};

[ThreadStatic]
private static Mock<EasyLoggingConfigProvider> t_easyLoggingProvider;

Expand All @@ -63,7 +71,7 @@ public void BeforeEach()
}

[Test]
//[Ignore("This test requires manual interaction and therefore cannot be run in CI")]
[Ignore("This test requires manual interaction and therefore cannot be run in CI")]
public void TestThatCreatedDirectoryPermissionsFollowUmask()
{
// Note: To test with a different value than the default umask, it will have to be set before running this test
Expand Down Expand Up @@ -93,6 +101,26 @@ public void TestThatCreatedDirectoryPermissionsFollowUmask()
}
}

[Test]
//[Ignore("This test requires manual interaction and therefore cannot be run in CI")]
public void TestThatThrowsErrorWhenLogPathAndHomeDirectoryIsNotSet()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// arrange
t_easyLoggingProvider
.Setup(provider => provider.ProvideConfig(ConfigPath))
.Returns(s_configWithNoLogPath);

// act
var thrown = Assert.Throws<Exception>(() => t_easyLoggerStarter.Init(ConfigPath));

// assert
Assert.IsNotNull(thrown);
Assert.AreEqual(thrown.Message, "No log path found for easy logging. Home directory is not configured and log path is not provided");
}
}

[Test]
public void TestThatConfiguresEasyLoggingOnlyOnceWhenInitializedWithConfigPath()
{
Expand Down
4 changes: 1 addition & 3 deletions Snowflake.Data/Core/Session/EasyLoggingStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ private string GetLogPath(string logPath)
logPathOrDefault = EnvironmentOperations.Instance.GetFolderPath(Environment.SpecialFolder.UserProfile);

Check warning on line 108 in Snowflake.Data/Core/Session/EasyLoggingStarter.cs

View check run for this annotation

Codecov / codecov/patch

Snowflake.Data/Core/Session/EasyLoggingStarter.cs#L107-L108

Added lines #L107 - L108 were not covered by tests
if (string.IsNullOrEmpty(logPathOrDefault))
{
throw new SnowflakeDbException(
SFError.INTERNAL_ERROR,
"No log path found for easy logging. Home directory is not configured and log path is not provided.");
throw new Exception("No log path found for easy logging. Home directory is not configured and log path is not provided");

Check warning on line 111 in Snowflake.Data/Core/Session/EasyLoggingStarter.cs

View check run for this annotation

Codecov / codecov/patch

Snowflake.Data/Core/Session/EasyLoggingStarter.cs#L110-L111

Added lines #L110 - L111 were not covered by tests
}
}
var pathWithDotnetSubdirectory = Path.Combine(logPathOrDefault, "dotnet");
Expand Down

0 comments on commit 9383efc

Please sign in to comment.