From 606ea43b51d6678f19deb11037716fef55b601a5 Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Gill-Couture Date: Fri, 11 Apr 2025 11:01:05 -0400 Subject: [PATCH] fix: improve tests and remove unused code - Corrected XML test data to remove unnecessary `` tags, resolving failing tests. - Removed the unused `ratatui_utils` module and its associated code. - Simplified example in `harmony_tui/src/lib.rs` to use `tokio::main` and register scores directly with `Maestro`. This aligns with the project's evolving structure. --- examples/tui/src/main.rs | 5 +--- harmony_tui/src/lib.rs | 32 ++++++++++++++-------- harmony_tui/src/ratatui_utils.rs | 22 --------------- opnsense-config-xml/src/data/interfaces.rs | 4 --- 4 files changed, 21 insertions(+), 42 deletions(-) delete mode 100644 harmony_tui/src/ratatui_utils.rs diff --git a/examples/tui/src/main.rs b/examples/tui/src/main.rs index 9623fa2..05a768b 100644 --- a/examples/tui/src/main.rs +++ b/examples/tui/src/main.rs @@ -1,10 +1,7 @@ use harmony::{ inventory::Inventory, maestro::Maestro, - modules::{ - dummy::{ErrorScore, PanicScore, SuccessScore}, - k8s::deployment::K8sDeploymentScore, - }, + modules::dummy::{ErrorScore, PanicScore, SuccessScore}, topology::HAClusterTopology, }; diff --git a/harmony_tui/src/lib.rs b/harmony_tui/src/lib.rs index 10997ad..11208f0 100644 --- a/harmony_tui/src/lib.rs +++ b/harmony_tui/src/lib.rs @@ -1,4 +1,3 @@ -mod ratatui_utils; mod widget; use log::{debug, error, info}; @@ -30,17 +29,26 @@ pub mod tui { /// /// # Example /// -/// ```rust -/// use harmony; -/// use harmony_tui::init; -/// -/// #[harmony::main] -/// pub async fn main(maestro: harmony::Maestro) { -/// maestro.register(DeploymentScore::new("nginx-test", "nginx")); -/// maestro.register(OKDLoadBalancerScore::new(&maestro.inventory, &maestro.topology)); -/// // Register other scores as needed -/// -/// init(maestro).await.unwrap(); +/// ```rust,no_run +/// use harmony::{ +/// inventory::Inventory, +/// maestro::Maestro, +/// modules::dummy::{ErrorScore, PanicScore, SuccessScore}, +/// topology::HAClusterTopology, +/// }; +/// +/// #[tokio::main] +/// async fn main() { +/// let inventory = Inventory::autoload(); +/// let topology = HAClusterTopology::autoload(); +/// let mut maestro = Maestro::new(inventory, topology); +/// +/// maestro.register_all(vec![ +/// Box::new(SuccessScore {}), +/// Box::new(ErrorScore {}), +/// Box::new(PanicScore {}), +/// ]); +/// harmony_tui::init(maestro).await.unwrap(); /// } /// ``` pub async fn init( diff --git a/harmony_tui/src/ratatui_utils.rs b/harmony_tui/src/ratatui_utils.rs deleted file mode 100644 index 84b8659..0000000 --- a/harmony_tui/src/ratatui_utils.rs +++ /dev/null @@ -1,22 +0,0 @@ -use ratatui::layout::{Constraint, Flex, Layout, Rect}; - -/// Centers a [`Rect`] within another [`Rect`] using the provided [`Constraint`]s. -/// -/// # Examples -/// -/// ```rust -/// use ratatui::layout::{Constraint, Rect}; -/// -/// let area = Rect::new(0, 0, 100, 100); -/// let horizontal = Constraint::Percentage(20); -/// let vertical = Constraint::Percentage(30); -/// -/// let centered = center(area, horizontal, vertical); -/// ``` -pub(crate) fn center(area: Rect, horizontal: Constraint, vertical: Constraint) -> Rect { - let [area] = Layout::horizontal([horizontal]) - .flex(Flex::Center) - .areas(area); - let [area] = Layout::vertical([vertical]).flex(Flex::Center).areas(area); - area -} diff --git a/opnsense-config-xml/src/data/interfaces.rs b/opnsense-config-xml/src/data/interfaces.rs index 4e518c7..e0a84d3 100644 --- a/opnsense-config-xml/src/data/interfaces.rs +++ b/opnsense-config-xml/src/data/interfaces.rs @@ -132,22 +132,18 @@ mod test { - - - -