fix: improve tests and remove unused code

- Corrected XML test data to remove unnecessary `<descr>` 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.
This commit is contained in:
Jean-Gabriel Gill-Couture 2025-04-11 11:01:05 -04:00
parent 31ae8365a6
commit 606ea43b51
4 changed files with 21 additions and 42 deletions

View File

@ -1,10 +1,7 @@
use harmony::{ use harmony::{
inventory::Inventory, inventory::Inventory,
maestro::Maestro, maestro::Maestro,
modules::{ modules::dummy::{ErrorScore, PanicScore, SuccessScore},
dummy::{ErrorScore, PanicScore, SuccessScore},
k8s::deployment::K8sDeploymentScore,
},
topology::HAClusterTopology, topology::HAClusterTopology,
}; };

View File

@ -1,4 +1,3 @@
mod ratatui_utils;
mod widget; mod widget;
use log::{debug, error, info}; use log::{debug, error, info};
@ -30,17 +29,26 @@ pub mod tui {
/// ///
/// # Example /// # Example
/// ///
/// ```rust /// ```rust,no_run
/// use harmony; /// use harmony::{
/// use harmony_tui::init; /// inventory::Inventory,
/// maestro::Maestro,
/// modules::dummy::{ErrorScore, PanicScore, SuccessScore},
/// topology::HAClusterTopology,
/// };
/// ///
/// #[harmony::main] /// #[tokio::main]
/// pub async fn main(maestro: harmony::Maestro) { /// async fn main() {
/// maestro.register(DeploymentScore::new("nginx-test", "nginx")); /// let inventory = Inventory::autoload();
/// maestro.register(OKDLoadBalancerScore::new(&maestro.inventory, &maestro.topology)); /// let topology = HAClusterTopology::autoload();
/// // Register other scores as needed /// let mut maestro = Maestro::new(inventory, topology);
/// ///
/// init(maestro).await.unwrap(); /// maestro.register_all(vec![
/// Box::new(SuccessScore {}),
/// Box::new(ErrorScore {}),
/// Box::new(PanicScore {}),
/// ]);
/// harmony_tui::init(maestro).await.unwrap();
/// } /// }
/// ``` /// ```
pub async fn init<T: Topology + std::fmt::Debug + Send + Sync + 'static>( pub async fn init<T: Topology + std::fmt::Debug + Send + Sync + 'static>(

View File

@ -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
}

View File

@ -132,22 +132,18 @@ mod test {
<interfaces> <interfaces>
<paul> <paul>
<if></if> <if></if>
<descr></descr>
<enable/> <enable/>
</paul> </paul>
<anotherpaul> <anotherpaul>
<if></if> <if></if>
<descr></descr>
<enable/> <enable/>
</anotherpaul> </anotherpaul>
<thirdone> <thirdone>
<if></if> <if></if>
<descr></descr>
<enable/> <enable/>
</thirdone> </thirdone>
<andgofor4> <andgofor4>
<if></if> <if></if>
<descr></descr>
<enable/> <enable/>
</andgofor4> </andgofor4>
</interfaces> </interfaces>