Expand description
MockTape — an in-memory tape simulation for unit testing.
Real tape hardware is not available in most CI environments, and even when
it is, tests that touch a physical drive are slow and potentially
destructive. MockTape lets the entire higher-level logic of
tape-backup-lib be tested without any hardware.
§Model
A real tape stores data as a sequence of tape files separated by
filemarks. MockTape represents this as a Vec<Vec<u8>>, where each
inner Vec<u8> holds the bytes of one tape file. The current position is
tracked as a (file_index, byte_offset) pair.
§Filemark behaviour
Reading returns Ok(0) (zero bytes) when the read cursor reaches the end
of the current tape file, mirroring the Linux st driver. The filemark is
auto-consumed: file_idx advances automatically, so the next read
call immediately returns data from the following tape file. Do not call
Tape::space_filemarks(1) between consecutive tape-file reads; that
would skip one additional filemark.
§Overwrite semantics
Writing at position (f, b) truncates the current tape file at offset b
and removes all tape files that follow — mirroring the behaviour of a real
tape, where the write head physically overwrites everything from the
current position onwards. This means that rewinding and writing new data
replaces everything that was there before.
Structs§
- Mock
Tape - In-memory tape simulation. See the module documentation for the model and behavioural contract.