|
| 1 | +use std::process::Command; |
| 2 | +use tempfile::TempDir; |
1 | 3 |
|
| 4 | +/// Helper function: Initialize a temporary Libra repository |
| 5 | +fn init_temp_repo() -> TempDir { |
| 6 | + let temp_dir = tempfile::tempdir().expect("Failed to create temporary directory"); |
| 7 | + let temp_path = temp_dir.path(); |
| 8 | + |
| 9 | + // Variables can be used directly in the `format!` string |
| 10 | + // FIX: Removed {:?} and added variable directly with formatting |
| 11 | + println!("Temporary directory created at: {temp_path:?}"); |
| 12 | + assert!(temp_path.is_dir(), "Temporary path is not a valid directory"); |
| 13 | + |
| 14 | + // Using env!("CARGO_BIN_EXE_libra") to get the path to the libra executable |
| 15 | + let output = Command::new(env!("CARGO_BIN_EXE_libra")) |
| 16 | + .current_dir(temp_path) |
| 17 | + .arg("init") |
| 18 | + .output() |
| 19 | + .expect("Failed to execute libra binary"); |
| 20 | + |
| 21 | + if !output.status.success() { |
| 22 | + panic!( |
| 23 | + "Failed to initialize libra repository: {}", |
| 24 | + String::from_utf8_lossy(&output.stderr) |
| 25 | + ); |
| 26 | + } |
| 27 | + |
| 28 | + temp_dir |
| 29 | +} |
| 30 | + |
| 31 | +#[tokio::test] |
| 32 | +/// Test track/untrack path rule management |
| 33 | +async fn test_lfs_track_untrack() { |
| 34 | + let temp_repo = init_temp_repo(); |
| 35 | + let temp_path = temp_repo.path(); |
| 36 | + |
| 37 | + // Add a path rule |
| 38 | + // FIX: Removed & from args |
| 39 | + let track_output = Command::new(env!("CARGO_BIN_EXE_libra")) |
| 40 | + .current_dir(temp_path) |
| 41 | + .args(["lfs", "track", "*.txt"]) // Changed &[...] to [...] |
| 42 | + .output() |
| 43 | + .expect("Failed to track path"); |
| 44 | + assert!( |
| 45 | + track_output.status.success(), |
| 46 | + "Failed to track path: {}", |
| 47 | + String::from_utf8_lossy(&track_output.stderr) |
| 48 | + ); |
| 49 | + |
| 50 | + // Remove a path rule |
| 51 | + // FIX: Removed & from args |
| 52 | + let untrack_output = Command::new(env!("CARGO_BIN_EXE_libra")) |
| 53 | + .current_dir(temp_path) |
| 54 | + .args(["lfs", "untrack", "*.txt"]) // Changed &[...] to [...] |
| 55 | + .output() |
| 56 | + .expect("Failed to untrack path"); |
| 57 | + assert!( |
| 58 | + untrack_output.status.success(), |
| 59 | + "Failed to untrack path: {}", |
| 60 | + String::from_utf8_lossy(&untrack_output.stderr) |
| 61 | + ); |
| 62 | +} |
| 63 | + |
| 64 | +#[tokio::test] |
| 65 | +/// Test file status viewing |
| 66 | +async fn test_lfs_ls_files() { |
| 67 | + let temp_repo = init_temp_repo(); |
| 68 | + let temp_path = temp_repo.path(); |
| 69 | + |
| 70 | + // Create a test file and add it to LFS |
| 71 | + let file_path = temp_path.join("tracked_file.txt"); |
| 72 | + std::fs::write(&file_path, "Tracked content").expect("Failed to create tracked file"); |
| 73 | + |
| 74 | + // FIX: Removed & from args |
| 75 | + Command::new(env!("CARGO_BIN_EXE_libra")) |
| 76 | + .current_dir(temp_path) |
| 77 | + .args(["lfs", "track", "*.txt"]) // Changed &[...] to [...] |
| 78 | + .output() |
| 79 | + .expect("Failed to track file"); |
| 80 | + |
| 81 | + // FIX: Removed & from args |
| 82 | + Command::new(env!("CARGO_BIN_EXE_libra")) |
| 83 | + .current_dir(temp_path) |
| 84 | + .args(["add", "tracked_file.txt"]) // Changed &[...] to [...] |
| 85 | + .output() |
| 86 | + .expect("Failed to add file to LFS"); |
| 87 | + |
| 88 | + // View file status |
| 89 | + // FIX: Removed & from args |
| 90 | + let ls_files_output = Command::new(env!("CARGO_BIN_EXE_libra")) |
| 91 | + .current_dir(temp_path) |
| 92 | + .args(["lfs", "ls-files"]) // Changed &[...] to [...] |
| 93 | + .output() |
| 94 | + .expect("Failed to list LFS files"); |
| 95 | + assert!( |
| 96 | + ls_files_output.status.success(), |
| 97 | + "Failed to list LFS files: {}", |
| 98 | + String::from_utf8_lossy(&ls_files_output.stderr) |
| 99 | + ); |
| 100 | + |
| 101 | + let stdout = String::from_utf8_lossy(&ls_files_output.stdout); |
| 102 | + // FIX: Variables can be used directly in the `format!` string |
| 103 | + assert!( |
| 104 | + stdout.contains("tracked_file.txt"), |
| 105 | + "LFS file list does not contain expected file: {stdout}", // Changed {} to direct variable embed |
| 106 | + ); |
| 107 | +} |
0 commit comments