use assert_cmd::prelude::*; use predicates::prelude::*; use std::fs::{create_dir_all, File}; use std::io::prelude::*; use std::process::Command; mod common; #[test] fn new_service() -> Result<(), Box> { // Create a temporary project let root_dir = common::create_project("new-service")?; let folder = root_dir.path(); // Create a new service let mut cmd = Command::cargo_bin("orcs")?; cmd.arg("-p") .arg(&folder) .arg("new") .arg("service") .arg("my-service"); cmd.assert().success(); // Check if the service file exists let _ = File::open(folder.join("srv").join("my-service").join("orcs.toml"))?; Ok(()) } #[test] fn new_recipe() -> Result<(), Box> { // Create a temporary project let root_dir = common::create_project("new-recipe")?; let folder = root_dir.path(); // Create a new service let mut cmd = Command::cargo_bin("orcs")?; cmd.arg("-p") .arg(&folder) .arg("new") .arg("recipe") .arg("my-recipe"); cmd.assert().success(); // Check if the service file exists let _ = File::open(folder.join("rcp").join("my-recipe.toml"))?; Ok(()) } #[test] fn new_service_from_template() -> Result<(), Box> { // Create a temporary project let root_dir = common::create_project("service-from-template")?; let folder = root_dir.path(); // Create a template create_dir_all(folder.join("template"))?; let mut test_file = File::create(folder.join("template").join("test.txt"))?; let test_data = "Hello, {{{ service_name }}}!"; test_file.write_all(test_data.as_bytes())?; // Run the command let mut cmd = Command::cargo_bin("orcs")?; cmd.arg("-p") .arg(&folder) .arg("new") .arg("service") .arg("my-service") .arg("-t") .arg(&folder.join("template")); cmd.assert().success(); // Check the service folder let mut file = File::open(folder.join("srv").join("my-service").join("test.txt"))?; let mut data = String::new(); file.read_to_string(&mut data)?; assert!(predicate::str::contains("my-service").eval(&data)); Ok(()) }