mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-26 09:47:39 +00:00
TopLogs will now return the count pass in, reduced to 5000 from 7500 to prevent JsonSerialization issues when being sent to the grid.
Added tests for TopLogs and GetPagedLogs.
This commit is contained in:
parent
73fadac397
commit
070115a59a
3 changed files with 77 additions and 11 deletions
|
@ -1,12 +1,17 @@
|
||||||
// ReSharper disable RedundantUsingDirective
|
// ReSharper disable RedundantUsingDirective
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using AutoMoq;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
|
using Moq;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Instrumentation;
|
using NzbDrone.Core.Instrumentation;
|
||||||
|
using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
|
using NzbDrone.Core.Repository.Quality;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test
|
namespace NzbDrone.Core.Test
|
||||||
|
@ -112,8 +117,6 @@ namespace NzbDrone.Core.Test
|
||||||
provider.GetAllLogs().Should().HaveCount(1);
|
provider.GetAllLogs().Should().HaveCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void write_log_exception()
|
public void write_log_exception()
|
||||||
{
|
{
|
||||||
|
@ -182,10 +185,6 @@ namespace NzbDrone.Core.Test
|
||||||
ExceptionVerification.ExcpectedErrors(1);
|
ExceptionVerification.ExcpectedErrors(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void null_string_as_arg_should_not_fail()
|
public void null_string_as_arg_should_not_fail()
|
||||||
{
|
{
|
||||||
|
@ -198,5 +197,72 @@ namespace NzbDrone.Core.Test
|
||||||
epFile.Path.Should().BeNull();
|
epFile.Path.Should().BeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void top_logs()
|
||||||
|
{
|
||||||
|
//Setup
|
||||||
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||||
|
var db = MockLib.GetEmptyDatabase();
|
||||||
|
mocker.SetConstant(db);
|
||||||
|
|
||||||
|
var fakeLogs = Builder<Log>.CreateListOfSize(510)
|
||||||
|
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
db.InsertMany(fakeLogs);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var logs = mocker.Resolve<LogProvider>().TopLogs(500);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
logs.Should().HaveCount(501);
|
||||||
|
logs.Last().Message.Should().Be(
|
||||||
|
"Number of logs currently shown: 500. More may exist, check 'All' to see everything");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void top_logs_less_than_number_wanted()
|
||||||
|
{
|
||||||
|
//Setup
|
||||||
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||||
|
var db = MockLib.GetEmptyDatabase();
|
||||||
|
mocker.SetConstant(db);
|
||||||
|
|
||||||
|
var fakeLogs = Builder<Log>.CreateListOfSize(100)
|
||||||
|
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
db.InsertMany(fakeLogs);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var logs = mocker.Resolve<LogProvider>().TopLogs(500);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
logs.Should().HaveCount(101);
|
||||||
|
logs.Last().Message.Should().Be(
|
||||||
|
"Number of logs currently shown: 100. More may exist, check 'All' to see everything");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void pagedLogs()
|
||||||
|
{
|
||||||
|
//Setup
|
||||||
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||||
|
var db = MockLib.GetEmptyDatabase();
|
||||||
|
mocker.SetConstant(db);
|
||||||
|
|
||||||
|
var fakeLogs = Builder<Log>.CreateListOfSize(100)
|
||||||
|
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
db.InsertMany(fakeLogs);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var logs = mocker.Resolve<LogProvider>().GetPagedLogs(1, 50);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
logs.Items.Should().HaveCount(50);
|
||||||
|
logs.TotalItems.Should().Be(100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -22,15 +22,15 @@ namespace NzbDrone.Core.Instrumentation
|
||||||
return _database.Fetch<Log>();
|
return _database.Fetch<Log>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IList<Log> TopLogs()
|
public IList<Log> TopLogs(int count)
|
||||||
{
|
{
|
||||||
var logs = _database.Fetch<Log>("SELECT TOP 7500 * FROM Logs ORDER BY Time Desc");
|
var logs = _database.Fetch<Log>("SELECT TOP " + count + " * FROM Logs ORDER BY Time Desc");
|
||||||
logs.Add(new Log
|
logs.Add(new Log
|
||||||
{
|
{
|
||||||
Time = DateTime.Now.AddYears(-100),
|
Time = DateTime.Now.AddYears(-100),
|
||||||
Level = "Info",
|
Level = "Info",
|
||||||
Logger = "NzbDrone.Core.Instrumentation.LogProvider",
|
Logger = "Core.Instrumentation.LogProvider",
|
||||||
Message = String.Format("Number of logs currently shown: 7500. More may exist, check 'All' to see everything")
|
Message = String.Format("Number of logs currently shown: {0}. More may exist, check 'All' to see everything", Math.Min(count, logs.Count))
|
||||||
});
|
});
|
||||||
|
|
||||||
return logs;
|
return logs;
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace NzbDrone.Web.Controllers
|
||||||
[GridAction]
|
[GridAction]
|
||||||
public ActionResult _TopAjaxBinding()
|
public ActionResult _TopAjaxBinding()
|
||||||
{
|
{
|
||||||
var logs = _logProvider.TopLogs();
|
var logs = _logProvider.TopLogs(5000);
|
||||||
|
|
||||||
return View(new GridModel(logs));
|
return View(new GridModel(logs));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue