Skip to content

Commit

Permalink
Add a test to check that saving doesn't corrupt the original package
Browse files Browse the repository at this point in the history
  • Loading branch information
snpefk committed Oct 19, 2024
1 parent f45c095 commit 99be093
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/opensi-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ impl Package {
}
}

pub fn to_bytes(self) -> Result<Vec<u8>, Error> {
pub fn to_bytes(&self) -> Result<Vec<u8>, Error> {
let buffer = Vec::new();
let cursor = io::Cursor::new(buffer);
let mut zip = ZipWriter::new(cursor);
Expand All @@ -531,7 +531,8 @@ impl Package {
zip.start_file("[Content_Types].xml", options)?;
zip.write_all(Self::CONTENT_TYPE_FILE_CONTENT.as_ref())?;

for (key, value) in self.resource.into_iter() {
let resources = &self.resource;
for (key, value) in resources.into_iter() {
zip.start_file(key.extract_key(), options)?;
zip.write_all(&value)?
}
Expand Down
10 changes: 10 additions & 0 deletions crates/opensi-core/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ fn read_package_name() {
let package = Package::open_zip_file(PATH).expect("pack is not found");
assert_eq!(package.name, "SLAM JAM 2".to_owned());
}

#[test]
fn resave_test() {
let package_original = Package::open_zip_file(PATH).expect("Pack is not found");
let bytes = &package_original.to_bytes().expect("Can't serialize package to bytes");
let package_resaved = Package::from_zip_buffer(bytes)
.expect("Can't read package from buffer");

assert_eq!(package_original, package_resaved);
}

0 comments on commit 99be093

Please sign in to comment.