2024-03-31 00:27:56 +03:00
|
|
|
use std::{fs::File, io::Write};
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-03-31 00:27:56 +03:00
|
|
|
use gitbutler_core::zip::Zipper;
|
2024-03-31 00:25:36 +03:00
|
|
|
use tempfile::tempdir;
|
2024-03-31 00:27:56 +03:00
|
|
|
use walkdir::WalkDir;
|
2024-03-31 00:25:36 +03:00
|
|
|
|
2024-03-29 12:04:26 +03:00
|
|
|
#[test]
|
|
|
|
fn zip_dir() {
|
|
|
|
let tmp_dir = tempdir().unwrap();
|
|
|
|
let tmp_dir_path = tmp_dir.path();
|
|
|
|
let file_path = tmp_dir_path.join("test.txt");
|
|
|
|
let mut file = File::create(file_path).unwrap();
|
|
|
|
file.write_all(b"test").unwrap();
|
|
|
|
|
|
|
|
let zipper_cache = tempdir().unwrap();
|
|
|
|
let zipper = Zipper::new(zipper_cache.path());
|
|
|
|
let zip_file_path = zipper.zip(tmp_dir).unwrap();
|
|
|
|
assert!(zip_file_path.exists());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn zip_file() {
|
|
|
|
let tmp_dir = tempdir().unwrap();
|
|
|
|
let tmp_dir_path = tmp_dir.path();
|
|
|
|
let file_path = tmp_dir_path.join("test.txt");
|
|
|
|
let mut file = File::create(&file_path).unwrap();
|
|
|
|
file.write_all(b"test").unwrap();
|
|
|
|
|
|
|
|
let zipper_cache = tempdir().unwrap();
|
|
|
|
let zipper = Zipper::new(zipper_cache.path());
|
|
|
|
zipper.zip(file_path).unwrap_err();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn zip_once() {
|
|
|
|
let tmp_dir = tempdir().unwrap();
|
|
|
|
let tmp_dir_path = tmp_dir.path();
|
|
|
|
let file_path = tmp_dir_path.join("test.txt");
|
|
|
|
let mut file = File::create(file_path).unwrap();
|
|
|
|
file.write_all(b"test").unwrap();
|
|
|
|
|
|
|
|
let zipper_cache = tempdir().unwrap();
|
|
|
|
let zipper = Zipper::new(zipper_cache.path());
|
|
|
|
assert_eq!(zipper.zip(&tmp_dir).unwrap(), zipper.zip(&tmp_dir).unwrap());
|
|
|
|
assert_eq!(WalkDir::new(tmp_dir).into_iter().count(), 1);
|
|
|
|
}
|