-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7535dc
commit 26a5d53
Showing
53 changed files
with
652 additions
and
460 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
Snowflake.Data.Tests/UnitTests/Logger/SFLoggerPairTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* Copyright (c) 2024 Snowflake Computing Inc. All rights reserved. | ||
*/ | ||
|
||
using NUnit.Framework; | ||
using Snowflake.Data.Configuration; | ||
using Snowflake.Data.Log; | ||
using System; | ||
|
||
namespace Snowflake.Data.Tests.UnitTests | ||
{ | ||
[TestFixture, NonParallelizable] | ||
class SFLoggerPairTest | ||
{ | ||
SFLogger _loggerPair; | ||
|
||
[OneTimeSetUp] | ||
public static void BeforeAll() | ||
{ | ||
// Log level defaults to Warn on net6.0 builds in github actions | ||
// Set the root level to Debug | ||
EasyLoggerManager.Instance.ReconfigureEasyLogging(EasyLoggingLogLevel.Debug, "STDOUT"); | ||
} | ||
|
||
[OneTimeTearDown] | ||
public static void AfterAll() | ||
{ | ||
EasyLoggerManager.Instance.ReconfigureEasyLogging(EasyLoggingLogLevel.Warn, "STDOUT"); | ||
} | ||
|
||
[SetUp] | ||
public void BeforeTest() | ||
{ | ||
_loggerPair = SFLoggerFactory.GetLogger<SFLoggerPairTest>(); | ||
} | ||
|
||
[TearDown] | ||
public void AfterTest() | ||
{ | ||
// Return to default setting | ||
SFLoggerFactory.EnableSFLogger(); | ||
} | ||
|
||
[Test] | ||
public void TestUsingSFLogger() | ||
{ | ||
SFLoggerFactory.EnableSFLogger(); | ||
_loggerPair = SFLoggerFactory.GetLogger<SFLoggerPairTest>(); | ||
Assert.IsInstanceOf<SFLoggerPair>(_loggerPair); | ||
} | ||
|
||
[Test] | ||
public void TestIsDebugEnabled( | ||
[Values(false, true)] bool isEnabled) | ||
{ | ||
_loggerPair = GetLogger(isEnabled); | ||
|
||
Assert.AreEqual(isEnabled, _loggerPair.IsDebugEnabled()); | ||
_loggerPair.Debug("debug log message", new Exception("test exception")); | ||
} | ||
|
||
[Test] | ||
public void TestIsInfoEnabled( | ||
[Values(false, true)] bool isEnabled) | ||
{ | ||
_loggerPair = GetLogger(isEnabled); | ||
|
||
Assert.AreEqual(isEnabled, _loggerPair.IsInfoEnabled()); | ||
_loggerPair.Info("info log message", new Exception("test exception")); | ||
} | ||
|
||
[Test] | ||
public void TestIsWarnEnabled( | ||
[Values(false, true)] bool isEnabled) | ||
{ | ||
_loggerPair = GetLogger(isEnabled); | ||
|
||
Assert.AreEqual(isEnabled, _loggerPair.IsWarnEnabled()); | ||
_loggerPair.Warn("warn log message", new Exception("test exception")); | ||
} | ||
|
||
[Test] | ||
public void TestIsErrorEnabled( | ||
[Values(false, true)] bool isEnabled) | ||
{ | ||
_loggerPair = GetLogger(isEnabled); | ||
|
||
Assert.AreEqual(isEnabled, _loggerPair.IsErrorEnabled()); | ||
_loggerPair.Error("error log message", new Exception("test exception")); | ||
} | ||
|
||
[Test] | ||
public void TestIsFatalEnabled( | ||
[Values(false, true)] bool isEnabled) | ||
{ | ||
_loggerPair = GetLogger(isEnabled); | ||
|
||
Assert.AreEqual(isEnabled, _loggerPair.IsFatalEnabled()); | ||
_loggerPair.Fatal("fatal log message", new Exception("test exception")); | ||
} | ||
|
||
[Test] | ||
public void TestGetAppenders() | ||
{ | ||
Assert.Throws<NotImplementedException>(() => _loggerPair.GetAppenders()); | ||
} | ||
|
||
[Test] | ||
public void TestAddAppender() | ||
{ | ||
Assert.Throws<NotImplementedException>(() => _loggerPair.AddAppender(new SFConsoleAppender())); | ||
} | ||
|
||
[Test] | ||
public void TestRemoveAppender() | ||
{ | ||
Assert.Throws<NotImplementedException>(() => _loggerPair.RemoveAppender(new SFConsoleAppender())); | ||
} | ||
|
||
[Test] | ||
public void TestSetLevel() | ||
{ | ||
Assert.Throws<NotImplementedException>(() => _loggerPair.SetLevel(LoggingEvent.DEBUG)); | ||
} | ||
|
||
private SFLogger GetLogger(bool isEnabled) | ||
{ | ||
if (isEnabled) | ||
{ | ||
SFLoggerFactory.EnableSFLogger(); | ||
} | ||
else | ||
{ | ||
SFLoggerFactory.DisableSFLogger(); | ||
} | ||
|
||
return SFLoggerFactory.GetLogger<SFLoggerPairTest>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.