pub struct SimFs { /* private fields */ }Expand description
Deterministic in-memory filesystem with fault injection.
Each operation checks the configured fault rules. If a rule matches, the simulation RNG decides (based on probability) whether to inject the fault.
use vortex_fs::{SimFs, VortexFs};
let mut fs = SimFs::new(42);
fs.create_dir_all("/data/logs").unwrap();
fs.write_file("/data/logs/app.log", b"hello").unwrap();
assert!(fs.exists("/data/logs/app.log"));
assert_eq!(fs.read_file("/data/logs/app.log").unwrap(), b"hello");Implementations§
Source§impl SimFs
impl SimFs
Sourcepub fn with_faults(seed: u64, config: FsFaultConfig) -> Self
pub fn with_faults(seed: u64, config: FsFaultConfig) -> Self
Create with fault injection configuration.
Sourcepub fn set_fault_config(&mut self, config: FsFaultConfig)
pub fn set_fault_config(&mut self, config: FsFaultConfig)
Set the fault configuration.
Sourcepub fn total_bytes_written(&self) -> u64
pub fn total_bytes_written(&self) -> u64
Get total bytes written so far.
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Number of entries (files + directories).
Trait Implementations§
Source§impl VortexFs for SimFs
impl VortexFs for SimFs
Source§fn read_file(&self, path: &str) -> VortexFsResult<Vec<u8>>
fn read_file(&self, path: &str) -> VortexFsResult<Vec<u8>>
Read the entire contents of a file.
Source§fn write_file(&mut self, path: &str, data: &[u8]) -> VortexFsResult<()>
fn write_file(&mut self, path: &str, data: &[u8]) -> VortexFsResult<()>
Write data to a file (creates or overwrites).
Source§fn append_file(&mut self, path: &str, data: &[u8]) -> VortexFsResult<()>
fn append_file(&mut self, path: &str, data: &[u8]) -> VortexFsResult<()>
Append data to a file (creates if not exists).
Source§fn remove_file(&mut self, path: &str) -> VortexFsResult<()>
fn remove_file(&mut self, path: &str) -> VortexFsResult<()>
Remove a file.
Source§fn create_dir_all(&mut self, path: &str) -> VortexFsResult<()>
fn create_dir_all(&mut self, path: &str) -> VortexFsResult<()>
Create a directory (and all parent directories).
Source§fn remove_dir(&mut self, path: &str) -> VortexFsResult<()>
fn remove_dir(&mut self, path: &str) -> VortexFsResult<()>
Remove an empty directory.
Source§fn read_dir(&self, path: &str) -> VortexFsResult<Vec<String>>
fn read_dir(&self, path: &str) -> VortexFsResult<Vec<String>>
List the entries in a directory.
Source§fn metadata(&self, path: &str) -> VortexFsResult<FileMetadata>
fn metadata(&self, path: &str) -> VortexFsResult<FileMetadata>
Get metadata about a file or directory.
Auto Trait Implementations§
impl Freeze for SimFs
impl RefUnwindSafe for SimFs
impl Send for SimFs
impl Sync for SimFs
impl Unpin for SimFs
impl UnsafeUnpin for SimFs
impl UnwindSafe for SimFs
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more