#[cfg(test)]
mod tests {
use std::{fs, path::Path};
use crate::{
config::config_structure::Config,
init_command::{init_command, init_structure::Init},
};
#[test]
fn test_init_command_creates_template_file() {
let project_name = "test_project";
let init = Init {
name: project_name.to_string(),
};
let expected_file = format!("{}-template.json", project_name);
if Path::new(&expected_file).exists() {
fs::remove_file(&expected_file).unwrap();
}
init_command(&init);
assert!(
Path::new(&expected_file).exists(),
"Template file was not created"
);
let contents = fs::read_to_string(&expected_file).expect("Failed to read created file");
assert!(
contents.contains("\"name\": \"test_project\""),
"Template JSON missing expected content"
);
let config: Config = serde_json::from_str(&contents).expect("Invalid JSON structure");
assert_eq!(config.name, project_name);
assert_eq!(config.version, "0.1.0");
fs::remove_file(&expected_file).unwrap();
}
}