From 331bf5914a0a275782f5ca2142d8a15c8a42b4d9 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 28 Oct 2017 17:04:35 -0400 Subject: [PATCH] Fixed: Check if NzbGet KeepHistory value is set too high --- .../NzbgetTests/NzbgetFixture.cs | 26 ++++++++++++++++--- .../Download/Clients/Nzbget/Nzbget.cs | 18 ++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs index c15deaf27..2da8f4d50 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs @@ -19,6 +19,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests private NzbgetQueueItem _queued; private NzbgetHistoryItem _failed; private NzbgetHistoryItem _completed; + private Dictionary _configItems; [SetUp] public void Setup() @@ -80,13 +81,17 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests DownloadRate = 7000000 }); - var configItems = new Dictionary(); - configItems.Add("Category1.Name", "music"); - configItems.Add("Category1.DestDir", @"/remote/mount/music"); + Mocker.GetMock() + .Setup(v => v.GetVersion(It.IsAny())) + .Returns("14.0"); + + _configItems = new Dictionary(); + _configItems.Add("Category1.Name", "music"); + _configItems.Add("Category1.DestDir", @"/remote/mount/music"); Mocker.GetMock() .Setup(v => v.GetConfig(It.IsAny())) - .Returns(configItems); + .Returns(_configItems); } protected void GivenFailedDownload() @@ -414,5 +419,18 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests 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); + } } } diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs index 2a84ab1b4..d682b6a6c 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs @@ -1,7 +1,8 @@ using System; +using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; -using System.Collections.Generic; using FluentValidation.Results; using NLog; using NzbDrone.Common.Disk; @@ -9,8 +10,8 @@ using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Validation; using NzbDrone.Core.RemotePathMappings; +using NzbDrone.Core.Validation; namespace NzbDrone.Core.Download.Clients.Nzbget { @@ -296,8 +297,9 @@ namespace NzbDrone.Core.Download.Clients.Nzbget { var config = _proxy.GetConfig(Settings); - var keepHistory = config.GetValueOrDefault("KeepHistory"); - if (keepHistory == "0") + var keepHistory = config.GetValueOrDefault("KeepHistory", "7"); + 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") { @@ -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." }; } + 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; }