feat(cli): Added Sonarr support for fetching host and security configs
This commit is contained in:
@@ -28,6 +28,10 @@ pub enum SonarrGetCommand {
|
||||
)]
|
||||
episode_id: i64,
|
||||
},
|
||||
#[command(about = "Fetch the host config for your Sonarr instance")]
|
||||
HostConfig,
|
||||
#[command(about = "Fetch the security config for your Sonarr instance")]
|
||||
SecurityConfig,
|
||||
#[command(about = "Get the system status")]
|
||||
SystemStatus,
|
||||
}
|
||||
@@ -62,6 +66,12 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrGetCommand> for SonarrGetCommandHan
|
||||
SonarrGetCommand::EpisodeDetails { episode_id } => {
|
||||
execute_network_event!(self, SonarrEvent::GetEpisodeDetails(Some(episode_id)));
|
||||
}
|
||||
SonarrGetCommand::HostConfig => {
|
||||
execute_network_event!(self, SonarrEvent::GetHostConfig);
|
||||
}
|
||||
SonarrGetCommand::SecurityConfig => {
|
||||
execute_network_event!(self, SonarrEvent::GetSecurityConfig);
|
||||
}
|
||||
SonarrGetCommand::SystemStatus => {
|
||||
execute_network_event!(self, SonarrEvent::GetStatus);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,22 @@ mod tests {
|
||||
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_host_config_has_no_arg_requirements() {
|
||||
let result =
|
||||
Cli::command().try_get_matches_from(["managarr", "sonarr", "get", "host-config"]);
|
||||
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_security_config_has_no_arg_requirements() {
|
||||
let result =
|
||||
Cli::command().try_get_matches_from(["managarr", "sonarr", "get", "security-config"]);
|
||||
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
mod handler {
|
||||
@@ -99,6 +115,52 @@ mod tests {
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_get_host_config_command() {
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
mock_network
|
||||
.expect_handle_network_event()
|
||||
.with(eq::<NetworkEvent>(SonarrEvent::GetHostConfig.into()))
|
||||
.times(1)
|
||||
.returning(|_| {
|
||||
Ok(Serdeable::Sonarr(SonarrSerdeable::Value(
|
||||
json!({"testResponse": "response"}),
|
||||
)))
|
||||
});
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
let get_host_config_command = SonarrGetCommand::HostConfig;
|
||||
|
||||
let result =
|
||||
SonarrGetCommandHandler::with(&app_arc, get_host_config_command, &mut mock_network)
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_get_security_config_command() {
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
mock_network
|
||||
.expect_handle_network_event()
|
||||
.with(eq::<NetworkEvent>(SonarrEvent::GetSecurityConfig.into()))
|
||||
.times(1)
|
||||
.returning(|_| {
|
||||
Ok(Serdeable::Sonarr(SonarrSerdeable::Value(
|
||||
json!({"testResponse": "response"}),
|
||||
)))
|
||||
});
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
let get_security_config_command = SonarrGetCommand::SecurityConfig;
|
||||
|
||||
let result =
|
||||
SonarrGetCommandHandler::with(&app_arc, get_security_config_command, &mut mock_network)
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_get_system_status_command() {
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
|
||||
@@ -117,8 +117,11 @@ pub struct IndexerField {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SecurityConfig {
|
||||
pub authentication_method: AuthenticationMethod,
|
||||
pub authentication_required: AuthenticationRequired,
|
||||
pub username: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub authentication_required: Option<AuthenticationRequired>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub username: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub password: Option<String>,
|
||||
pub api_key: String,
|
||||
pub certificate_validation: CertificateValidation,
|
||||
|
||||
@@ -964,7 +964,7 @@ mod test {
|
||||
async fn test_handle_get_sonarr_logs_event() {
|
||||
let expected_logs = vec![
|
||||
HorizontallyScrollableText::from(
|
||||
"2023-05-20 21:29:16 UTC|FATAL|RadarrError|Some.Big.Bad.Exception|test exception",
|
||||
"2023-05-20 21:29:16 UTC|FATAL|SonarrError|Some.Big.Bad.Exception|test exception",
|
||||
),
|
||||
HorizontallyScrollableText::from("2023-05-20 21:29:16 UTC|INFO|TestLogger|test message"),
|
||||
];
|
||||
@@ -985,7 +985,7 @@ mod test {
|
||||
{
|
||||
"time": "2023-05-20T21:29:16Z",
|
||||
"level": "fatal",
|
||||
"logger": "RadarrError",
|
||||
"logger": "SonarrError",
|
||||
"exception": "test exception",
|
||||
"exceptionType": "Some.Big.Bad.Exception",
|
||||
"id": 2
|
||||
@@ -1032,7 +1032,7 @@ mod test {
|
||||
async fn test_handle_get_sonarr_logs_event_uses_provided_events() {
|
||||
let expected_logs = vec![
|
||||
HorizontallyScrollableText::from(
|
||||
"2023-05-20 21:29:16 UTC|FATAL|RadarrError|Some.Big.Bad.Exception|test exception",
|
||||
"2023-05-20 21:29:16 UTC|FATAL|SonarrError|Some.Big.Bad.Exception|test exception",
|
||||
),
|
||||
HorizontallyScrollableText::from("2023-05-20 21:29:16 UTC|INFO|TestLogger|test message"),
|
||||
];
|
||||
@@ -1053,7 +1053,7 @@ mod test {
|
||||
{
|
||||
"time": "2023-05-20T21:29:16Z",
|
||||
"level": "fatal",
|
||||
"logger": "RadarrError",
|
||||
"logger": "SonarrError",
|
||||
"exception": "test exception",
|
||||
"exceptionType": "Some.Big.Bad.Exception",
|
||||
"id": 2
|
||||
|
||||
Reference in New Issue
Block a user