Change end-to-end test to use &[u8] instead of Vec<u8>
This commit is contained in:
parent
a8b5210487
commit
19250df9e9
1 changed files with 6 additions and 7 deletions
|
@ -7,20 +7,19 @@ use std::io::Cursor;
|
|||
// This test asserts that after creating a zip file, then reading its contents back out,
|
||||
// the extracted data will *always* be exactly the same as the original data.
|
||||
#[test]
|
||||
fn main() -> zip::result::ZipResult<()> {
|
||||
let buf: &mut Vec<u8> = &mut Vec::new();
|
||||
fn main() {
|
||||
// TODO: The buffer length is tied to the LOREM_IPSUM length currently
|
||||
let buf: &mut [u8] = &mut [0u8; 760];
|
||||
let mut file = Cursor::new(buf);
|
||||
|
||||
write_to_zip_file(&mut file)?;
|
||||
write_to_zip_file(&mut file).expect("file written");
|
||||
|
||||
let file_contents: String = read_zip_file(file).unwrap();
|
||||
|
||||
assert!(file_contents.as_bytes() == LOREM_IPSUM);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_to_zip_file(file: &mut Cursor<&mut Vec<u8>>) -> zip::result::ZipResult<()> {
|
||||
fn write_to_zip_file(file: &mut Cursor<&mut [u8]>) -> zip::result::ZipResult<()> {
|
||||
let mut zip = zip::ZipWriter::new(file);
|
||||
|
||||
zip.add_directory("test/", FileOptions::default())?;
|
||||
|
@ -38,7 +37,7 @@ fn write_to_zip_file(file: &mut Cursor<&mut Vec<u8>>) -> zip::result::ZipResult<
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn read_zip_file(zip_file: Cursor<&mut Vec<u8>>) -> zip::result::ZipResult<String> {
|
||||
fn read_zip_file(zip_file: Cursor<&mut [u8]>) -> zip::result::ZipResult<String> {
|
||||
let mut archive = zip::ZipArchive::new(zip_file).unwrap();
|
||||
|
||||
let mut file = archive.by_name("test/lorem_ipsum.txt")?;
|
||||
|
|
Loading…
Add table
Reference in a new issue