Fixed: Check if NzbGet KeepHistory value is set too high

pull/110/head
Qstick 7 years ago
parent b88d4aad0e
commit 331bf5914a

@ -19,6 +19,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
private NzbgetQueueItem _queued; private NzbgetQueueItem _queued;
private NzbgetHistoryItem _failed; private NzbgetHistoryItem _failed;
private NzbgetHistoryItem _completed; private NzbgetHistoryItem _completed;
private Dictionary<string, string> _configItems;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -80,13 +81,17 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
DownloadRate = 7000000 DownloadRate = 7000000
}); });
var configItems = new Dictionary<string, string>(); Mocker.GetMock<INzbgetProxy>()
configItems.Add("Category1.Name", "music"); .Setup(v => v.GetVersion(It.IsAny<NzbgetSettings>()))
configItems.Add("Category1.DestDir", @"/remote/mount/music"); .Returns("14.0");
_configItems = new Dictionary<string, string>();
_configItems.Add("Category1.Name", "music");
_configItems.Add("Category1.DestDir", @"/remote/mount/music");
Mocker.GetMock<INzbgetProxy>() Mocker.GetMock<INzbgetProxy>()
.Setup(v => v.GetConfig(It.IsAny<NzbgetSettings>())) .Setup(v => v.GetConfig(It.IsAny<NzbgetSettings>()))
.Returns(configItems); .Returns(_configItems);
} }
protected void GivenFailedDownload() protected void GivenFailedDownload()
@ -414,5 +419,18 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
error.IsValid.Should().Be(expected); error.IsValid.Should().Be(expected);
} }
[TestCase("0", false)]
[TestCase("1", true)]
[TestCase(" 7", false)]
[TestCase("5000000", false)]
public void should_test_keephistory(string keephistory, bool expected)
{
_configItems["KeepHistory"] = keephistory;
var error = Subject.Test();
error.IsValid.Should().Be(expected);
}
} }
} }

@ -1,7 +1,8 @@
using System; using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Collections.Generic;
using FluentValidation.Results; using FluentValidation.Results;
using NLog; using NLog;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
@ -9,8 +10,8 @@ using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Validation;
using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.RemotePathMappings;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Download.Clients.Nzbget namespace NzbDrone.Core.Download.Clients.Nzbget
{ {
@ -296,8 +297,9 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
{ {
var config = _proxy.GetConfig(Settings); var config = _proxy.GetConfig(Settings);
var keepHistory = config.GetValueOrDefault("KeepHistory"); var keepHistory = config.GetValueOrDefault("KeepHistory", "7");
if (keepHistory == "0") int value;
if (!int.TryParse(keepHistory, NumberStyles.None, CultureInfo.InvariantCulture, out value) || value == 0)
{ {
return new NzbDroneValidationFailure(string.Empty, "NzbGet setting KeepHistory should be greater than 0") return new NzbDroneValidationFailure(string.Empty, "NzbGet setting KeepHistory should be greater than 0")
{ {
@ -305,6 +307,14 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
DetailedDescription = "NzbGet setting KeepHistory is set to 0. Which prevents Lidarr from seeing completed downloads." DetailedDescription = "NzbGet setting KeepHistory is set to 0. Which prevents Lidarr from seeing completed downloads."
}; };
} }
else if (value > 25000)
{
return new NzbDroneValidationFailure(string.Empty, "NzbGet setting KeepHistory should be less than 25000")
{
InfoLink = string.Format("http://{0}:{1}/", Settings.Host, Settings.Port),
DetailedDescription = "NzbGet setting KeepHistory is set too high."
};
}
return null; return null;
} }

Loading…
Cancel
Save