1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-27 22:57:09 -04:00

New: Show health warning if system time is off expected time

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
This commit is contained in:
Mark McDowall
2019-04-28 11:50:18 -07:00
committed by Qstick
parent f39824cb9c
commit 3766e0eba9
4 changed files with 100 additions and 1 deletions
@@ -0,0 +1,49 @@
using System;
using System.Text;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Cloud;
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.HealthCheck.Checks;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.HealthCheck.Checks
{
[TestFixture]
public class SystemTimeCheckFixture : CoreTest<SystemTimeCheck>
{
[SetUp]
public void Setup()
{
Mocker.SetConstant<IRadarrCloudRequestBuilder>(new RadarrCloudRequestBuilder());
}
private void GivenServerTime(DateTime dateTime)
{
var json = new ServiceTimeResponse { DateTimeUtc = dateTime }.ToJson();
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Execute(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Encoding.ASCII.GetBytes(json)));
}
[Test]
public void should_not_return_error_when_system_time_is_close_to_server_time()
{
GivenServerTime(DateTime.UtcNow);
Subject.Check().ShouldBeOk();
}
[Test]
public void should_return_error_when_system_time_is_more_than_one_day_from_server_time()
{
GivenServerTime(DateTime.UtcNow.AddDays(2));
Subject.Check().ShouldBeError();
ExceptionVerification.ExpectedErrors(1);
}
}
}