gitbutler/crates/gitbutler-core/tests/zip/mod.rs
Sebastian Thiel 6224c70695
fix integration test structure to assure tests run only once.
Previously, tests were included by `app.rs` which is the entrypoint
for intgration tests, but there were also loose `.rs` files which
each count as separate test (with their own binary).

This wasn't intended and I don't know what happened there,
so now `core.rs` is the entrypoint.
2024-05-28 13:25:45 +02:00

47 lines
1.4 KiB
Rust

use std::{fs::File, io::Write};
use gitbutler_core::zip::Zipper;
use tempfile::tempdir;
use walkdir::WalkDir;
#[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);
}