feat(cli): Support for testing all Sonarr indexers at once

This commit is contained in:
2024-11-22 17:38:11 -07:00
parent 6896fcc134
commit 8807adea83
3 changed files with 37 additions and 2 deletions
+2 -1
View File
@@ -116,7 +116,7 @@ pub enum RadarrCommand {
#[arg(long, help = "The ID of the indexer to test", required = true)]
indexer_id: i64,
},
#[command(about = "Test all indexers")]
#[command(about = "Test all Radarr indexers")]
TestAllIndexers,
#[command(about = "Trigger an automatic search for the movie with the specified ID")]
TriggerAutomaticSearch {
@@ -243,6 +243,7 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, RadarrCommand> for RadarrCliHandler<'a, '
serde_json::to_string_pretty(&resp)?
}
RadarrCommand::TestAllIndexers => {
println!("Testing all Radarr indexers. This may take a minute...");
let resp = self
.network
.handle_network_event(RadarrEvent::TestAllIndexers.into())
+10
View File
@@ -97,6 +97,8 @@ pub enum SonarrCommand {
#[arg(long, help = "The ID of the indexer to test", required = true)]
indexer_id: i64,
},
#[command(about = "Test all Radarr indexers")]
TestAllIndexers,
}
impl From<SonarrCommand> for Command {
@@ -199,6 +201,14 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrCommand> for SonarrCliHandler<'a, '
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrCommand::TestAllIndexers => {
println!("Testing all Sonarr indexers. This may take a minute...");
let resp = self
.network
.handle_network_event(SonarrEvent::TestAllIndexers.into())
.await?;
serde_json::to_string_pretty(&resp)?
}
};
Ok(result)
+25 -1
View File
@@ -22,7 +22,9 @@ mod tests {
use rstest::rstest;
#[rstest]
fn test_commands_that_have_no_arg_requirements(#[values("clear-blocklist")] subcommand: &str) {
fn test_commands_that_have_no_arg_requirements(
#[values("clear-blocklist", "test-all-indexers")] subcommand: &str,
) {
let result = Cli::command().try_get_matches_from(["managarr", "sonarr", subcommand]);
assert!(result.is_ok());
@@ -486,5 +488,27 @@ mod tests {
assert!(result.is_ok());
}
#[tokio::test]
async fn test_test_all_indexers_command() {
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(SonarrEvent::TestAllIndexers.into()))
.times(1)
.returning(|_| {
Ok(Serdeable::Sonarr(SonarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::default()));
let test_all_indexers_command = SonarrCommand::TestAllIndexers;
let result = SonarrCliHandler::with(&app_arc, test_all_indexers_command, &mut mock_network)
.handle()
.await;
assert!(result.is_ok());
}
}
}