Add ReadarrEvent::GetStatus, mapped to GET /system/status, and get_readarr_status in the new readarr_network/system module. It stores the version and start time on ReadarrData so the system view and the tick refresh can read them. Surface it as `managarr readarr get system-status`, matching the Radarr, Sonarr, and Lidarr spelling of the same call. A `list status` spelling would have made the same command a different verb on the fourth servarr, which is a difference the user would have to remember for no benefit. Readarr instances answer /system/status with thirty keys; SystemStatus models the two that are used and serde ignores the rest, as it does for the other three servarrs. This is the first ReadarrCommand variant, so ReadarrCliHandler now reads its app and network fields.
73 lines
1.9 KiB
Rust
73 lines
1.9 KiB
Rust
#[cfg(test)]
|
|
mod tests {
|
|
use crate::Cli;
|
|
use crate::cli::{
|
|
Command,
|
|
readarr::{ReadarrCommand, get_command_handler::ReadarrGetCommand},
|
|
};
|
|
use clap::CommandFactory;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn test_readarr_get_command_from() {
|
|
let command = ReadarrGetCommand::SystemStatus;
|
|
|
|
let result = Command::from(command.clone());
|
|
|
|
assert_eq!(result, Command::Readarr(ReadarrCommand::Get(command)));
|
|
}
|
|
|
|
mod cli {
|
|
use super::*;
|
|
use rstest::rstest;
|
|
|
|
#[rstest]
|
|
fn test_get_commands_have_no_arg_requirements(#[values("system-status")] subcommand: &str) {
|
|
let result = Cli::command().try_get_matches_from(["managarr", "readarr", "get", subcommand]);
|
|
|
|
assert_ok!(&result);
|
|
}
|
|
}
|
|
|
|
mod handler {
|
|
use std::sync::Arc;
|
|
|
|
use mockall::predicate::eq;
|
|
use serde_json::json;
|
|
use tokio::sync::Mutex;
|
|
|
|
use crate::{
|
|
app::App,
|
|
cli::{
|
|
CliCommandHandler,
|
|
readarr::get_command_handler::{ReadarrGetCommand, ReadarrGetCommandHandler},
|
|
},
|
|
models::{Serdeable, readarr_models::ReadarrSerdeable},
|
|
network::{MockNetworkTrait, NetworkEvent, readarr_network::ReadarrEvent},
|
|
};
|
|
|
|
#[tokio::test]
|
|
async fn test_handle_get_system_status_command() {
|
|
let mut mock_network = MockNetworkTrait::new();
|
|
mock_network
|
|
.expect_handle_network_event()
|
|
.with(eq::<NetworkEvent>(ReadarrEvent::GetStatus.into()))
|
|
.times(1)
|
|
.returning(|_| {
|
|
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
|
|
json!({"testResponse": "response"}),
|
|
)))
|
|
});
|
|
let app_arc = Arc::new(Mutex::new(App::test_default()));
|
|
let get_system_status_command = ReadarrGetCommand::SystemStatus;
|
|
|
|
let result =
|
|
ReadarrGetCommandHandler::with(&app_arc, get_system_status_command, &mut mock_network)
|
|
.handle()
|
|
.await;
|
|
|
|
assert_ok!(&result);
|
|
}
|
|
}
|
|
}
|