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..d44bb99db --- /dev/null +++ b/src/NzbDrone.Core.Test/HealthCheck/Checks/ReleaseBranchCheckFixture.cs @@ -0,0 +1,51 @@ +using Moq; +using NUnit.Framework; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.HealthCheck.Checks; +using NzbDrone.Core.Localization; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.HealthCheck.Checks +{ + [TestFixture] + public class ReleaseBranchCheckFixture : CoreTest + { + [SetUp] + public void Setup() + { + Mocker.GetMock() + .Setup(s => s.GetLocalizedString(It.IsAny())) + .Returns("Some Warning Message"); + } + + private void GivenValidBranch(string branch) + { + Mocker.GetMock() + .SetupGet(s => s.Branch) + .Returns(branch); + } + + [TestCase("book-index")] + [TestCase("phantom")] + + // ToDo: Master should be valid once released + [TestCase("master")] + public void should_return_warning_when_branch_is_not_valid(string branch) + { + GivenValidBranch(branch); + + Subject.Check().ShouldBeWarning(); + } + + [TestCase("nightly")] + [TestCase("Nightly")] + [TestCase("develop")] + [TestCase("Develop")] + 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..b4e24074d --- /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; +using NzbDrone.Core.Localization; + +namespace NzbDrone.Core.HealthCheck.Checks +{ + [CheckOn(typeof(ConfigSavedEvent))] + public class ReleaseBranchCheck : HealthCheckBase + { + private readonly IConfigFileProvider _configFileService; + + public ReleaseBranchCheck(IConfigFileProvider configFileService, ILocalizationService localizationService) + : base(localizationService) + { + _configFileService = configFileService; + } + + public override HealthCheck Check() + { + var currentBranch = _configFileService.Branch.ToLower(); + + if (!Enum.GetNames(typeof(ReleaseBranches)).Any(x => x.ToLower() == currentBranch)) + { + return new HealthCheck(GetType(), HealthCheckResult.Warning, string.Format(_localizationService.GetLocalizedString("ReleaseBranchCheckOfficialBranchMessage"), _configFileService.Branch), "#branch-is-not-a-valid-release-branch"); + } + + return new HealthCheck(GetType()); + } + + public enum ReleaseBranches + { + // ToDo Enable Master as valid once released + //Master, + Develop, + Nightly + } + } +} diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index 5df1e43f6..260cde907 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -487,6 +487,7 @@ "RefreshInformation": "Refresh information", "RefreshInformationAndScanDisk": "Refresh information and scan disk", "RefreshScan": "Refresh & Scan", + "ReleaseBranchCheckOfficialBranchMessage": "Branch {0} is not a valid Readarr release branch, you will not receive updates", "ReleaseDate": "Release Date", "ReleaseGroup": "Release Group", "ReleaseProfiles": "Release Profiles", @@ -740,4 +741,4 @@ "WriteTagsSync": "All files; keep in sync with Goodreads", "Year": "Year", "YesCancel": "Yes, Cancel" -} +} \ No newline at end of file