use assert_cmd::cargo::cargo_bin_cmd;
use std::fs;
use tempfile::tempdir;
#[test]
fn test_init() {
let temp_dir = tempdir().unwrap();
let mut cmd = cargo_bin_cmd!("ml-cellar");
cmd.arg("init");
cmd.current_dir(temp_dir.path());
cmd.assert().success();
let git_dir = temp_dir.path().join(".git");
assert!(git_dir.is_dir(), ".git directory should exist");
let gitattributes_path = temp_dir.path().join(".gitattributes");
assert!(gitattributes_path.is_file(), ".gitattributes should exist");
let gitattributes_text = fs::read_to_string(&gitattributes_path).unwrap();
let target_gitattributes =
fs::read_to_string("tests/fixtures/init_test/.gitattributes").unwrap();
assert_eq!(
gitattributes_text, target_gitattributes,
".gitattributes is \n***\n{} \n*** \n and different from the target file.",
gitattributes_text
);
let repository_config_path = temp_dir.path().join(".mlcellar.toml");
assert!(
repository_config_path.is_file(),
".mlcellar.toml should exist"
);
let mlcellar_text = fs::read_to_string(&repository_config_path).unwrap();
let target_mlcellar = fs::read_to_string("tests/fixtures/init_test/.mlcellar.toml").unwrap();
assert_eq!(
mlcellar_text, target_mlcellar,
".mlcellar.toml is \n***\n{} \n*** \n and different from the target file.",
mlcellar_text
);
}