Added Mono version health check

pull/65/head
Mark McDowall 10 years ago
parent 1d4738b18f
commit 01d3decf7e

@ -36,7 +36,7 @@ namespace NzbDrone.Common.Test.DiskProviderTests
[Test]
public void should_be_able_to_check_space_on_ramdrive()
{
LinuxOnly();
MonoOnly();
Subject.GetAvailableSpace("/run/").Should().NotBe(0);
}

@ -19,7 +19,7 @@ namespace NzbDrone.Common.Test.EnsureTest
[TestCase(@"/var/user/file with, comma.mkv")]
public void EnsureLinuxPath(string path)
{
LinuxOnly();
MonoOnly();
Ensure.That(path, () => path).IsValidPath();
}
}

@ -50,7 +50,7 @@ namespace NzbDrone.Common.Test
[TestCase(@"//CAPITAL//lower// ", @"/CAPITAL/lower")]
public void Clean_Path_Linux(string dirty, string clean)
{
LinuxOnly();
MonoOnly();
var result = dirty.CleanFilePath();
result.Should().Be(clean);
@ -139,7 +139,7 @@ namespace NzbDrone.Common.Test
[Test]
public void get_actual_casing_should_return_original_value_in_linux()
{
LinuxOnly();
MonoOnly();
var path = Directory.GetCurrentDirectory();
path.GetActualCasing().Should().Be(path);
path.GetActualCasing().Should().Be(path);

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Processes;
using NzbDrone.Core.HealthCheck.Checks;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.HealthCheck.Checks
{
[TestFixture]
public class MonoVersionCheckFixture : CoreTest<DownloadClientCheck>
{
[SetUp]
public void Setup()
{
MonoOnly();
}
private void GivenOutput(string version)
{
Mocker.GetMock<IProcessProvider>()
.Setup(s => s.StartAndCapture("mono", "--version"))
.Returns(new ProcessOutput
{
Standard = new List<string>
{
String.Format("Mono JIT compiler version {0} (Debian {0}-8)", version),
"Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com"
}
});
}
[Test]
public void should_return_warning_when_mono_3_0()
{
GivenOutput("3.0.0.1");
Subject.Check().ShouldBeWarning();
}
[Test]
public void should_return_warning_when_mono_2_10_8()
{
GivenOutput("2.10.8.1");
Subject.Check().ShouldBeWarning();
}
[Test]
public void should_return_null_when_mono_3_2()
{
GivenOutput("3.2.0.1");
Subject.Check().Should().BeNull();
}
[Test]
public void should_return_null_when_mono_4_0()
{
GivenOutput("4.0.0.0");
Subject.Check().Should().BeNull();
}
}
}

@ -75,7 +75,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
[Test]
public void should_return_false_if_unopacking_on_linux()
{
LinuxOnly();
MonoOnly();
GivenInWorkingFolder();
GivenLastWriteTimeUtc(DateTime.UtcNow.AddDays(-5));

@ -108,7 +108,7 @@ namespace NzbDrone.Core.Test.MediaFiles
[Test]
public void filter_should_return_none_existing_files_not_ignoring_case()
{
LinuxOnly();
MonoOnly();
var files = new List<string>()
{

@ -125,10 +125,11 @@
<Compile Include="Framework\CoreTest.cs" />
<Compile Include="Framework\DbTest.cs" />
<Compile Include="Framework\NBuilderExtensions.cs" />
<Compile Include="HealthCheck\Checks\DownloadClientCheckFixture.cs" />
<Compile Include="HealthCheck\Checks\UpdateCheckFixture.cs" />
<Compile Include="HealthCheck\Checks\IndexerCheckFixture.cs" />
<Compile Include="HealthCheck\Checks\DroneFactoryCheckFixture.cs" />
<Compile Include="HealthCheck\Checks\DownloadClientCheckFixture.cs" />
<Compile Include="HealthCheck\Checks\MonoVersionCheckFixture.cs" />
<Compile Include="HealthCheck\Checks\HealthCheckFixtureExtentions.cs" />
<Compile Include="HistoryTests\HistoryServiceFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedHistoryItemsFixture.cs" />

@ -0,0 +1,49 @@
using System;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Processes;
namespace NzbDrone.Core.HealthCheck.Checks
{
public class MonoVersionnCheck : IProvideHealthCheck
{
private readonly IProcessProvider _processProvider;
private readonly Logger _logger;
private static readonly Regex VersionRegex = new Regex(@"(?<=\W)(?<version>\d+\.\d+\.\d+\.\d+)(?=\W)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public MonoVersionnCheck(IProcessProvider processProvider, Logger logger)
{
_processProvider = processProvider;
_logger = logger;
}
public HealthCheck Check()
{
if (!OsInfo.IsMono)
{
return null;
}
var output = _processProvider.StartAndCapture("mono", "--version");
foreach (var line in output.Standard)
{
var versionMatch = VersionRegex.Match(line);
if (versionMatch.Success)
{
var version = new Version(versionMatch.Groups["version"].Value);
if (version >= new Version(3, 2))
{
_logger.Debug("mono version is 3.2 or better: {0}", version.ToString());
return null;
}
}
}
return new HealthCheck(HealthCheckResultType.Warning, "mono version is less than 3.2, upgrade for improved stability");
}
}
}

@ -268,6 +268,7 @@
<Compile Include="Exceptions\StatusCodeToExceptions.cs" />
<Compile Include="HealthCheck\CheckHealthCommand.cs" />
<Compile Include="HealthCheck\Checks\DownloadClientCheck.cs" />
<Compile Include="HealthCheck\Checks\MonoVersionnCheck.cs" />
<Compile Include="HealthCheck\Checks\DroneFactoryCheck.cs" />
<Compile Include="HealthCheck\Checks\IndexerCheck.cs" />
<Compile Include="HealthCheck\Checks\UpdateCheck.cs" />

@ -8,7 +8,7 @@ namespace NzbDrone.Mono.Test.DiskProviderTests
{
public DiskProviderFixture()
{
LinuxOnly();
MonoOnly();
}
}
}

@ -8,7 +8,7 @@ namespace NzbDrone.Mono.Test.DiskProviderTests
{
public FreeSpaceFixture()
{
LinuxOnly();
MonoOnly();
}
}
}

@ -131,7 +131,7 @@ namespace NzbDrone.Test.Common
}
protected void LinuxOnly()
protected void MonoOnly()
{
if (!OsInfo.IsMono)
{

Loading…
Cancel
Save