From 8d7ced2d8a0a8d1934cf1afedc1a9a6d218008a8 Mon Sep 17 00:00:00 2001 From: Talison Fabio <54823205+talis-fb@users.noreply.github.com> Date: Sat, 26 Apr 2025 10:22:48 -0300 Subject: [PATCH] test: add all tests --- tests/integration.rs | 117 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 7 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index 1bc730f..7e49001 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -368,7 +368,6 @@ fn multiple_files_with_conflict_and_choice_to_rename_with_already_a_renamed( assert_same_directory(src_files_path, dest_files_path_renamed.join("src_files"), false); } - #[proptest(cases = 25)] fn smart_unpack_with_single_file( ext: DirectoryExtension, @@ -390,9 +389,6 @@ fn smart_unpack_with_single_file( }) .collect::>(); - // let dest_files_path = root_path.join("dest_files"); - // fs::create_dir_all(&dest_files_path).unwrap(); - let archive = &root_path.join(format!("archive.{}", merge_extensions(&ext, extra_extensions))); crate::utils::cargo_bin() @@ -438,28 +434,135 @@ fn smart_unpack_with_multiple_files( file.write_all("Some content".as_bytes()).unwrap(); }); + let input_files = src_files_path + .read_dir() + .unwrap() + .map(|entry| entry.unwrap().path()) + .collect::>(); + let archive = &root_path.join(format!("archive.{}", merge_extensions(&ext, extra_extensions))); + let output_path = root_path.join("archive"); + assert_eq!(false, output_path.exists()); + crate::utils::cargo_bin() .arg("compress") - .arg(&src_files_path) + .args(input_files) .arg(archive) .assert() .success(); - let a = crate::utils::cargo_bin() + crate::utils::cargo_bin() .current_dir(&root_path) .arg("decompress") .arg(archive) .assert() .success(); - let output_path = root_path.join("archive"); assert_eq!(true, output_path.exists(), "Output directory does not exist"); assert_same_directory(src_files_path, output_path, false); } +#[proptest(cases = 25)] +fn no_smart_unpack_with_single_file( + ext: DirectoryExtension, + #[any(size_range(0..1).lift())] extra_extensions: Vec, +) { + let temp_dir = tempdir().unwrap(); + let root_path = temp_dir.path(); + + let src_files_path = root_path.join("src_files"); + fs::create_dir_all(&src_files_path).unwrap(); + + ["file1.txt"] + .into_iter() + .map(|f| src_files_path.join(f)) + .for_each(|path| { + let mut file = fs::File::create(&path).unwrap(); + file.write_all("Some content".as_bytes()).unwrap(); + }); + + let input_files = src_files_path + .read_dir() + .unwrap() + .map(|entry| entry.unwrap().path()) + .collect::>(); + + let archive = &root_path.join(format!("archive.{}", merge_extensions(&ext, extra_extensions))); + + let output_path = root_path.join("archive"); + assert_eq!(false, output_path.exists()); + + crate::utils::cargo_bin() + .arg("compress") + .args(input_files) + .arg(archive) + .assert() + .success(); + + crate::utils::cargo_bin() + .current_dir(&root_path) + .arg("decompress") + .arg("--no-smart-unpack") + .arg(archive) + .assert() + .success(); + + assert_eq!(true, output_path.exists(), "Output directory does not exist"); + + assert_same_directory(src_files_path, output_path, false); +} + +#[proptest(cases = 25)] +fn no_smart_unpack_with_multiple_files( + ext: DirectoryExtension, + #[any(size_range(0..1).lift())] extra_extensions: Vec, +) { + let temp_dir = tempdir().unwrap(); + let root_path = temp_dir.path(); + + let src_files_path = root_path.join("src_files"); + fs::create_dir_all(&src_files_path).unwrap(); + + ["file1.txt", "file2.txt", "file3.txt", "file4.txt", "file5.txt"] + .into_iter() + .map(|f| src_files_path.join(f)) + .for_each(|path| { + let mut file = fs::File::create(&path).unwrap(); + file.write_all("Some content".as_bytes()).unwrap(); + }); + + let input_files = src_files_path + .read_dir() + .unwrap() + .map(|entry| entry.unwrap().path()) + .collect::>(); + + let archive = &root_path.join(format!("archive.{}", merge_extensions(&ext, extra_extensions))); + + let output_path = root_path.join("archive"); + assert_eq!(false, output_path.exists()); + + crate::utils::cargo_bin() + .arg("compress") + .args(input_files) + .arg(archive) + .assert() + .success(); + + crate::utils::cargo_bin() + .current_dir(&root_path) + .arg("decompress") + .arg("--no-smart-unpack") + .arg(archive) + .assert() + .success(); + + assert_eq!(true, output_path.exists(), "Output directory does not exist"); + + assert_same_directory(src_files_path, output_path, false); +} #[proptest(cases = 25)] fn multiple_files_with_disabled_smart_unpack_by_dir(