Skip to content

Commit

Permalink
Fix settings being null and added debug output to test
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn committed Apr 12, 2020
1 parent c7ad86b commit 2307614
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/Configuratorr/IndexerMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public static int run(IndexMigratorOptions options)

var sonarrDbPath = Path.Combine(options.SonarrDirectory, "sonarr.db");
var radarrDbPath = Path.Combine(options.RadarrDirectory, "radarr.db");
MigrateIndexers(indexerNames, sonarrDbPath);
MigrateIndexers(indexerNames, radarrDbPath);
MigrateIndexers(indexerNames, sonarrDbPath, options);
MigrateIndexers(indexerNames, radarrDbPath, options);
return 0;
}

public static void MigrateIndexers(List<string> indexerNames, string dbPath)
public static void MigrateIndexers(List<string> indexerNames, string dbPath, IndexMigratorOptions options)
{
Console.WriteLine($"Started migration into ({dbPath})");
var connectionStringBuilder = new SqliteConnectionStringBuilder();
Expand All @@ -37,7 +37,7 @@ public static void MigrateIndexers(List<string> indexerNames, string dbPath)
+ $"VALUES(@Name, @Implementation, @Settings, @ConfigContract, @EnableRss, @EnableAS, @EnableIS);";
var cmd = connection.CreateCommand();
cmd.CommandText = commandText;
indexerNames.Select(name => new Indexer { Name = name }).ToList()
indexerNames.Select(name => IndexerFactory.Create(name, options)).ToList()
.ForEach(InsertIndexer(cmd));

transaction.Commit();
Expand Down
3 changes: 2 additions & 1 deletion src/Configuratorr/Model/Indexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ namespace Configuratorr.Model
public class Indexer
{
public string Name { get; set; }
public IndexerSettings Settings { get; set; }
public IndexerSettings Settings { get; set; } = new IndexerSettings();
public string Implementation { get; set; } = "Torznab";
public string ConfigContract { get; set; } = "TorznabSettings";
public int EnableRss { get; set; } = 1;
public int EnableAutomaticSearch { get; set; } = 1;
public int EnableInteractiveSearch { get; set; } = 1;


}

Expand Down
19 changes: 19 additions & 0 deletions src/Configuratorr/Model/IndexerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Configuratorr.Options;

namespace Configuratorr.Model
{
public static class IndexerFactory
{
public static Indexer Create(string name, IndexMigratorOptions options) {
var settings = new IndexerSettings{
baseUrl = $"http://{options.jackettURL}/api/v2.O/indexers/{name}/results/torznab/",
apiKey = options.ApiKey
};

return new Indexer{
Name = name,
Settings = settings
};
}
}
}
12 changes: 6 additions & 6 deletions src/Configuratorr/Model/IndexerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ namespace Configuratorr.Model
{
public class IndexerSettings
{
public int MinimumSeeders { get; set; } = 1;
public int minimumSeeders { get; set; } = 1;
public object seedCriteria { get; set; } = new object();
public string BaseUrl { get; set; }
public string ApiPath { get; set; } = "/api";
public string ApiKey { get; set; }
public int[] Categories { get; set; } = {5030, 5040};
public int[] AnimeCategories { get; set; } = {};
public string baseUrl { get; set; }
public string apiPath { get; set; } = "/api";
public string apiKey { get; set; }
public int[] categories { get; set; } = {5030, 5040};
public int[] animeCategories { get; set; } = {};
}
}
3 changes: 3 additions & 0 deletions src/Configuratorr/Options/IndexMigratorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ public class IndexMigratorOptions
public string SonarrDirectory { get; set; }
[Option("radarr", Required = true, HelpText = "Radarr configuration directory")]
public string RadarrDirectory { get; set; }

[Option("jackettURL", Required = false, HelpText = "Jackett base URL default: localhost:9117", Default = "localhost:9117")]
public string jackettURL { get; set; }
}
}
26 changes: 25 additions & 1 deletion test/ConfiguratorrTests/IndexerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Moq;
using Xunit;
using Microsoft.Data.Sqlite;
using Configuratorr.Model;

namespace ConfiguratorrTests
{
Expand Down Expand Up @@ -41,7 +42,12 @@ private static void TestMigration(string dbFile)
var indexers = IndexerPlugin.GetIndexerNamesFromPath(jackettPath);
var tempDb = Path.GetTempPath() + Guid.NewGuid().ToString() + ".db";
File.Copy(dbFile, tempDb);
IndexerMigrator.MigrateIndexers(indexers, tempDb);
var options = new Configuratorr.Options.IndexMigratorOptions
{
ApiKey = Guid.NewGuid().ToString(),
jackettURL = "localhost:9117"
};
IndexerMigrator.MigrateIndexers(indexers, tempDb, options);
var connectionStringBuilder = new SqliteConnectionStringBuilder();
connectionStringBuilder.DataSource = tempDb;

Expand All @@ -59,6 +65,24 @@ private static void TestMigration(string dbFile)
Assert.Equal(6, count);
}
}

selectCmd.CommandText = "SELECT * FROM Indexers;";
using (var reader =selectCmd.ExecuteReader())
{
while (reader.Read()) {
for (int i = 0; i < reader.FieldCount; i++)
{
string value = reader.GetValue(i).ToString();
Assert.NotEqual("null", value);
if (i == 3) {
var settings = Newtonsoft.Json.JsonConvert.DeserializeObject<IndexerSettings>(value);
Assert.Equal(options.ApiKey, settings.apiKey);
Assert.Contains(options.jackettURL, settings.baseUrl);
Assert.Contains(reader.GetValue(1).ToString(), settings.baseUrl);
}
}
}
}
}

File.Delete(tempDb);
Expand Down

0 comments on commit 2307614

Please sign in to comment.