cuddle-please/crates/cuddle-please/tests/config.rs
kjuulh 34417f77bc
Some checks failed
continuous-integration/drone/push Build is failing
feat: with working main
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-03 23:31:53 +02:00

88 lines
1.9 KiB
Rust

pub mod common;
use common::BufferUi;
use cuddle_please_commands::PleaseCommand;
use tracing_test::traced_test;
use crate::common::{assert_output, get_test_data_path};
fn get_base_args<'a>() -> Vec<&'a str> {
vec![
"cuddle-please",
"config",
"list",
"--no-vcs",
"--engine=local",
"--token=something",
]
}
const EXPECTED_OUTPUT: &str = r#"cuddle-config
PleaseConfig
owner: kjuulh
repository: cuddle-please
branch: main
api_url: https://some-example.gitea-instance
"#;
#[test]
#[traced_test]
fn test_config_from_current_dir() {
let args = get_base_args();
let ui = &BufferUi::default();
let current_dir = get_test_data_path("cuddle-embed");
PleaseCommand::new_from_args(Some(ui), args)
.execute(Some(&current_dir))
.unwrap();
assert_output(ui, EXPECTED_OUTPUT, "");
}
#[test]
#[traced_test]
fn test_config_from_source_dir() {
let mut args = get_base_args();
let ui = &BufferUi::default();
let current_dir = get_test_data_path("cuddle-embed");
args.push("--source");
args.push(current_dir.to_str().unwrap());
PleaseCommand::new_from_args(Some(ui), args)
.execute(None)
.unwrap();
assert_output(ui, EXPECTED_OUTPUT, "");
}
#[test]
#[traced_test]
fn test_config_from_stdin() {
let mut args = get_base_args();
let ui = &BufferUi::default();
let config = r#"
project:
owner: kjuulh
repository: cuddle-please
branch: main
settings:
api_url: https://some-example.gitea-instance"#;
args.push("--config-stdin");
PleaseCommand::new_from_args_with_stdin(Some(ui), args, || Ok(config.into()))
.execute(None)
.unwrap();
assert_output(ui, EXPECTED_OUTPUT, "");
}
#[test]
#[traced_test]
fn test_config_fails_when_not_path_is_set() {
let args = get_base_args();
let ui = &BufferUi::default();
let res = PleaseCommand::new_from_args(Some(ui), args).execute(None);
assert!(res.is_err())
}