Co-authored-by: tahahawa <tahahawa@gmail.com> Reviewed-on: #9 Reviewed-by: johnride <jg@nationtech.io> Co-authored-by: Taha Hawa <taha@taha.dev> Co-committed-by: Taha Hawa <taha@taha.dev>
This commit is contained in:
19
examples/cli/Cargo.toml
Normal file
19
examples/cli/Cargo.toml
Normal file
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "example-cli"
|
||||
edition = "2024"
|
||||
version.workspace = true
|
||||
readme.workspace = true
|
||||
license.workspace = true
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
harmony = { path = "../../harmony" }
|
||||
harmony_cli = { path = "../../harmony_cli" }
|
||||
harmony_types = { path = "../../harmony_types" }
|
||||
cidr = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
harmony_macros = { path = "../../harmony_macros" }
|
||||
log = { workspace = true }
|
||||
env_logger = { workspace = true }
|
||||
url = { workspace = true }
|
||||
assert_cmd = "2.0.16"
|
||||
38
examples/cli/src/main.rs
Normal file
38
examples/cli/src/main.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
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_cli::init(maestro, None).await.unwrap();
|
||||
}
|
||||
|
||||
use assert_cmd::Command;
|
||||
|
||||
#[test]
|
||||
fn test_example_success() {
|
||||
let mut cmd = Command::cargo_bin("example-cli").unwrap();
|
||||
let assert = cmd.args(&["--yes", "--filter", "SuccessScore"]).assert();
|
||||
|
||||
assert.success();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_example_fail() {
|
||||
let mut cmd_fail = Command::cargo_bin("example-cli").unwrap();
|
||||
let assert_fail = cmd_fail.args(&["--yes", "--filter", "ErrorScore"]).assert();
|
||||
|
||||
assert_fail.failure();
|
||||
}
|
||||
Reference in New Issue
Block a user