#[cfg(test)]
mod integration_tests {
use crate::*;
use tempfile::TempDir;
use std::fs;
#[test]
fn test_basic_workflow() {
let root_dir = TempDir::new().unwrap();
let storage_dir = TempDir::new().unwrap();
let mut titor = TitorBuilder::new()
.compression_strategy(CompressionStrategy::Fast)
.build(
root_dir.path().to_path_buf(),
storage_dir.path().to_path_buf(),
)
.unwrap();
fs::write(root_dir.path().join("README.md"), "# My Project").unwrap();
fs::write(root_dir.path().join("main.rs"), "fn main() {}").unwrap();
let checkpoint1 = titor.checkpoint(Some("Initial commit".to_string())).unwrap();
assert_eq!(checkpoint1.metadata.file_count, 2);
fs::write(root_dir.path().join("main.rs"), "fn main() { println!(\"Hello\"); }").unwrap();
fs::write(root_dir.path().join("lib.rs"), "pub fn hello() {}").unwrap();
let checkpoint2 = titor.checkpoint(Some("Add hello function".to_string())).unwrap();
assert_eq!(checkpoint2.parent_id, Some(checkpoint1.id.clone()));
let restore_result = titor.restore(&checkpoint1.id).unwrap();
assert_eq!(restore_result.files_restored, 2);
assert_eq!(restore_result.files_deleted, 1);
let main_content = fs::read_to_string(root_dir.path().join("main.rs")).unwrap();
assert_eq!(main_content, "fn main() {}");
assert!(!root_dir.path().join("lib.rs").exists());
}
}