New: Explicitly enforce SABnzbd minimum version of 0.7.0

pull/4/head
Mark McDowall 8 years ago
parent f0ca2bc11e
commit 974a7276c3

@ -396,5 +396,21 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
result.OutputRootFolders.Should().NotBeNull();
result.OutputRootFolders.First().Should().Be(@"O:\mymount".AsOsAgnostic());
}
[TestCase("0.6.9", false)]
[TestCase("0.7.0", true)]
[TestCase("0.8.0", true)]
[TestCase("1.0.0", true)]
[TestCase("1.0.0RC1", true)]
public void should_test_version(string version, bool expected)
{
Mocker.GetMock<ISabnzbdProxy>()
.Setup(v => v.GetVersion(It.IsAny<SabnzbdSettings>()))
.Returns(version);
var error = Subject.Test();
error.IsValid.Should().Be(expected);
}
}
}

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using FluentValidation.Results;
using NLog;
using NzbDrone.Common.Disk;
@ -28,6 +29,8 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
_proxy = proxy;
}
private static readonly Regex VersionRegex = new Regex(@"(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?<candidate>.*)", RegexOptions.Compiled);
protected override string AddFromNzbFile(RemoteEpisode remoteEpisode, string filename, byte[] fileContent)
{
var category = Settings.TvCategory;
@ -253,25 +256,44 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
protected override void Test(List<ValidationFailure> failures)
{
failures.AddIfNotNull(TestConnection());
failures.AddIfNotNull(TestConnectionAndVersion());
failures.AddIfNotNull(TestAuthentication());
failures.AddIfNotNull(TestGlobalConfig());
failures.AddIfNotNull(TestCategory());
}
private ValidationFailure TestConnection()
private ValidationFailure TestConnectionAndVersion()
{
try
{
_proxy.GetVersion(Settings);
var version = _proxy.GetVersion(Settings);
var parsed = VersionRegex.Match(version);
if (!parsed.Success)
{
return new ValidationFailure("Version", "Unknown Version: " + version);
}
var major = Convert.ToInt32(parsed.Groups["major"].Value);
var minor = Convert.ToInt32(parsed.Groups["minor"].Value);
if (major >= 1)
{
return null;
}
if (minor >= 7)
{
return null;
}
return new ValidationFailure("Version", "Version 0.7.0+ is required, but found: " + version);
}
catch (Exception ex)
{
_logger.Error(ex, ex.Message);
return new ValidationFailure("Host", "Unable to connect to SABnzbd");
}
return null;
}
private ValidationFailure TestAuthentication()

@ -14,7 +14,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
SabnzbdAddResponse DownloadNzb(byte[] nzbData, string filename, string category, int priority, SabnzbdSettings settings);
void RemoveFrom(string source, string id,bool deleteData, SabnzbdSettings settings);
string ProcessRequest(IRestRequest restRequest, string action, SabnzbdSettings settings);
SabnzbdVersionResponse GetVersion(SabnzbdSettings settings);
string GetVersion(SabnzbdSettings settings);
SabnzbdConfig GetConfig(SabnzbdSettings settings);
SabnzbdQueue GetQueue(int start, int limit, SabnzbdSettings settings);
SabnzbdHistory GetHistory(int start, int limit, string category, SabnzbdSettings settings);
@ -68,7 +68,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
return response.Content;
}
public SabnzbdVersionResponse GetVersion(SabnzbdSettings settings)
public string GetVersion(SabnzbdSettings settings)
{
var request = new RestRequest();
var action = "mode=version";
@ -80,7 +80,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
response = new SabnzbdVersionResponse();
}
return response;
return response.Version;
}
public SabnzbdConfig GetConfig(SabnzbdSettings settings)

Loading…
Cancel
Save