2023-11-10 16:44:04 +00:00
|
|
|
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;
|
2021-04-27 20:56:11 +00:00
|
|
|
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;
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Integration.Test
|
|
|
|
{
|
2020-08-17 21:18:47 +00:00
|
|
|
[Parallelizable(ParallelScope.Fixtures)]
|
2016-04-04 17:40:51 +00:00
|
|
|
public abstract class IntegrationTest : IntegrationTestBase
|
2013-04-22 03:18:08 +00:00
|
|
|
{
|
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
|
|
|
|
2016-04-04 17:40:51 +00:00
|
|
|
protected override void StartTestTarget()
|
2013-04-22 03:18:08 +00:00
|
|
|
{
|
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-04-22 03:18:08 +00:00
|
|
|
|
2013-08-14 03:22:28 +00:00
|
|
|
_runner.Start();
|
2016-04-04 17:40:51 +00:00
|
|
|
}
|
2014-04-19 15:09:22 +00:00
|
|
|
|
2016-04-04 17:40:51 +00:00
|
|
|
protected override void InitializeTestTarget()
|
|
|
|
{
|
2021-04-27 20:56:11 +00:00
|
|
|
// Make sure tasks have been initialized so the config put below doesn't cause errors
|
2023-11-10 16:44:04 +00:00
|
|
|
WaitForCompletion(() => Tasks.All().SelectList(x => x.TaskName).Contains("RssSync"), 30000);
|
2021-04-27 20:56:11 +00:00
|
|
|
|
2023-11-10 16:44:04 +00:00
|
|
|
var indexer = Indexers.Schema().FirstOrDefault(i => i.Implementation == nameof(Newznab));
|
|
|
|
|
|
|
|
if (indexer == null)
|
2014-04-19 15:09:22 +00:00
|
|
|
{
|
2023-11-10 16:44:04 +00:00
|
|
|
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);
|
2013-08-13 05:08:37 +00:00
|
|
|
}
|
2013-04-22 03:18:08 +00:00
|
|
|
|
2016-04-04 17:40:51 +00:00
|
|
|
protected override void StopTestTarget()
|
2013-04-22 03:18:08 +00:00
|
|
|
{
|
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);
|
2013-04-22 03:18:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|