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

96 lines
3.1 KiB
C#
Raw Normal View History

2022-03-28 20:46:21 +00:00
using System.Collections.Generic;
2020-08-17 21:18:47 +00:00
using System.Threading;
2022-03-28 20:46:21 +00:00
using Microsoft.Extensions.Configuration;
2013-11-13 20:08:37 +00:00
using NLog;
2022-03-28 20:46:21 +00:00
using Npgsql;
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;
2018-11-23 07:03:32 +00:00
using Radarr.Http.ClientSchema;
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"));
Indexers.Post(new Radarr.Api.V3.Indexers.IndexerResource
{
2018-02-13 18:10:49 +00:00
EnableRss = false,
EnableInteractiveSearch = false,
EnableAutomaticSearch = false,
2018-02-13 18:10:49 +00:00
ConfigContract = nameof(NewznabSettings),
Implementation = nameof(Newznab),
Name = "NewznabTest",
Protocol = Core.Indexers.DownloadProtocol.Usenet,
2018-11-23 07:03:32 +00:00
Fields = SchemaBuilder.ToSchema(new NewznabSettings())
});
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);
}
}
}