feat: harmony-cli v0.1 #8 #9

Merged
taha merged 23 commits from harmony-cli into master 2025-04-19 01:13:40 +00:00
8 changed files with 1204 additions and 385 deletions
Showing only changes of commit 09e61eaabc - Show all commits

View File

@@ -148,9 +148,9 @@ mod test {
modules::dummy::{ErrorScore, PanicScore, SuccessScore}, modules::dummy::{ErrorScore, PanicScore, SuccessScore},
topology::HAClusterTopology, topology::HAClusterTopology,
}; };
use harmony::{score::Score, topology::Topology};
#[tokio::test] fn init_test_maestro() -> Maestro<HAClusterTopology> {
async fn test_init_success_score() {
let inventory = Inventory::autoload(); let inventory = Inventory::autoload();
let topology = HAClusterTopology::autoload(); let topology = HAClusterTopology::autoload();
let mut maestro = Maestro::new(inventory, topology); let mut maestro = Maestro::new(inventory, topology);
@@ -161,6 +161,12 @@ mod test {
Box::new(PanicScore {}), Box::new(PanicScore {}),
]); ]);
maestro
}
#[tokio::test]
async fn test_init_success_score() {
let maestro = init_test_maestro();
let res = crate::init( let res = crate::init(
maestro, maestro,
Some(crate::Args { Some(crate::Args {
@@ -179,15 +185,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn test_init_error_score() { async fn test_init_error_score() {
let inventory = Inventory::autoload(); let maestro = init_test_maestro();
let topology = HAClusterTopology::autoload();
let mut maestro = Maestro::new(inventory, topology);
maestro.register_all(vec![
Box::new(SuccessScore {}),
Box::new(ErrorScore {}),
Box::new(PanicScore {}),
]);
let res = crate::init( let res = crate::init(
maestro, maestro,
@@ -207,15 +205,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn test_init_number_score() { async fn test_init_number_score() {
let inventory = Inventory::autoload(); let maestro = init_test_maestro();
let topology = HAClusterTopology::autoload();
let mut maestro = Maestro::new(inventory, topology);
maestro.register_all(vec![
Box::new(SuccessScore {}),
Box::new(ErrorScore {}),
Box::new(PanicScore {}),
]);
let res = crate::init( let res = crate::init(
maestro, maestro,
@@ -235,15 +225,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn test_filter_fn_all() { async fn test_filter_fn_all() {
let inventory = Inventory::autoload(); let maestro = init_test_maestro();
let topology = HAClusterTopology::autoload();
let mut maestro = Maestro::new(inventory, topology);
maestro.register_all(vec![
Box::new(SuccessScore {}),
Box::new(ErrorScore {}),
Box::new(PanicScore {}),
]);
let res = crate::maestro_scores_filter(&maestro, true, None, 0); let res = crate::maestro_scores_filter(&maestro, true, None, 0);
@@ -252,15 +234,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn test_filter_fn_all_success() { async fn test_filter_fn_all_success() {
let inventory = Inventory::autoload(); let maestro = init_test_maestro();
let topology = HAClusterTopology::autoload();
let mut maestro = Maestro::new(inventory, topology);
maestro.register_all(vec![
Box::new(SuccessScore {}),
Box::new(ErrorScore {}),
Box::new(PanicScore {}),
]);
let res = crate::maestro_scores_filter(&maestro, true, Some("Success".to_owned()), 0); let res = crate::maestro_scores_filter(&maestro, true, Some("Success".to_owned()), 0);
@@ -276,15 +250,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn test_filter_fn_all_error() { async fn test_filter_fn_all_error() {
let inventory = Inventory::autoload(); let maestro = init_test_maestro();
let topology = HAClusterTopology::autoload();
let mut maestro = Maestro::new(inventory, topology);
maestro.register_all(vec![
Box::new(SuccessScore {}),
Box::new(ErrorScore {}),
Box::new(PanicScore {}),
]);
let res = crate::maestro_scores_filter(&maestro, true, Some("Error".to_owned()), 0); let res = crate::maestro_scores_filter(&maestro, true, Some("Error".to_owned()), 0);
@@ -300,15 +266,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn test_filter_fn_all_score() { async fn test_filter_fn_all_score() {
let inventory = Inventory::autoload(); let maestro = init_test_maestro();
let topology = HAClusterTopology::autoload();
let mut maestro = Maestro::new(inventory, topology);
maestro.register_all(vec![
Box::new(SuccessScore {}),
Box::new(ErrorScore {}),
Box::new(PanicScore {}),
]);
let res = crate::maestro_scores_filter(&maestro, true, Some("Score".to_owned()), 0); let res = crate::maestro_scores_filter(&maestro, true, Some("Score".to_owned()), 0);
@@ -330,15 +288,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn test_filter_fn_number() { async fn test_filter_fn_number() {
let inventory = Inventory::autoload(); let maestro = init_test_maestro();
let topology = HAClusterTopology::autoload();
let mut maestro = Maestro::new(inventory, topology);
maestro.register_all(vec![
Box::new(SuccessScore {}),
Box::new(ErrorScore {}),
Box::new(PanicScore {}),
]);
let res = crate::maestro_scores_filter(&maestro, false, None, 0); let res = crate::maestro_scores_filter(&maestro, false, None, 0);
@@ -356,15 +306,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn test_filter_fn_number_invalid() { async fn test_filter_fn_number_invalid() {
let inventory = Inventory::autoload(); let maestro = init_test_maestro();
let topology = HAClusterTopology::autoload();
let mut maestro = Maestro::new(inventory, topology);
maestro.register_all(vec![
Box::new(SuccessScore {}),
Box::new(ErrorScore {}),
Box::new(PanicScore {}),
]);
let res = crate::maestro_scores_filter(&maestro, false, None, 11); let res = crate::maestro_scores_filter(&maestro, false, None, 11);
Review

Those 8 lines should be extracted to a utilty function in the test module such as "init_test_maestro() -> Maestro"

Those 8 lines should be extracted to a utilty function in the test module such as "init_test_maestro() -> Maestro"