Compare commits
3 Commits
2d97cac64b
...
8c7f7471b2
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c7f7471b2 | |||
| 122c75f4be | |||
| 09e61eaabc |
@ -53,8 +53,8 @@ fn maestro_scores_filter<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
|
||||
let mut scores_vec: Vec<Box<dyn Score<T>>> = match filter {
|
||||
Some(f) => scores_read
|
||||
.iter()
|
||||
.map(|s| s.clone_box())
|
||||
.filter(|s| s.name().contains(&f))
|
||||
.map(|s| s.clone_box())
|
||||
.collect(),
|
||||
None => scores_read.iter().map(|s| s.clone_box()).collect(),
|
||||
};
|
||||
@ -70,6 +70,7 @@ fn maestro_scores_filter<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
|
||||
return scores_vec;
|
||||
}
|
||||
|
||||
// TODO: consider adding doctest for this function
|
||||
fn list_scores_with_index<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
|
||||
scores_vec: &Vec<Box<dyn Score<T>>>,
|
||||
) -> String {
|
||||
@ -113,7 +114,7 @@ pub async fn init<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// if no score to run provided, and list isn't specified, print help
|
||||
// prompt user if --yes is not specified
|
||||
if !args.yes {
|
||||
let confirmation = Confirm::new(
|
||||
format!(
|
||||
@ -131,7 +132,7 @@ pub async fn init<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
|
||||
}
|
||||
}
|
||||
|
||||
// if all is specified, run all. Otherwise, run the first match or specified index
|
||||
// Run filtered scores
|
||||
for s in scores_vec {
|
||||
println!("Running: {}", s.name());
|
||||
maestro.interpret(s).await?;
|
||||
@ -148,9 +149,9 @@ mod test {
|
||||
modules::dummy::{ErrorScore, PanicScore, SuccessScore},
|
||||
topology::HAClusterTopology,
|
||||
};
|
||||
use harmony::{score::Score, topology::Topology};
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_init_success_score() {
|
||||
fn init_test_maestro() -> Maestro<HAClusterTopology> {
|
||||
let inventory = Inventory::autoload();
|
||||
let topology = HAClusterTopology::autoload();
|
||||
let mut maestro = Maestro::new(inventory, topology);
|
||||
@ -161,6 +162,12 @@ mod test {
|
||||
Box::new(PanicScore {}),
|
||||
]);
|
||||
|
||||
maestro
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_init_success_score() {
|
||||
let maestro = init_test_maestro();
|
||||
let res = crate::init(
|
||||
maestro,
|
||||
Some(crate::Args {
|
||||
@ -179,15 +186,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_init_error_score() {
|
||||
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 {}),
|
||||
]);
|
||||
let maestro = init_test_maestro();
|
||||
|
||||
let res = crate::init(
|
||||
maestro,
|
||||
@ -207,15 +206,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_init_number_score() {
|
||||
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 {}),
|
||||
]);
|
||||
let maestro = init_test_maestro();
|
||||
|
||||
let res = crate::init(
|
||||
maestro,
|
||||
@ -235,15 +226,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_filter_fn_all() {
|
||||
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 {}),
|
||||
]);
|
||||
let maestro = init_test_maestro();
|
||||
|
||||
let res = crate::maestro_scores_filter(&maestro, true, None, 0);
|
||||
|
||||
@ -252,15 +235,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_filter_fn_all_success() {
|
||||
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 {}),
|
||||
]);
|
||||
let maestro = init_test_maestro();
|
||||
|
||||
let res = crate::maestro_scores_filter(&maestro, true, Some("Success".to_owned()), 0);
|
||||
|
||||
@ -276,15 +251,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_filter_fn_all_error() {
|
||||
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 {}),
|
||||
]);
|
||||
let maestro = init_test_maestro();
|
||||
|
||||
let res = crate::maestro_scores_filter(&maestro, true, Some("Error".to_owned()), 0);
|
||||
|
||||
@ -300,15 +267,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_filter_fn_all_score() {
|
||||
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 {}),
|
||||
]);
|
||||
let maestro = init_test_maestro();
|
||||
|
||||
let res = crate::maestro_scores_filter(&maestro, true, Some("Score".to_owned()), 0);
|
||||
|
||||
@ -330,15 +289,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_filter_fn_number() {
|
||||
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 {}),
|
||||
]);
|
||||
let maestro = init_test_maestro();
|
||||
|
||||
let res = crate::maestro_scores_filter(&maestro, false, None, 0);
|
||||
|
||||
@ -356,15 +307,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_filter_fn_number_invalid() {
|
||||
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 {}),
|
||||
]);
|
||||
let maestro = init_test_maestro();
|
||||
|
||||
let res = crate::maestro_scores_filter(&maestro, false, None, 11);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user