tape: fix regression tests
This commit is contained in:
parent
368f4c5416
commit
ce5327badc
@ -228,9 +228,10 @@ impl <R: BlockRead> Read for BlockedReader<R> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use anyhow::Error;
|
use anyhow::{bail, Error};
|
||||||
use crate::tape::{
|
use crate::tape::{
|
||||||
TapeWrite,
|
TapeWrite,
|
||||||
|
BlockReadError,
|
||||||
helpers::{EmulateTapeReader, EmulateTapeWriter},
|
helpers::{EmulateTapeReader, EmulateTapeWriter},
|
||||||
file_formats::{
|
file_formats::{
|
||||||
PROXMOX_TAPE_BLOCK_SIZE,
|
PROXMOX_TAPE_BLOCK_SIZE,
|
||||||
@ -260,7 +261,7 @@ mod test {
|
|||||||
|
|
||||||
let reader = &mut &tape_data[..];
|
let reader = &mut &tape_data[..];
|
||||||
let reader = EmulateTapeReader::new(reader);
|
let reader = EmulateTapeReader::new(reader);
|
||||||
let mut reader = BlockedReader::open(reader)?.unwrap();
|
let mut reader = BlockedReader::open(reader)?;
|
||||||
|
|
||||||
let mut read_data = Vec::with_capacity(PROXMOX_TAPE_BLOCK_SIZE);
|
let mut read_data = Vec::with_capacity(PROXMOX_TAPE_BLOCK_SIZE);
|
||||||
reader.read_to_end(&mut read_data)?;
|
reader.read_to_end(&mut read_data)?;
|
||||||
@ -293,8 +294,10 @@ mod test {
|
|||||||
let tape_data = Vec::new();
|
let tape_data = Vec::new();
|
||||||
let reader = &mut &tape_data[..];
|
let reader = &mut &tape_data[..];
|
||||||
let reader = EmulateTapeReader::new(reader);
|
let reader = EmulateTapeReader::new(reader);
|
||||||
let reader = BlockedReader::open(reader)?;
|
match BlockedReader::open(reader) {
|
||||||
assert!(reader.is_none());
|
Err(BlockReadError::EndOfFile) => { /* OK */ },
|
||||||
|
_ => bail!("expected EOF"),
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -313,7 +316,7 @@ mod test {
|
|||||||
|
|
||||||
let reader = &mut &tape_data[..];
|
let reader = &mut &tape_data[..];
|
||||||
let reader = EmulateTapeReader::new(reader);
|
let reader = EmulateTapeReader::new(reader);
|
||||||
let mut reader = BlockedReader::open(reader)?.unwrap();
|
let mut reader = BlockedReader::open(reader)?;
|
||||||
|
|
||||||
let mut data = Vec::with_capacity(PROXMOX_TAPE_BLOCK_SIZE);
|
let mut data = Vec::with_capacity(PROXMOX_TAPE_BLOCK_SIZE);
|
||||||
assert!(reader.read_to_end(&mut data).is_err());
|
assert!(reader.read_to_end(&mut data).is_err());
|
||||||
@ -336,7 +339,7 @@ mod test {
|
|||||||
|
|
||||||
let reader = &mut &tape_data[..];
|
let reader = &mut &tape_data[..];
|
||||||
let reader = EmulateTapeReader::new(reader);
|
let reader = EmulateTapeReader::new(reader);
|
||||||
let mut reader = BlockedReader::open(reader)?.unwrap();
|
let mut reader = BlockedReader::open(reader)?;
|
||||||
|
|
||||||
let mut buf = [0u8; 1];
|
let mut buf = [0u8; 1];
|
||||||
assert_eq!(reader.read(&mut buf)?, 1, "wrong byte count");
|
assert_eq!(reader.read(&mut buf)?, 1, "wrong byte count");
|
||||||
|
Loading…
Reference in New Issue
Block a user