refactor: Removed the filtering of monitored_storage_paths from the networking module and migrated all of it to the UI
This commit is contained in:
@@ -2,7 +2,6 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Subcommand, arg};
|
use clap::{Subcommand, arg};
|
||||||
use indoc::formatdoc;
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
@@ -60,10 +59,7 @@ pub enum LidarrListCommand {
|
|||||||
Artists,
|
Artists,
|
||||||
#[command(about = "List all items in the Lidarr blocklist")]
|
#[command(about = "List all items in the Lidarr blocklist")]
|
||||||
Blocklist,
|
Blocklist,
|
||||||
#[command(about = formatdoc!(
|
#[command(about = "List disk space details for all provisioned root folders in Lidarr")]
|
||||||
"List disk space details for all provisioned root folders in Lidarr
|
|
||||||
(returns unfiltered response; i.e. ignores 'monitored_storage_paths' config field)")
|
|
||||||
)]
|
|
||||||
DiskSpace,
|
DiskSpace,
|
||||||
#[command(about = "List all active downloads in Lidarr")]
|
#[command(about = "List all active downloads in Lidarr")]
|
||||||
Downloads {
|
Downloads {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Subcommand, command};
|
use clap::{Subcommand, command};
|
||||||
use indoc::formatdoc;
|
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -28,10 +27,7 @@ pub enum RadarrListCommand {
|
|||||||
#[arg(long, help = "How many downloads to fetch", default_value_t = 500)]
|
#[arg(long, help = "How many downloads to fetch", default_value_t = 500)]
|
||||||
count: u64,
|
count: u64,
|
||||||
},
|
},
|
||||||
#[command(about = formatdoc!(
|
#[command(about = "List disk space details for all provisioned root folders in Radarr")]
|
||||||
"List disk space details for all provisioned root folders in Radarr
|
|
||||||
(returns unfiltered response; i.e. ignores 'monitored_storage_paths' config field)")
|
|
||||||
)]
|
|
||||||
DiskSpace,
|
DiskSpace,
|
||||||
#[command(about = "Fetch all Radarr history events")]
|
#[command(about = "Fetch all Radarr history events")]
|
||||||
History {
|
History {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use indoc::formatdoc;
|
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -26,10 +25,7 @@ pub enum SonarrListCommand {
|
|||||||
#[arg(long, help = "How many downloads to fetch", default_value_t = 500)]
|
#[arg(long, help = "How many downloads to fetch", default_value_t = 500)]
|
||||||
count: u64,
|
count: u64,
|
||||||
},
|
},
|
||||||
#[command(about = formatdoc!(
|
#[command(about = "List disk space details for all provisioned root folders in Sonarr")]
|
||||||
"List disk space details for all provisioned root folders in Sonarr
|
|
||||||
(returns unfiltered response; i.e. ignores 'monitored_storage_paths' config field)")
|
|
||||||
)]
|
|
||||||
DiskSpace,
|
DiskSpace,
|
||||||
#[command(about = "List the episodes for the series with the given ID")]
|
#[command(about = "List the episodes for the series with the given ID")]
|
||||||
Episodes {
|
Episodes {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::app::{App, ServarrConfig};
|
|
||||||
use crate::models::HorizontallyScrollableText;
|
use crate::models::HorizontallyScrollableText;
|
||||||
use crate::models::lidarr_models::{LidarrSerdeable, LidarrTask, LidarrTaskName, SystemStatus};
|
use crate::models::lidarr_models::{LidarrSerdeable, LidarrTask, LidarrTaskName, SystemStatus};
|
||||||
use crate::models::servarr_models::{
|
use crate::models::servarr_models::{
|
||||||
@@ -12,8 +11,6 @@ mod tests {
|
|||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::sync::Mutex;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_handle_get_diskspace_event() {
|
async fn test_handle_get_diskspace_event() {
|
||||||
@@ -35,11 +32,6 @@ mod tests {
|
|||||||
.await;
|
.await;
|
||||||
app.lock().await.server_tabs.set_index(2);
|
app.lock().await.server_tabs.set_index(2);
|
||||||
let mut network = test_network(&app);
|
let mut network = test_network(&app);
|
||||||
let filtered_disk_space_vec = vec![DiskSpace {
|
|
||||||
path: Some("/path1".to_owned()),
|
|
||||||
free_space: 1111,
|
|
||||||
total_space: 2222,
|
|
||||||
}];
|
|
||||||
let disk_space_vec = vec![
|
let disk_space_vec = vec![
|
||||||
DiskSpace {
|
DiskSpace {
|
||||||
path: Some("/path1".to_owned()),
|
path: Some("/path1".to_owned()),
|
||||||
@@ -63,69 +55,9 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
app.lock().await.data.lidarr_data.disk_space_vec,
|
app.lock().await.data.lidarr_data.disk_space_vec,
|
||||||
filtered_disk_space_vec
|
|
||||||
);
|
|
||||||
assert_eq!(disk_spaces, disk_space_vec);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_handle_get_lidarr_diskspace_event_populates_data_with_all_storage_when_monitored_storage_paths_is_empty()
|
|
||||||
{
|
|
||||||
let (mock, base_app, _server) = MockServarrApi::get()
|
|
||||||
.returns(json!([
|
|
||||||
{
|
|
||||||
"path": "/path1",
|
|
||||||
"freeSpace": 1111,
|
|
||||||
"totalSpace": 2222,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/path2",
|
|
||||||
"freeSpace": 3333,
|
|
||||||
"totalSpace": 4444
|
|
||||||
}
|
|
||||||
]))
|
|
||||||
.build_for(LidarrEvent::GetDiskSpace)
|
|
||||||
.await;
|
|
||||||
let mut app = App::test_default();
|
|
||||||
let servarr_config = ServarrConfig {
|
|
||||||
monitored_storage_paths: Some(vec![]),
|
|
||||||
..base_app.lock().await.server_tabs.tabs[2]
|
|
||||||
.config
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.clone()
|
|
||||||
};
|
|
||||||
app.server_tabs.tabs[2].config = Some(servarr_config);
|
|
||||||
app.server_tabs.set_index(2);
|
|
||||||
let app_arc = Arc::new(Mutex::new(app));
|
|
||||||
|
|
||||||
let mut network = test_network(&app_arc);
|
|
||||||
let disk_space_vec = vec![
|
|
||||||
DiskSpace {
|
|
||||||
path: Some("/path1".to_owned()),
|
|
||||||
free_space: 1111,
|
|
||||||
total_space: 2222,
|
|
||||||
},
|
|
||||||
DiskSpace {
|
|
||||||
path: Some("/path2".to_owned()),
|
|
||||||
free_space: 3333,
|
|
||||||
total_space: 4444,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
let LidarrSerdeable::DiskSpaces(disk_space) = network
|
|
||||||
.handle_lidarr_event(LidarrEvent::GetDiskSpace)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
else {
|
|
||||||
panic!("Expected DiskSpaces")
|
|
||||||
};
|
|
||||||
mock.assert_async().await;
|
|
||||||
assert_eq!(
|
|
||||||
app_arc.lock().await.data.lidarr_data.disk_space_vec,
|
|
||||||
disk_space_vec
|
disk_space_vec
|
||||||
);
|
);
|
||||||
assert_eq!(disk_space, disk_space_vec);
|
assert_eq!(disk_spaces, disk_space_vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
@@ -101,28 +101,7 @@ impl Network<'_, '_> {
|
|||||||
|
|
||||||
self
|
self
|
||||||
.handle_request::<(), Vec<DiskSpace>>(request_props, |disk_space_vec, mut app| {
|
.handle_request::<(), Vec<DiskSpace>>(request_props, |disk_space_vec, mut app| {
|
||||||
if let Some(paths) = app
|
|
||||||
.server_tabs
|
|
||||||
.get_active_config()
|
|
||||||
.as_ref()
|
|
||||||
.expect("Servarr config is undefined")
|
|
||||||
.monitored_storage_paths
|
|
||||||
.as_ref()
|
|
||||||
&& !paths.is_empty()
|
|
||||||
{
|
|
||||||
app.data.lidarr_data.disk_space_vec = disk_space_vec
|
|
||||||
.into_iter()
|
|
||||||
.filter(|it| {
|
|
||||||
if let Some(path) = it.path.as_ref() {
|
|
||||||
paths.contains(path)
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
} else {
|
|
||||||
app.data.lidarr_data.disk_space_vec = disk_space_vec;
|
app.data.lidarr_data.disk_space_vec = disk_space_vec;
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,28 +27,7 @@ impl Network<'_, '_> {
|
|||||||
|
|
||||||
self
|
self
|
||||||
.handle_request::<(), Vec<DiskSpace>>(request_props, |disk_space_vec, mut app| {
|
.handle_request::<(), Vec<DiskSpace>>(request_props, |disk_space_vec, mut app| {
|
||||||
if let Some(paths) = app
|
|
||||||
.server_tabs
|
|
||||||
.get_active_config()
|
|
||||||
.as_ref()
|
|
||||||
.expect("Servarr config is undefined")
|
|
||||||
.monitored_storage_paths
|
|
||||||
.as_ref()
|
|
||||||
&& !paths.is_empty()
|
|
||||||
{
|
|
||||||
app.data.radarr_data.disk_space_vec = disk_space_vec
|
|
||||||
.into_iter()
|
|
||||||
.filter(|it| {
|
|
||||||
if let Some(path) = it.path.as_ref() {
|
|
||||||
paths.contains(path)
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
} else {
|
|
||||||
app.data.radarr_data.disk_space_vec = disk_space_vec;
|
app.data.radarr_data.disk_space_vec = disk_space_vec;
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::app::{App, ServarrConfig};
|
|
||||||
use crate::models::HorizontallyScrollableText;
|
use crate::models::HorizontallyScrollableText;
|
||||||
use crate::models::radarr_models::{RadarrSerdeable, RadarrTask, RadarrTaskName, SystemStatus};
|
use crate::models::radarr_models::{RadarrSerdeable, RadarrTask, RadarrTaskName, SystemStatus};
|
||||||
use crate::models::servarr_models::{
|
use crate::models::servarr_models::{
|
||||||
@@ -12,8 +11,6 @@ mod tests {
|
|||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::sync::Mutex;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_handle_get_radarr_diskspace_event() {
|
async fn test_handle_get_radarr_diskspace_event() {
|
||||||
@@ -33,11 +30,6 @@ mod tests {
|
|||||||
.build_for(RadarrEvent::GetDiskSpace)
|
.build_for(RadarrEvent::GetDiskSpace)
|
||||||
.await;
|
.await;
|
||||||
let mut network = test_network(&app);
|
let mut network = test_network(&app);
|
||||||
let filtered_disk_space_vec = vec![DiskSpace {
|
|
||||||
path: Some("/path1".to_owned()),
|
|
||||||
free_space: 1111,
|
|
||||||
total_space: 2222,
|
|
||||||
}];
|
|
||||||
let disk_space_vec = vec![
|
let disk_space_vec = vec![
|
||||||
DiskSpace {
|
DiskSpace {
|
||||||
path: Some("/path1".to_owned()),
|
path: Some("/path1".to_owned()),
|
||||||
@@ -61,65 +53,6 @@ mod tests {
|
|||||||
mock.assert_async().await;
|
mock.assert_async().await;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
app.lock().await.data.radarr_data.disk_space_vec,
|
app.lock().await.data.radarr_data.disk_space_vec,
|
||||||
filtered_disk_space_vec
|
|
||||||
);
|
|
||||||
assert_eq!(disk_space, disk_space_vec);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_handle_get_radarr_diskspace_event_populates_data_with_all_storage_when_monitored_storage_paths_is_empty()
|
|
||||||
{
|
|
||||||
let (mock, base_app, _server) = MockServarrApi::get()
|
|
||||||
.returns(json!([
|
|
||||||
{
|
|
||||||
"path": "/path1",
|
|
||||||
"freeSpace": 1111,
|
|
||||||
"totalSpace": 2222,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/path2",
|
|
||||||
"freeSpace": 3333,
|
|
||||||
"totalSpace": 4444
|
|
||||||
}
|
|
||||||
]))
|
|
||||||
.build_for(RadarrEvent::GetDiskSpace)
|
|
||||||
.await;
|
|
||||||
let mut app = App::test_default();
|
|
||||||
let servarr_config = ServarrConfig {
|
|
||||||
monitored_storage_paths: Some(vec![]),
|
|
||||||
..base_app.lock().await.server_tabs.tabs[0]
|
|
||||||
.config
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.clone()
|
|
||||||
};
|
|
||||||
app.server_tabs.tabs[0].config = Some(servarr_config);
|
|
||||||
let app_arc = Arc::new(Mutex::new(app));
|
|
||||||
|
|
||||||
let mut network = test_network(&app_arc);
|
|
||||||
let disk_space_vec = vec![
|
|
||||||
DiskSpace {
|
|
||||||
path: Some("/path1".to_owned()),
|
|
||||||
free_space: 1111,
|
|
||||||
total_space: 2222,
|
|
||||||
},
|
|
||||||
DiskSpace {
|
|
||||||
path: Some("/path2".to_owned()),
|
|
||||||
free_space: 3333,
|
|
||||||
total_space: 4444,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
let RadarrSerdeable::DiskSpaces(disk_space) = network
|
|
||||||
.handle_radarr_event(RadarrEvent::GetDiskSpace)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
else {
|
|
||||||
panic!("Expected DiskSpaces")
|
|
||||||
};
|
|
||||||
mock.assert_async().await;
|
|
||||||
assert_eq!(
|
|
||||||
app_arc.lock().await.data.radarr_data.disk_space_vec,
|
|
||||||
disk_space_vec
|
disk_space_vec
|
||||||
);
|
);
|
||||||
assert_eq!(disk_space, disk_space_vec);
|
assert_eq!(disk_space, disk_space_vec);
|
||||||
|
|||||||
@@ -101,28 +101,7 @@ impl Network<'_, '_> {
|
|||||||
|
|
||||||
self
|
self
|
||||||
.handle_request::<(), Vec<DiskSpace>>(request_props, |disk_space_vec, mut app| {
|
.handle_request::<(), Vec<DiskSpace>>(request_props, |disk_space_vec, mut app| {
|
||||||
if let Some(paths) = app
|
|
||||||
.server_tabs
|
|
||||||
.get_active_config()
|
|
||||||
.as_ref()
|
|
||||||
.expect("Servarr config is undefined")
|
|
||||||
.monitored_storage_paths
|
|
||||||
.as_ref()
|
|
||||||
&& !paths.is_empty()
|
|
||||||
{
|
|
||||||
app.data.sonarr_data.disk_space_vec = disk_space_vec
|
|
||||||
.into_iter()
|
|
||||||
.filter(|it| {
|
|
||||||
if let Some(path) = it.path.as_ref() {
|
|
||||||
paths.contains(path)
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
} else {
|
|
||||||
app.data.sonarr_data.disk_space_vec = disk_space_vec;
|
app.data.sonarr_data.disk_space_vec = disk_space_vec;
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::app::{App, ServarrConfig};
|
|
||||||
use crate::models::HorizontallyScrollableText;
|
use crate::models::HorizontallyScrollableText;
|
||||||
use crate::models::servarr_models::{
|
use crate::models::servarr_models::{
|
||||||
DiskSpace, HostConfig, LogResponse, QueueEvent, SecurityConfig, Update,
|
DiskSpace, HostConfig, LogResponse, QueueEvent, SecurityConfig, Update,
|
||||||
@@ -12,8 +11,6 @@ mod tests {
|
|||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::sync::Mutex;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_handle_get_sonarr_host_config_event() {
|
async fn test_handle_get_sonarr_host_config_event() {
|
||||||
@@ -130,11 +127,6 @@ mod tests {
|
|||||||
.await;
|
.await;
|
||||||
app.lock().await.server_tabs.next();
|
app.lock().await.server_tabs.next();
|
||||||
let mut network = test_network(&app);
|
let mut network = test_network(&app);
|
||||||
let filtered_disk_space_vec = vec![DiskSpace {
|
|
||||||
path: Some("/path1".to_owned()),
|
|
||||||
free_space: 1111,
|
|
||||||
total_space: 2222,
|
|
||||||
}];
|
|
||||||
let disk_space_vec = vec![
|
let disk_space_vec = vec![
|
||||||
DiskSpace {
|
DiskSpace {
|
||||||
path: Some("/path1".to_owned()),
|
path: Some("/path1".to_owned()),
|
||||||
@@ -158,66 +150,6 @@ mod tests {
|
|||||||
mock.assert_async().await;
|
mock.assert_async().await;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
app.lock().await.data.sonarr_data.disk_space_vec,
|
app.lock().await.data.sonarr_data.disk_space_vec,
|
||||||
filtered_disk_space_vec
|
|
||||||
);
|
|
||||||
assert_eq!(disk_space, disk_space_vec);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_handle_get_sonarr_diskspace_event_populates_data_with_all_storage_when_monitored_storage_paths_is_empty()
|
|
||||||
{
|
|
||||||
let (mock, base_app, _server) = MockServarrApi::get()
|
|
||||||
.returns(json!([
|
|
||||||
{
|
|
||||||
"path": "/path1",
|
|
||||||
"freeSpace": 1111,
|
|
||||||
"totalSpace": 2222,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/path2",
|
|
||||||
"freeSpace": 3333,
|
|
||||||
"totalSpace": 4444
|
|
||||||
}
|
|
||||||
]))
|
|
||||||
.build_for(SonarrEvent::GetDiskSpace)
|
|
||||||
.await;
|
|
||||||
let mut app = App::test_default();
|
|
||||||
let servarr_config = ServarrConfig {
|
|
||||||
monitored_storage_paths: Some(vec![]),
|
|
||||||
..base_app.lock().await.server_tabs.tabs[1]
|
|
||||||
.config
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.clone()
|
|
||||||
};
|
|
||||||
app.server_tabs.tabs[1].config = Some(servarr_config);
|
|
||||||
app.server_tabs.next();
|
|
||||||
let app_arc = Arc::new(Mutex::new(app));
|
|
||||||
|
|
||||||
let mut network = test_network(&app_arc);
|
|
||||||
let disk_space_vec = vec![
|
|
||||||
DiskSpace {
|
|
||||||
path: Some("/path1".to_owned()),
|
|
||||||
free_space: 1111,
|
|
||||||
total_space: 2222,
|
|
||||||
},
|
|
||||||
DiskSpace {
|
|
||||||
path: Some("/path2".to_owned()),
|
|
||||||
free_space: 3333,
|
|
||||||
total_space: 4444,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
let SonarrSerdeable::DiskSpaces(disk_space) = network
|
|
||||||
.handle_sonarr_event(SonarrEvent::GetDiskSpace)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
else {
|
|
||||||
panic!("Expected DiskSpaces")
|
|
||||||
};
|
|
||||||
mock.assert_async().await;
|
|
||||||
assert_eq!(
|
|
||||||
app_arc.lock().await.data.sonarr_data.disk_space_vec,
|
|
||||||
disk_space_vec
|
disk_space_vec
|
||||||
);
|
);
|
||||||
assert_eq!(disk_space, disk_space_vec);
|
assert_eq!(disk_space, disk_space_vec);
|
||||||
|
|||||||
Reference in New Issue
Block a user