parent
75270d8151
commit
54c914d48f
@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.HealthCheck.Checks;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Indexers.Torznab;
|
||||
using NzbDrone.Core.Localization;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.HealthCheck.Checks
|
||||
{
|
||||
[TestFixture]
|
||||
public class IndexerJackettAllCheckFixture : CoreTest<IndexerJackettAllCheck>
|
||||
{
|
||||
private List<IndexerDefinition> _indexers = new List<IndexerDefinition>();
|
||||
private IndexerDefinition _definition;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
Mocker.GetMock<IIndexerFactory>()
|
||||
.Setup(v => v.All())
|
||||
.Returns(_indexers);
|
||||
|
||||
Mocker.GetMock<ILocalizationService>()
|
||||
.Setup(s => s.GetLocalizedString(It.IsAny<string>()))
|
||||
.Returns("Some Warning Message");
|
||||
}
|
||||
|
||||
private void GivenIndexer(string baseUrl, string apiPath)
|
||||
{
|
||||
var torznabSettings = new TorznabSettings
|
||||
{
|
||||
BaseUrl = baseUrl,
|
||||
ApiPath = apiPath
|
||||
};
|
||||
|
||||
_definition = new IndexerDefinition
|
||||
{
|
||||
Name = "Indexer",
|
||||
ConfigContract = "TorznabSettings",
|
||||
Settings = torznabSettings
|
||||
};
|
||||
|
||||
_indexers.Add(_definition);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_return_error_when_no_indexers()
|
||||
{
|
||||
Subject.Check().ShouldBeOk();
|
||||
}
|
||||
|
||||
[TestCase("http://localhost:9117/", "api")]
|
||||
public void should_not_return_error_when_no_jackett_all_indexers(string baseUrl, string apiPath)
|
||||
{
|
||||
GivenIndexer(baseUrl, apiPath);
|
||||
|
||||
Subject.Check().ShouldBeOk();
|
||||
}
|
||||
|
||||
[TestCase("http://localhost:9117/torznab/all/api", "api")]
|
||||
[TestCase("http://localhost:9117/api/v2.0/indexers/all/results/torznab", "api")]
|
||||
[TestCase("http://localhost:9117/", "/torznab/all/api")]
|
||||
[TestCase("http://localhost:9117/", "/api/v2.0/indexers/all/results/torznab")]
|
||||
public void should_return_warning_if_any_jackett_all_indexer_exists(string baseUrl, string apiPath)
|
||||
{
|
||||
GivenIndexer(baseUrl, apiPath);
|
||||
|
||||
Subject.Check().ShouldBeWarning();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Indexers.Torznab;
|
||||
using NzbDrone.Core.Localization;
|
||||
using NzbDrone.Core.ThingiProvider.Events;
|
||||
|
||||
namespace NzbDrone.Core.HealthCheck.Checks
|
||||
{
|
||||
[CheckOn(typeof(ProviderUpdatedEvent<IIndexer>))]
|
||||
[CheckOn(typeof(ProviderDeletedEvent<IIndexer>))]
|
||||
[CheckOn(typeof(ProviderStatusChangedEvent<IIndexer>))]
|
||||
public class IndexerJackettAllCheck : HealthCheckBase
|
||||
{
|
||||
private readonly IIndexerFactory _providerFactory;
|
||||
|
||||
public IndexerJackettAllCheck(IIndexerFactory providerFactory, ILocalizationService localizationService)
|
||||
: base(localizationService)
|
||||
{
|
||||
_providerFactory = providerFactory;
|
||||
}
|
||||
|
||||
public override HealthCheck Check()
|
||||
{
|
||||
var jackettAllProviders = _providerFactory.All().Where(
|
||||
i => i.ConfigContract.Equals("TorznabSettings") &&
|
||||
((i.Settings as TorznabSettings).BaseUrl.Contains("/torznab/all/api", StringComparison.InvariantCultureIgnoreCase) ||
|
||||
(i.Settings as TorznabSettings).BaseUrl.Contains("/api/v2.0/indexers/all/results/torznab", StringComparison.InvariantCultureIgnoreCase) ||
|
||||
(i.Settings as TorznabSettings).ApiPath.Contains("/torznab/all/api", StringComparison.InvariantCultureIgnoreCase) ||
|
||||
(i.Settings as TorznabSettings).ApiPath.Contains("/api/v2.0/indexers/all/results/torznab", StringComparison.InvariantCultureIgnoreCase)));
|
||||
|
||||
if (jackettAllProviders.Empty())
|
||||
{
|
||||
return new HealthCheck(GetType());
|
||||
}
|
||||
|
||||
return new HealthCheck(GetType(),
|
||||
HealthCheckResult.Warning,
|
||||
string.Format(_localizationService.GetLocalizedString("IndexerJackettAll"),
|
||||
string.Join(", ", jackettAllProviders.Select(i => i.Name))),
|
||||
"#jackett-all-endpoint-used");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue