kjuulh
62a677ffcd
All checks were successful
continuous-integration/drone/push Build is passing
although I am not entirely happy with it, as we're missing args, state and project variables Signed-off-by: kjuulh <contact@kjuulh.io>
68 lines
1.5 KiB
Rust
68 lines
1.5 KiB
Rust
use cuddle_actions::AddActionOptions;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn test_can_schema_no_actions() -> anyhow::Result<()> {
|
|
let output = cuddle_actions::CuddleActions::default().get_pretty_actions()?;
|
|
|
|
assert_eq!("[]", &output);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn test_can_schema_simple_action() -> anyhow::Result<()> {
|
|
let output = cuddle_actions::CuddleActions::default()
|
|
.add_action("something", || Ok(()), &AddActionOptions::default())
|
|
.get_pretty_actions()?;
|
|
|
|
assert_eq!(
|
|
r#"[
|
|
{
|
|
"name": "something",
|
|
"description": null
|
|
}
|
|
]"#,
|
|
&output
|
|
);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn test_can_call_simple_action() -> anyhow::Result<()> {
|
|
cuddle_actions::CuddleActions::default()
|
|
.add_action("something", || Ok(()), &AddActionOptions::default())
|
|
.execute_from(vec!["cuddle-actions", "do", "something"])?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn test_can_fail_on_unknown_command() -> anyhow::Result<()> {
|
|
let res = cuddle_actions::CuddleActions::default().execute_from(vec![
|
|
"cuddle-actions",
|
|
"do",
|
|
"something",
|
|
]);
|
|
|
|
assert!(res.is_err());
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn test_can_cmd_can_fail() -> anyhow::Result<()> {
|
|
let res = cuddle_actions::CuddleActions::default()
|
|
.add_action(
|
|
"something",
|
|
|| anyhow::bail!("failed to run cmd"),
|
|
&AddActionOptions::default(),
|
|
)
|
|
.execute_from(vec!["cuddle-actions", "do", "something"]);
|
|
|
|
assert!(res.is_err());
|
|
|
|
Ok(())
|
|
}
|