Radarr/src/NzbDrone.Integration.Test/IntegrationTest.cs

97 lines
3.1 KiB
C#
Raw Permalink Normal View History

using System;
using System.Linq;
2020-08-17 21:18:47 +00:00
using System.Threading;
2013-11-13 20:08:37 +00:00
using NLog;
2020-08-17 21:18:47 +00:00
using NUnit.Framework;
using NzbDrone.Common.Extensions;
2022-03-28 20:46:21 +00:00
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Datastore.Migration.Framework;
2018-02-13 18:10:49 +00:00
using NzbDrone.Core.Indexers.Newznab;
2013-11-12 03:25:54 +00:00
using NzbDrone.Test.Common;
2022-03-28 20:46:21 +00:00
using NzbDrone.Test.Common.Datastore;
namespace NzbDrone.Integration.Test
{
2020-08-17 21:18:47 +00:00
[Parallelizable(ParallelScope.Fixtures)]
public abstract class IntegrationTest : IntegrationTestBase
{
2020-08-17 21:18:47 +00:00
protected static int StaticPort = 7878;
2016-07-31 21:40:07 +00:00
protected NzbDroneRunner _runner;
2013-11-13 20:08:37 +00:00
2018-02-13 18:10:49 +00:00
public override string MovieRootFolder => GetTempDirectory("MovieRootFolder");
2013-08-14 03:22:28 +00:00
2020-08-17 21:18:47 +00:00
protected int Port { get; private set; }
2022-03-28 20:46:21 +00:00
protected PostgresOptions PostgresOptions { get; set; } = new ();
2020-08-17 21:18:47 +00:00
protected override string RootUrl => $"http://localhost:{Port}/";
2013-08-14 05:02:25 +00:00
2016-12-09 06:54:15 +00:00
protected override string ApiKey => _runner.ApiKey;
2013-08-14 05:02:25 +00:00
protected override void StartTestTarget()
{
2020-08-17 21:18:47 +00:00
Port = Interlocked.Increment(ref StaticPort);
2022-03-28 20:46:21 +00:00
PostgresOptions = PostgresDatabase.GetTestOptions();
if (PostgresOptions?.Host != null)
{
CreatePostgresDb(PostgresOptions);
}
_runner = new NzbDroneRunner(LogManager.GetCurrentClassLogger(), PostgresOptions, Port);
2020-08-17 21:18:47 +00:00
_runner.Kill();
2013-08-14 03:22:28 +00:00
_runner.Start();
}
protected override void InitializeTestTarget()
{
// Make sure tasks have been initialized so the config put below doesn't cause errors
WaitForCompletion(() => Tasks.All().SelectList(x => x.TaskName).Contains("RssSync"), 30000);
var indexer = Indexers.Schema().FirstOrDefault(i => i.Implementation == nameof(Newznab));
if (indexer == null)
{
throw new NullReferenceException("Expected valid indexer schema, found null");
}
indexer.EnableRss = false;
indexer.EnableInteractiveSearch = false;
indexer.EnableAutomaticSearch = false;
indexer.ConfigContract = nameof(NewznabSettings);
indexer.Implementation = nameof(Newznab);
indexer.Name = "NewznabTest";
indexer.Protocol = Core.Indexers.DownloadProtocol.Usenet;
2019-07-15 01:18:03 +00:00
// Change Console Log Level to Debug so we get more details.
var config = HostConfig.Get(1);
config.ConsoleLogLevel = "Debug";
HostConfig.Put(config);
}
protected override void StopTestTarget()
{
2020-08-17 21:18:47 +00:00
_runner.Kill();
2022-03-28 20:46:21 +00:00
if (PostgresOptions?.Host != null)
{
DropPostgresDb(PostgresOptions);
}
}
private static void CreatePostgresDb(PostgresOptions options)
{
PostgresDatabase.Create(options, MigrationType.Main);
PostgresDatabase.Create(options, MigrationType.Log);
}
private static void DropPostgresDb(PostgresOptions options)
{
PostgresDatabase.Drop(options, MigrationType.Main);
PostgresDatabase.Drop(options, MigrationType.Log);
}
}
}