From ef2f954b814b10094de25d691812e699a587e0f4 Mon Sep 17 00:00:00 2001 From: Qstick Date: Fri, 28 Feb 2020 20:56:37 -0500 Subject: [PATCH] New: HealthCheck for valid Branch value --- .../Checks/ReleaseBranchCheckFixture.cs | 44 +++++++++++++++++++ .../HealthCheck/Checks/ReleaseBranchCheck.cs | 40 +++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/NzbDrone.Core.Test/HealthCheck/Checks/ReleaseBranchCheckFixture.cs create mode 100644 src/NzbDrone.Core/HealthCheck/Checks/ReleaseBranchCheck.cs diff --git a/src/NzbDrone.Core.Test/HealthCheck/Checks/ReleaseBranchCheckFixture.cs b/src/NzbDrone.Core.Test/HealthCheck/Checks/ReleaseBranchCheckFixture.cs new file mode 100644 index 000000000..abeed1742 --- /dev/null +++ b/src/NzbDrone.Core.Test/HealthCheck/Checks/ReleaseBranchCheckFixture.cs @@ -0,0 +1,44 @@ +using NUnit.Framework; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.HealthCheck.Checks; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.HealthCheck.Checks +{ + [TestFixture] + public class ReleaseBranchCheckFixture : CoreTest + { + private void GivenValidBranch(string branch) + { + Mocker.GetMock() + .SetupGet(s => s.Branch) + .Returns(branch); + } + + [Test] + public void should_return_warning_when_branch_not_valid() + { + GivenValidBranch("master"); + + Subject.Check().ShouldBeWarning(); + } + + [TestCase("develop")] + [TestCase("nightly")] + public void should_return_error_when_branch_is_v1(string branch) + { + GivenValidBranch(branch); + + Subject.Check().ShouldBeError(); + } + + [TestCase("aphrodite")] + [TestCase("Aphrodite")] + public void should_return_no_warning_when_branch_valid(string branch) + { + GivenValidBranch(branch); + + Subject.Check().ShouldBeOk(); + } + } +} diff --git a/src/NzbDrone.Core/HealthCheck/Checks/ReleaseBranchCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/ReleaseBranchCheck.cs new file mode 100644 index 000000000..517888592 --- /dev/null +++ b/src/NzbDrone.Core/HealthCheck/Checks/ReleaseBranchCheck.cs @@ -0,0 +1,40 @@ +using System; +using System.Linq; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.Configuration.Events; + +namespace NzbDrone.Core.HealthCheck.Checks +{ + [CheckOn(typeof(ConfigSavedEvent))] + public class ReleaseBranchCheck : HealthCheckBase + { + private readonly IConfigFileProvider _configFileService; + + public ReleaseBranchCheck(IConfigFileProvider configFileService) + { + _configFileService = configFileService; + } + + public override HealthCheck Check() + { + var currentBranch = _configFileService.Branch.ToLower(); + + if (!Enum.GetNames(typeof(ReleaseBranches)).Any(x => x.ToLower() == currentBranch)) + { + if (currentBranch == "develop" || currentBranch == "nightly") + { + return new HealthCheck(GetType(), HealthCheckResult.Error, string.Format("Branch {0} is for a previous version of Radarr, set branch to 'Aphrodite' for further updates", _configFileService.Branch)); + } + + return new HealthCheck(GetType(), HealthCheckResult.Warning, string.Format("Branch {0} is not a valid Radarr release branch, you will not receive updates", _configFileService.Branch)); + } + + return new HealthCheck(GetType()); + } + + public enum ReleaseBranches + { + Aphrodite + } + } +}