git-next/crates/cli/src/tests.rs

41 lines
983 B
Rust
Raw Normal View History

2024-05-14 07:58:28 +01:00
type TestResult = Result<(), Box<dyn std::error::Error>>;
mod init {
use super::*;
#[test]
fn should_not_update_file_if_it_exists() -> TestResult {
let fs = kxio::fs::temp()?;
let file = fs.base().join(".git-next.toml");
fs.file_write(&file, "contents")?;
crate::init::run(fs.clone())?;
2024-05-14 07:58:28 +01:00
assert_eq!(
fs.file_read_to_string(&file)?,
"contents",
"The file has been changed"
);
Ok(())
}
#[test]
fn should_create_default_file_if_not_exists() -> TestResult {
let fs = kxio::fs::temp()?;
crate::init::run(fs.clone())?;
2024-05-14 07:58:28 +01:00
let file = fs.base().join(".git-next.toml");
assert!(fs.path_exists(&file)?, "The file has not been created");
assert_eq!(
fs.file_read_to_string(&file)?,
include_str!("../default.toml"),
2024-05-14 07:58:28 +01:00
"The file does not match the default template"
);
Ok(())
}
}