git-next/crates/cli/src/tests.rs
Paul Campbell 9a9c73d929
All checks were successful
Rust / build (push) Successful in 1m15s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
feat: return better errors to the user on init
2024-07-30 11:18:29 +01:00

40 lines
983 B
Rust

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())?;
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())?;
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"),
"The file does not match the default template"
);
Ok(())
}
}