(cherry picked from commit ef2f954b814b10094de25d691812e699a587e0f4)pull/1323/head
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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue