use assert_cmd::cargo::cargo_bin_cmd;
use std::fs;
use tempfile::tempdir;
#[test]
fn test_rack() {
let temp_dir = tempdir().unwrap();
let rack_path = temp_dir.path().join("my_rack");
let mut cmd = cargo_bin_cmd!("ml-cellar");
cmd.arg("rack").arg(&rack_path);
cmd.assert().success();
assert!(rack_path.is_dir());
let readme = rack_path.join("README.md");
let config = rack_path.join("config.toml");
let template = rack_path.join("template.md");
assert!(readme.is_file(), "README.md should exist");
assert!(config.is_file(), "config.toml should exist");
assert!(template.is_file(), "template.md should exist");
let readme_text = fs::read_to_string(&readme).unwrap();
assert!(readme_text.contains("my_rack"), "README content is wrong");
let config_text = fs::read_to_string(&config).unwrap();
let target_config =
fs::read_to_string("tests/fixtures/test_registry/test_rack/config.toml").unwrap();
assert_eq!(
config_text, target_config,
"config.toml is \n***\n{} \n*** \n and different from the config file.",
config_text
);
let template_text = fs::read_to_string(&template).unwrap();
let target_template =
fs::read_to_string("tests/fixtures/test_registry/test_rack/template.md").unwrap();
assert_eq!(
template_text, target_template,
"template.md is \n***\n{} \n*** \n and different from the template file.",
template_text
);
}