Skip to content

Commit

Permalink
Added integration tests for directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Le0X8 committed Jul 13, 2024
1 parent 5f74b30 commit b542d44
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
Binary file added tests/samples/zip/002.zip
Binary file not shown.
60 changes: 58 additions & 2 deletions tests/zip.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use corelib::{self, File};

#[test]
fn metadata_000() {
fn sample_000() {
let mut file = File::new("tests/samples/zip/000.zip");

let metadata = corelib::formats::zip::parser::metadata(&mut file);
Expand All @@ -21,7 +21,7 @@ fn metadata_000() {
}

#[test]
fn metadata_001() {
fn sample_001() {
let mut file = File::new("tests/samples/zip/001.zip");

let metadata = corelib::formats::zip::parser::metadata(&mut file);
Expand Down Expand Up @@ -67,3 +67,59 @@ fn metadata_001() {

std::fs::remove_dir_all("tests/samples/zip/001").unwrap();
}

#[test]
fn sample_002() {
let mut file = File::new("tests/samples/zip/002.zip");

let metadata = corelib::formats::zip::parser::metadata(&mut file);
assert_eq!(metadata.files.len(), 3);
assert_eq!(metadata.files[0].file.path, "test/");
assert_eq!(metadata.files[0].file.size, 0);
assert_eq!(metadata.files[0].compression, "stored");
assert_eq!(metadata.files[0].uncompressed_size, 0);
assert_eq!(
metadata.files[0].file.modified.to_rfc3339(),
"2024-07-13T14:27:00+00:00"
);
assert_eq!(metadata.files[1].file.path, "test/test.txt");
assert_eq!(metadata.files[1].file.size, 14);
assert_eq!(metadata.files[1].compression, "stored");
assert_eq!(metadata.files[1].uncompressed_size, 14);
assert_eq!(
metadata.files[1].file.modified.to_rfc3339(),
"2024-07-13T14:26:48+00:00"
);
assert_eq!(metadata.files[2].file.path, "test.txt");
assert_eq!(metadata.files[2].file.size, 14);
assert_eq!(metadata.files[2].compression, "stored");
assert_eq!(metadata.files[2].uncompressed_size, 14);
assert_eq!(
metadata.files[2].file.modified.to_rfc3339(),
"2024-07-13T14:26:48+00:00"
);

let test_txt = corelib::formats::zip::parser::get_file(&mut file, &metadata.files[1]);
assert_eq!(String::from_utf8(test_txt).unwrap(), "Hello, world!\n");
let test_test_txt = corelib::formats::zip::parser::get_file(&mut file, &metadata.files[2]);
assert_eq!(String::from_utf8(test_test_txt).unwrap(), "Hello, world!\n");

std::fs::create_dir_all("tests/samples/zip/002").unwrap();

corelib::formats::zip::parser::extract(&mut file, metadata.files, 1024, &|path| {
format!("tests/samples/zip/002/{}", path)
});

let extracted_test_txt = std::fs::read("tests/samples/zip/002/test.txt").unwrap();
assert_eq!(
String::from_utf8(extracted_test_txt).unwrap(),
"Hello, world!\n"
);
let extracted_test2_txt = std::fs::read("tests/samples/zip/002/test/test.txt").unwrap();
assert_eq!(
String::from_utf8(extracted_test2_txt).unwrap(),
"Hello, world!\n"
);

std::fs::remove_dir_all("tests/samples/zip/002").unwrap();
}

0 comments on commit b542d44

Please sign in to comment.