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")?;
|
|
|
|
|
2024-07-30 10:52:05 +01:00
|
|
|
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()?;
|
|
|
|
|
2024-07-30 10:52:05 +01:00
|
|
|
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)?,
|
2024-07-14 20:14:00 +01:00
|
|
|
include_str!("../default.toml"),
|
2024-05-14 07:58:28 +01:00
|
|
|
"The file does not match the default template"
|
|
|
|
);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|