Skip to content

Commit

Permalink
Use constant file names for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-lf committed Nov 14, 2024
1 parent 0ab8c66 commit 15090b4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Snowflake.Data.Tests/SFBaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ public static void RecordTestPerformance(string name, TimeSpan time)
public void Setup()
{
#if NETFRAMEWORK
Environment.SetEnvironmentVariable("net_test_framework", "net471");
Environment.SetEnvironmentVariable("NET_TEST_FRAMEWORK", "net471");
#else
Environment.SetEnvironmentVariable("net_test_framework", "net6.0");
Environment.SetEnvironmentVariable("NET_TEST_FRAMEWORK", "net6.0");
#endif
ILoggerFactory factory = LoggerFactory.Create(
builder => builder
Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data.Tests/TestLog4Net.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="MyRollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="test_log4net.log" />
<file value="${TEST_LOG4NET_FILE_NAME}"/>
<appendToFile value="true"/>
<rollingStyle value="Size" />
<maximumFileSize value="10MB" />
Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data.Tests/TestNLog.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!-- write logs to file -->
<target xsi:type="File"
name="logfile"
fileName="test_nlog.log"
fileName="${environment:TEST_NLOG_FILE_NAME}"
keepFileOpen="false"
concurrentWrites="true"
layout="${longdate}|${level}|${message} |${all-event-properties} ${exception:format=tostring}"/>
Expand Down
16 changes: 12 additions & 4 deletions Snowflake.Data.Tests/UnitTests/Logger/SFLoggerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Serilog;
using Serilog.Extensions.Logging;
using System.IO;
using System;

namespace Snowflake.Data.Tests.UnitTests
{
Expand All @@ -22,6 +23,10 @@ class SFLoggerTest
private const string ErrorMessage = "Error message";
private const string CriticalMessage = "critical message";

private const string Log4NetFileName = "test_log4net.log";
private const string SerilogFileName = "test_serilog.log";
private const string NlogFileName = "test_nlog.log";

public abstract class SFBaseLoggerTest
{
protected ILogger _logger;
Expand Down Expand Up @@ -154,14 +159,15 @@ public class Log4NetTest : SFBaseLoggerTest
[OneTimeSetUp]
public void SetUp()
{
Environment.SetEnvironmentVariable("TEST_LOG4NET_FILE_NAME", Log4NetFileName);
var factory = LoggerFactory.Create(
builder => builder
.AddLog4Net("TestLog4Net.config")
.SetMinimumLevel(LogLevel.Trace));

var log4netLogger = factory.CreateLogger("Log4NetTest");
SFLoggerFactory.SetCustomLogger(log4netLogger);
_logFile = "test_log4net.log";
_logFile = Log4NetFileName;
}
}

Expand All @@ -173,11 +179,12 @@ public void SetUp()
{
var loggerSerilog = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.File("test_serilog.log")
.WriteTo.File(SerilogFileName)
.CreateLogger();

var serilogLogger = new SerilogLoggerFactory(loggerSerilog).CreateLogger("SerilogTest");
SFLoggerFactory.SetCustomLogger(serilogLogger);
_logFile = "test_serilog.log";
_logFile = SerilogFileName;
}
}

Expand All @@ -187,14 +194,15 @@ public class NlogTest : SFBaseLoggerTest
[OneTimeSetUp]
public void SetUp()
{
Environment.SetEnvironmentVariable("TEST_NLOG_FILE_NAME", NlogFileName);
var factory = LoggerFactory.Create(
builder => builder
.AddNLog("TestNLog.config")
.SetMinimumLevel(LogLevel.Trace));

var nlogLogger = factory.CreateLogger("NlogTest");
SFLoggerFactory.SetCustomLogger(nlogLogger);
_logFile = "test_nlog.log";
_logFile = NlogFileName;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data.Tests/log4net.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="MyRollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="test_log4net_${net_test_framework}.log" />
<file value="test_log4net_${NET_TEST_FRAMEWORK}.log" />
<appendToFile value="true"/>
<rollingStyle value="Size" />
<maximumFileSize value="10MB" />
Expand Down

0 comments on commit 15090b4

Please sign in to comment.