this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 37ff052fe16568b67a2f714d63b733c3d84db33d 195 lines 5.6 kB view raw
1extern crate assert_cmd; 2extern crate assert_fs; 3extern crate predicates; 4 5use assert_cmd::prelude::*; 6use assert_fs::prelude::*; 7use assert_fs::TempDir; 8use predicates::prelude::*; 9use std::process::Command; 10 11// Test the most common multi-level compression case: tar.gz 12#[test] 13fn test_tar_gz_manual_roundtrip() -> Result<(), Box<dyn std::error::Error>> { 14 let temp_dir = TempDir::new()?; 15 let file = temp_dir.child("test.txt"); 16 file.write_str("test content")?; 17 18 // Step 1: Create a tar file 19 let tar_file = temp_dir.child("test.tar"); 20 Command::cargo_bin("cmprss")? 21 .arg("tar") 22 .arg(file.path()) 23 .arg(tar_file.path()) 24 .assert() 25 .success(); 26 27 // Step 2: Compress the tar file with gzip 28 let tar_gz_file = temp_dir.child("test.tar.gz"); 29 Command::cargo_bin("cmprss")? 30 .arg("gzip") 31 .arg(tar_file.path()) 32 .arg(tar_gz_file.path()) 33 .assert() 34 .success(); 35 36 // Step 3: Extract the gzip layer 37 let extract_tar = temp_dir.child("extracted.tar"); 38 Command::cargo_bin("cmprss")? 39 .arg("gzip") 40 .arg("--extract") 41 .arg(tar_gz_file.path()) 42 .arg(extract_tar.path()) 43 .assert() 44 .success(); 45 46 // Step 4: Extract the tar layer to a directory 47 let extract_dir = temp_dir.child("extracted"); 48 extract_dir.create_dir_all()?; 49 Command::cargo_bin("cmprss")? 50 .arg("tar") 51 .arg("--extract") 52 .arg(extract_tar.path()) 53 .arg(extract_dir.path()) 54 .assert() 55 .success(); 56 57 // Verify the extracted content 58 let extracted_file = extract_dir.child("test.txt"); 59 extracted_file.assert(predicate::path::exists()); 60 extracted_file.assert(predicate::str::contains("test content")); 61 62 Ok(()) 63} 64 65// 66// Test the multi-level compression using tar.gz format 67// 68#[test] 69fn test_tar_gz_compress() -> Result<(), Box<dyn std::error::Error>> { 70 let temp_dir = TempDir::new()?; 71 72 // Create a file structure for testing 73 let source_dir = temp_dir.child("source"); 74 source_dir.create_dir_all()?; 75 76 let test_file = source_dir.child("test_file.txt"); 77 test_file.write_str("test content for tar.gz compression")?; 78 79 // Create a tar.gz archive directly in one step 80 let archive = temp_dir.child("direct.tar.gz"); 81 Command::cargo_bin("cmprss")? 82 .arg("--compress") // explicitly specify compression 83 .arg(source_dir.path()) 84 .arg(archive.path()) 85 .assert() 86 .success(); 87 88 // Verify the archive was created 89 archive.assert(predicate::path::exists()); 90 91 Ok(()) 92} 93 94// 95// Test the multi-level extraction using tar.gz format 96// 97#[test] 98fn test_tar_gz_extract() -> Result<(), Box<dyn std::error::Error>> { 99 let temp_dir = TempDir::new()?; 100 101 // Create a file structure for testing 102 let source_dir = temp_dir.child("source"); 103 source_dir.create_dir_all()?; 104 105 let test_file = source_dir.child("test_file.txt"); 106 test_file.write_str("test content for tar.gz extraction")?; 107 108 // Create a tar file first 109 let tar_file = temp_dir.child("archive.tar"); 110 Command::cargo_bin("cmprss")? 111 .arg("tar") 112 .arg(source_dir.path()) 113 .arg(tar_file.path()) 114 .assert() 115 .success(); 116 117 // Compress the tar with gzip 118 let tar_gz_file = temp_dir.child("archive.tar.gz"); 119 Command::cargo_bin("cmprss")? 120 .arg("gzip") 121 .arg(tar_file.path()) 122 .arg(tar_gz_file.path()) 123 .assert() 124 .success(); 125 126 // Create an extraction directory 127 let extract_dir = temp_dir.child("extract"); 128 extract_dir.create_dir_all()?; 129 130 // Extract the tar.gz archive 131 Command::cargo_bin("cmprss")? 132 .arg("--extract") 133 .arg(tar_gz_file.path()) 134 .arg(extract_dir.path()) 135 .assert() 136 .success(); 137 138 // Verify the file was extracted correctly 139 let extracted_file = extract_dir.child("test_file.txt"); 140 extracted_file.assert(predicate::path::exists()); 141 extracted_file.assert(predicate::str::contains( 142 "test content for tar.gz extraction", 143 )); 144 145 Ok(()) 146} 147 148// 149// Test the multi-level extraction using tar.gz format with explicit commands 150// 151#[test] 152fn test_tar_gz_explicit_then_extract() -> Result<(), Box<dyn std::error::Error>> { 153 let temp_dir = TempDir::new()?; 154 155 // Create a simple test file 156 let test_file = temp_dir.child("test.txt"); 157 test_file.write_str("test content for tar.gz")?; 158 159 // Create a tar archive first (explicit command) 160 let tar_file = temp_dir.child("test.tar"); 161 Command::cargo_bin("cmprss")? 162 .arg("tar") 163 .arg(test_file.path()) 164 .arg(tar_file.path()) 165 .assert() 166 .success(); 167 168 // Compress the tar with gzip (explicit command) 169 let tar_gz_file = temp_dir.child("test.tar.gz"); 170 Command::cargo_bin("cmprss")? 171 .arg("gzip") 172 .arg(tar_file.path()) 173 .arg(tar_gz_file.path()) 174 .assert() 175 .success(); 176 177 // Create an extraction directory 178 let extract_dir = temp_dir.child("extract"); 179 extract_dir.create_dir_all()?; 180 181 // Extract using the tar.gz auto-detection 182 Command::cargo_bin("cmprss")? 183 .arg("-e") // Use short form for extract 184 .arg(tar_gz_file.path()) 185 .arg(extract_dir.path()) 186 .assert() 187 .success(); 188 189 // Verify the file was extracted correctly 190 let extracted_file = extract_dir.child("test.txt"); 191 extracted_file.assert(predicate::path::exists()); 192 extracted_file.assert(predicate::str::contains("test content for tar.gz")); 193 194 Ok(()) 195}