mirror of https://github.com/lidarr/Lidarr
Set test log output via environment variable
This commit is contained in:
parent
2dddf8cb33
commit
899f12fd0c
|
@ -1,6 +1,8 @@
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NUnit.Framework.Interfaces;
|
using NUnit.Framework.Interfaces;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
@ -20,9 +22,19 @@ namespace NzbDrone.Test.Common
|
||||||
if (LogManager.Configuration == null || LogManager.Configuration.AllTargets.None(c => c is ExceptionVerification))
|
if (LogManager.Configuration == null || LogManager.Configuration.AllTargets.None(c => c is ExceptionVerification))
|
||||||
{
|
{
|
||||||
LogManager.Configuration = new LoggingConfiguration();
|
LogManager.Configuration = new LoggingConfiguration();
|
||||||
var consoleTarget = new ConsoleTarget { Layout = "${level}: ${message} ${exception}" };
|
|
||||||
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
var logOutput = TestLogOutput.Console;
|
||||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));
|
Enum.TryParse<TestLogOutput>(Environment.GetEnvironmentVariable("LIDARR_TESTS_LOG_OUTPUT"), out logOutput);
|
||||||
|
|
||||||
|
switch (logOutput)
|
||||||
|
{
|
||||||
|
case TestLogOutput.Console:
|
||||||
|
RegisterConsoleLogger();
|
||||||
|
break;
|
||||||
|
case TestLogOutput.File:
|
||||||
|
RegisterFileLogger();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
RegisterExceptionVerification();
|
RegisterExceptionVerification();
|
||||||
|
|
||||||
|
@ -30,6 +42,32 @@ namespace NzbDrone.Test.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void RegisterConsoleLogger()
|
||||||
|
{
|
||||||
|
var consoleTarget = new ConsoleTarget { Layout = "${level}: ${message} ${exception}" };
|
||||||
|
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
||||||
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RegisterFileLogger()
|
||||||
|
{
|
||||||
|
const string layout = @"${level}|${message}${onexception:inner=${newline}${newline}${exception:format=ToString}${newline}}";
|
||||||
|
|
||||||
|
var fileTarget = new FileTarget();
|
||||||
|
|
||||||
|
fileTarget.Name = "Test File Logger";
|
||||||
|
fileTarget.FileName = Path.Combine(TestContext.CurrentContext.WorkDirectory, "TestLog.txt");
|
||||||
|
fileTarget.AutoFlush = false;
|
||||||
|
fileTarget.KeepFileOpen = true;
|
||||||
|
fileTarget.ConcurrentWrites = true;
|
||||||
|
fileTarget.ConcurrentWriteAttemptDelay = 50;
|
||||||
|
fileTarget.ConcurrentWriteAttempts = 10;
|
||||||
|
fileTarget.Layout = layout;
|
||||||
|
|
||||||
|
LogManager.Configuration.AddTarget(fileTarget.GetType().Name, fileTarget);
|
||||||
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, fileTarget));
|
||||||
|
}
|
||||||
|
|
||||||
private static void RegisterExceptionVerification()
|
private static void RegisterExceptionVerification()
|
||||||
{
|
{
|
||||||
var exceptionVerification = new ExceptionVerification();
|
var exceptionVerification = new ExceptionVerification();
|
||||||
|
@ -42,6 +80,7 @@ namespace NzbDrone.Test.Common
|
||||||
{
|
{
|
||||||
InitLogging();
|
InitLogging();
|
||||||
ExceptionVerification.Reset();
|
ExceptionVerification.Reset();
|
||||||
|
TestLogger.Info("--- Start: {0} ---", TestContext.CurrentContext.Test.FullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TearDown]
|
[TearDown]
|
||||||
|
@ -53,6 +92,8 @@ namespace NzbDrone.Test.Common
|
||||||
{
|
{
|
||||||
ExceptionVerification.AssertNoUnexpectedLogs();
|
ExceptionVerification.AssertNoUnexpectedLogs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TestLogger.Info("--- End: {0} ---", TestContext.CurrentContext.Test.FullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,7 @@
|
||||||
<Compile Include="StringExtensions.cs" />
|
<Compile Include="StringExtensions.cs" />
|
||||||
<Compile Include="TestBase.cs" />
|
<Compile Include="TestBase.cs" />
|
||||||
<Compile Include="TestException.cs" />
|
<Compile Include="TestException.cs" />
|
||||||
|
<Compile Include="TestLogOutput.cs" />
|
||||||
<Compile Include="TestValidator.cs" />
|
<Compile Include="TestValidator.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace NzbDrone.Test.Common
|
||||||
|
{
|
||||||
|
public enum TestLogOutput
|
||||||
|
{
|
||||||
|
Console = 0,
|
||||||
|
File = 1,
|
||||||
|
None = 2
|
||||||
|
}
|
||||||
|
}
|
8
test.sh
8
test.sh
|
@ -4,14 +4,20 @@ WHERE="cat != ManualTest"
|
||||||
TEST_DIR="."
|
TEST_DIR="."
|
||||||
TEST_PATTERN="*Test.dll"
|
TEST_PATTERN="*Test.dll"
|
||||||
ASSEMBLIES=""
|
ASSEMBLIES=""
|
||||||
|
TEST_LOG_FILE="TestLog.txt"
|
||||||
|
|
||||||
if [ -d "$TEST_DIR/_tests" ]; then
|
if [ -d "$TEST_DIR/_tests" ]; then
|
||||||
TEST_DIR="$TEST_DIR/_tests"
|
TEST_DIR="$TEST_DIR/_tests"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -f "$TEST_LOG_FILE"
|
||||||
|
|
||||||
|
# Uncomment to log test output to a file instead of the console
|
||||||
|
# export LIDARR_TESTS_LOG_OUTPUT="File"
|
||||||
|
|
||||||
NUNIT="$TEST_DIR/NUnit.ConsoleRunner.3.2.0/tools/nunit3-console.exe"
|
NUNIT="$TEST_DIR/NUnit.ConsoleRunner.3.2.0/tools/nunit3-console.exe"
|
||||||
NUNIT_COMMAND="$NUNIT"
|
NUNIT_COMMAND="$NUNIT"
|
||||||
NUNIT_PARAMS="--teamcity"
|
NUNIT_PARAMS="--teamcity --workers=1"
|
||||||
|
|
||||||
if [ "$PLATFORM" = "Windows" ]; then
|
if [ "$PLATFORM" = "Windows" ]; then
|
||||||
WHERE="$WHERE && cat != LINUX"
|
WHERE="$WHERE && cat != LINUX"
|
||||||
|
|
Loading…
Reference in New Issue