Deskmetrics will not report any data unless using the master branch.

pull/2/head
kay.one 13 years ago
parent 7482a4c935
commit 44d6d20bd6

@ -4,6 +4,7 @@ using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests
@ -11,6 +12,13 @@ namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
public class AnalyticsProviderFixture : CoreTest public class AnalyticsProviderFixture : CoreTest
{ {
[SetUp]
public void Setup()
{
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.UpdateUrl).Returns(UpdateProvider.DEFAULT_UPDATE_URL);
}
[Test] [Test]
public void checkpoint_should_stop_existing_start_then_start_again() public void checkpoint_should_stop_existing_start_then_start_again()
{ {
@ -60,5 +68,48 @@ namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests
} }
[Test]
public void shouldnt_register_anything_if_not_on_master_branch()
{
EnviromentProvider.IsNewInstall = false;
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.UpdateUrl).Returns("http://update.nzbdrone.com/master_auto/");
Mocker.GetMock<IDeskMetricsClient>(MockBehavior.Strict);
Mocker.Resolve<AnalyticsProvider>().Checkpoint();
}
[Test]
public void new_install_shouldnt_register_anything_if_not_on_master_branch()
{
EnviromentProvider.IsNewInstall = true;
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.UpdateUrl).Returns("http://update.nzbdrone.com/master_auto/");
Mocker.GetMock<IDeskMetricsClient>(MockBehavior.Strict);
Mocker.Resolve<AnalyticsProvider>().Checkpoint();
}
[TestCase("http://update.nzbdrone.com/master/")]
[TestCase("http://update.nzbdrone.com/master//")]
[TestCase("http://update.nzbdrone.com/master")]
[TestCase("http://update.nzbdrone.com/master ")]
[TestCase("http://update.nzbdrone.com/master/ ")]
[TestCase("http://UPDATE.nzbdrone.COM/master/ ")]
public void should_still_work_if_url_is_slightly_diffrent(string url)
{
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.UpdateUrl).Returns(url);
var provider = Mocker.Resolve<AnalyticsProvider>();
provider.Checkpoint();
Mocker.GetMock<IDeskMetricsClient>().Verify(c => c.Start(), Times.Once());
}
} }
} }

@ -4,6 +4,7 @@ using DeskMetrics;
using NLog; using NLog;
using Ninject; using Ninject;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers namespace NzbDrone.Core.Providers
{ {
@ -12,13 +13,15 @@ namespace NzbDrone.Core.Providers
private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private readonly IDeskMetricsClient _deskMetricsClient; private readonly IDeskMetricsClient _deskMetricsClient;
private readonly ConfigProvider _configProvider;
public const string DESKMETRICS_TEST_ID = "4ea8d347a14ad71442000002"; public const string DESKMETRICS_TEST_ID = "4ea8d347a14ad71442000002";
public const string DESKMETRICS_PRODUCTION_ID = "4f20b01ea14ad729b2000000"; public const string DESKMETRICS_PRODUCTION_ID = "4f20b01ea14ad729b2000000";
[Inject] [Inject]
public AnalyticsProvider(IDeskMetricsClient deskMetricsClient) public AnalyticsProvider(IDeskMetricsClient deskMetricsClient, ConfigProvider configProvider)
{ {
_deskMetricsClient = deskMetricsClient; _deskMetricsClient = deskMetricsClient;
_configProvider = configProvider;
} }
public AnalyticsProvider() public AnalyticsProvider()
@ -30,6 +33,10 @@ namespace NzbDrone.Core.Providers
{ {
try try
{ {
//Don't report anything unless working from master branch.
if (!IsOnMasterBranch())
return;
if (EnviromentProvider.IsNewInstall) if (EnviromentProvider.IsNewInstall)
{ {
_deskMetricsClient.RegisterInstall(); _deskMetricsClient.RegisterInstall();
@ -50,5 +57,14 @@ namespace NzbDrone.Core.Providers
logger.WarnException("Error while sending analytics data.", e); logger.WarnException("Error while sending analytics data.", e);
} }
} }
private bool IsOnMasterBranch()
{
var defaultUpdateUrl = UpdateProvider.DEFAULT_UPDATE_URL.Trim().Trim('/');
var currentUpdateUrl = _configProvider.UpdateUrl.Trim().Trim('/');
return String.Equals(defaultUpdateUrl, currentUpdateUrl, StringComparison.InvariantCultureIgnoreCase);
}
} }
} }

@ -258,7 +258,7 @@ namespace NzbDrone.Core.Providers.Core
public virtual string UpdateUrl public virtual string UpdateUrl
{ {
get { return GetValue("UpdateUrl", @"http://update.nzbdrone.com/master/"); } get { return GetValue("UpdateUrl", UpdateProvider.DEFAULT_UPDATE_URL); }
set { SetValue("UpdateUrl", value); } set { SetValue("UpdateUrl", value); }
} }

@ -24,7 +24,7 @@ namespace NzbDrone.Core.Providers
private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private static readonly Regex parseRegex = new Regex(@"(?:\>)(?<filename>NzbDrone.+?(?<version>\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase); private static readonly Regex parseRegex = new Regex(@"(?:\>)(?<filename>NzbDrone.+?(?<version>\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase);
public const string DEFAULT_UPDATE_URL = @"http://update.nzbdrone.com/master/";
[Inject] [Inject]

Loading…
Cancel
Save