mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-22 22:14:44 -04:00
New: Show health warning if system time is off expected time
This commit is contained in:
@@ -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<IReadarrCloudRequestBuilder>(new ReadarrCloudRequestBuilder());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user