New: HealthCheck for valid Branch value

(cherry picked from commit ef2f954b814b10094de25d691812e699a587e0f4)
pull/1323/head
Qstick 4 years ago committed by ta264
parent 7528ed4084
commit 5f946c0aa3

@ -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<ReleaseBranchCheck>
{
[SetUp]
public void Setup()
{
Mocker.GetMock<ILocalizationService>()
.Setup(s => s.GetLocalizedString(It.IsAny<string>()))
.Returns("Some Warning Message");
}
private void GivenValidBranch(string branch)
{
Mocker.GetMock<IConfigFileProvider>()
.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();
}
}
}

@ -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
}
}
}

@ -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"
}
}
Loading…
Cancel
Save