2023-07-29 15:27:16 +02:00
|
|
|
pub mod common;
|
|
|
|
|
|
|
|
use common::BufferUi;
|
2023-08-01 15:34:24 +02:00
|
|
|
use cuddle_please_commands::PleaseCommand;
|
2023-07-29 15:27:16 +02:00
|
|
|
use tracing_test::traced_test;
|
|
|
|
|
2023-07-29 19:23:05 +02:00
|
|
|
use crate::common::{assert_output, get_test_data_path};
|
|
|
|
|
2025-01-09 23:30:34 +01:00
|
|
|
#[allow(dead_code)]
|
2023-07-29 15:27:16 +02:00
|
|
|
fn get_base_args<'a>() -> Vec<&'a str> {
|
2023-08-01 16:38:30 +02:00
|
|
|
vec![
|
|
|
|
"cuddle-please",
|
|
|
|
"config",
|
|
|
|
"list",
|
|
|
|
"--no-vcs",
|
|
|
|
"--engine=local",
|
2023-08-03 23:31:53 +02:00
|
|
|
"--token=something",
|
2023-08-01 16:38:30 +02:00
|
|
|
]
|
2023-07-29 15:27:16 +02:00
|
|
|
}
|
|
|
|
|
2023-08-01 17:12:50 +02:00
|
|
|
const EXPECTED_OUTPUT: &str = r#"cuddle-config
|
2023-08-01 17:01:00 +02:00
|
|
|
PleaseConfig
|
|
|
|
owner: kjuulh
|
|
|
|
repository: cuddle-please
|
|
|
|
branch: main
|
|
|
|
api_url: https://some-example.gitea-instance
|
|
|
|
"#;
|
|
|
|
|
2025-01-09 23:30:34 +01:00
|
|
|
#[allow(dead_code)]
|
2023-07-29 15:27:16 +02:00
|
|
|
#[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");
|
|
|
|
|
2023-08-01 15:34:24 +02:00
|
|
|
PleaseCommand::new_from_args(Some(ui), args)
|
2023-07-29 15:27:16 +02:00
|
|
|
.execute(Some(¤t_dir))
|
|
|
|
.unwrap();
|
|
|
|
|
2023-08-01 17:01:00 +02:00
|
|
|
assert_output(ui, EXPECTED_OUTPUT, "");
|
2023-07-29 15:27:16 +02:00
|
|
|
}
|
|
|
|
|
2025-01-09 23:30:34 +01:00
|
|
|
#[allow(dead_code)]
|
2023-07-29 15:27:16 +02:00
|
|
|
#[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());
|
|
|
|
|
2023-08-01 15:34:24 +02:00
|
|
|
PleaseCommand::new_from_args(Some(ui), args)
|
2023-07-29 15:27:16 +02:00
|
|
|
.execute(None)
|
|
|
|
.unwrap();
|
|
|
|
|
2023-08-01 17:01:00 +02:00
|
|
|
assert_output(ui, EXPECTED_OUTPUT, "");
|
2023-07-29 15:27:16 +02:00
|
|
|
}
|
|
|
|
|
2025-01-09 23:30:34 +01:00
|
|
|
#[allow(dead_code)]
|
2023-07-29 15:27:16 +02:00
|
|
|
#[traced_test]
|
|
|
|
fn test_config_from_stdin() {
|
|
|
|
let mut args = get_base_args();
|
|
|
|
let ui = &BufferUi::default();
|
2023-08-01 02:31:44 +02:00
|
|
|
let config = r#"
|
|
|
|
project:
|
|
|
|
owner: kjuulh
|
|
|
|
repository: cuddle-please
|
|
|
|
branch: main
|
|
|
|
settings:
|
2023-08-01 17:01:00 +02:00
|
|
|
api_url: https://some-example.gitea-instance"#;
|
2023-07-29 15:27:16 +02:00
|
|
|
|
2023-08-01 02:31:44 +02:00
|
|
|
args.push("--config-stdin");
|
2023-08-01 15:34:24 +02:00
|
|
|
PleaseCommand::new_from_args_with_stdin(Some(ui), args, || Ok(config.into()))
|
2023-07-29 15:27:16 +02:00
|
|
|
.execute(None)
|
|
|
|
.unwrap();
|
2023-08-01 17:01:00 +02:00
|
|
|
assert_output(ui, EXPECTED_OUTPUT, "");
|
2023-07-29 15:27:16 +02:00
|
|
|
}
|
|
|
|
|
2025-01-09 23:30:34 +01:00
|
|
|
#[allow(dead_code)]
|
2023-07-29 15:27:16 +02:00
|
|
|
#[traced_test]
|
|
|
|
fn test_config_fails_when_not_path_is_set() {
|
|
|
|
let args = get_base_args();
|
|
|
|
let ui = &BufferUi::default();
|
|
|
|
|
2023-08-01 15:34:24 +02:00
|
|
|
let res = PleaseCommand::new_from_args(Some(ui), args).execute(None);
|
2023-07-29 15:27:16 +02:00
|
|
|
|
|
|
|
assert!(res.is_err())
|
|
|
|
}
|