feat(readarr): test all indexers and expose the command on the CLI
Results come back keyed only by indexer id, so each one is joined against the cached indexer list to recover a display name, and its validation failures are flattened into a single line for the results table. The endpoint reports failures with a non-2xx status, so the request ignores the status code and parses the body either way. When the request itself fails the results table is replaced with an empty one rather than being left showing the previous run.
This commit is contained in:
7 files changed
+245
-6
No files matched your search
@@ -110,6 +110,8 @@ pub enum ReadarrCommand {
|
||||
)]
|
||||
task_name: ReadarrTaskName,
|
||||
},
|
||||
#[command(about = "Test all Readarr indexers")]
|
||||
TestAllIndexers,
|
||||
#[command(
|
||||
about = "Test the indexer with the given ID. Note that a successful test returns an empty JSON body; i.e. '{}'"
|
||||
)]
|
||||
@@ -247,6 +249,14 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrCommand> for ReadarrCliHandler<'a,
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
ReadarrCommand::TestAllIndexers => {
|
||||
println!("Testing all Readarr indexers. This may take a minute...");
|
||||
let resp = self
|
||||
.network
|
||||
.handle_network_event(ReadarrEvent::TestAllIndexers.into())
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
ReadarrCommand::TestIndexer { indexer_id } => {
|
||||
let resp = self
|
||||
.network
|
||||
|
||||
@@ -4,6 +4,7 @@ mod tests {
|
||||
use clap::CommandFactory;
|
||||
use clap::error::ErrorKind;
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::Cli;
|
||||
|
||||
@@ -212,9 +213,11 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_clear_blocklist_has_no_arg_requirements() {
|
||||
let result = Cli::command().try_get_matches_from(["managarr", "readarr", "clear-blocklist"]);
|
||||
#[rstest]
|
||||
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", "readarr", subcommand]);
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
@@ -395,6 +398,28 @@ mod tests {
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_test_all_indexers_command() {
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
mock_network
|
||||
.expect_handle_network_event()
|
||||
.with(eq::<NetworkEvent>(ReadarrEvent::TestAllIndexers.into()))
|
||||
.times(1)
|
||||
.returning(|_| {
|
||||
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
|
||||
json!({"testResponse": "response"}),
|
||||
)))
|
||||
});
|
||||
let app_arc = Arc::new(Mutex::new(App::test_default()));
|
||||
let test_all_indexers_command = ReadarrCommand::TestAllIndexers;
|
||||
|
||||
let result = ReadarrCliHandler::with(&app_arc, test_all_indexers_command, &mut mock_network)
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_toggle_author_monitoring_command() {
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
|
||||
Reference in new issue
Block a user