Skip to content

Commit

Permalink
fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-erojaslizano committed May 14, 2024
1 parent f4dced9 commit 69b01cf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
32 changes: 12 additions & 20 deletions Snowflake.Data.Tests/IntegrationTests/EasyLoggingIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void BeforeAll()
Directory.CreateDirectory(s_workingDirectory);
}
}

[OneTimeTearDown]
public static void AfterAll()
{
Expand All @@ -36,7 +36,7 @@ public static void AfterEach()
{
EasyLoggingStarter.Instance.Reset(EasyLoggingLogLevel.Warn);
}

[Test]
public void TestEnableEasyLogging()
{
Expand All @@ -48,7 +48,7 @@ public void TestEnableEasyLogging()

// act
conn.Open();

// assert
Assert.IsTrue(EasyLoggerManager.HasEasyLoggingAppender());
}
Expand All @@ -65,54 +65,46 @@ public void TestFailToEnableEasyLoggingForWrongConfiguration()

// act
var thrown = Assert.Throws<SnowflakeDbException>(() => conn.Open());

// assert
Assert.That(thrown.Message, Does.Contain("Connection string is invalid: Unable to connect"));
Assert.IsFalse(EasyLoggerManager.HasEasyLoggingAppender());
}
}

[Test]
[Platform(Exclude="Win", Reason="skip test on Windows")]
public void TestFailToEnableEasyLoggingWhenConfigHasWrongPermissions()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Assert.Ignore("skip test on Windows");
}

// arrange
var configFilePath = CreateConfigTempFile(s_workingDirectory, Config("WARN", s_workingDirectory));
Syscall.chmod(configFilePath, FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IWGRP);
using (IDbConnection conn = new SnowflakeDbConnection())
{
conn.ConnectionString = ConnectionString + $"CLIENT_CONFIG_FILE={configFilePath}";

// act
var thrown = Assert.Throws<SnowflakeDbException>(() => conn.Open());

// assert
Assert.That(thrown.Message, Does.Contain("Connection string is invalid: Unable to connect"));
Assert.IsFalse(EasyLoggerManager.HasEasyLoggingAppender());
}
}

[Test]
[Platform(Exclude="Win", Reason="skip test on Windows")]
public void TestFailToEnableEasyLoggingWhenLogDirectoryNotAccessible()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Assert.Ignore("skip test on Windows");
}

// arrange
var configFilePath = CreateConfigTempFile(s_workingDirectory, Config("WARN", "/"));
using (IDbConnection conn = new SnowflakeDbConnection())
{
conn.ConnectionString = ConnectionString + $"CLIENT_CONFIG_FILE={configFilePath}";

// act
var thrown = Assert.Throws<SnowflakeDbException>(() => conn.Open());

// assert
Assert.That(thrown.Message, Does.Contain("Connection string is invalid: Unable to connect"));
Assert.That(thrown.InnerException.Message, Does.Contain("Failed to create logs directory"));
Expand All @@ -121,4 +113,4 @@ public void TestFailToEnableEasyLoggingWhenLogDirectoryNotAccessible()

}
}
}
}
2 changes: 1 addition & 1 deletion Snowflake.Data/Configuration/EasyLoggingConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void CheckIfValidPermissions(FileStream fileStream, string filePath)
var hasPermissions = ((UnixFileMode.OtherRead | UnixFileMode.GroupWrite) & unixFileMode) == 0;
#else
var entitlements = FileAccessPermissions.GroupWrite | FileAccessPermissions.OtherWrite;
var hasPermissions = _unixOperations.CheckFileHasAnyOfPermissions(filePath, entitlements);
var hasPermissions = !_unixOperations.CheckFileHasAnyOfPermissions(filePath, entitlements);
#endif
if (hasPermissions)
{
Expand Down
2 changes: 1 addition & 1 deletion ci/image/Dockerfile.dotnet-centos7-net6-build
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SHELL [ "/usr/bin/scl", "enable", "devtoolset-8"]

# dotnet-sdk-6.0
RUN rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
RUN yum -y install --exclude 1:openssl-libs-1.0.2k-26.el7_9.x86_64 dotnet-sdk-8.0
RUN yum -y install --exclude 1:openssl-libs-1.0.2k-26.el7_9.x86_64 dotnet-sdk-6.0

# workspace
RUN mkdir -p /home/user && \
Expand Down

0 comments on commit 69b01cf

Please sign in to comment.