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", ] } 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(¤t_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()) }