pub use crate::{
resources_fd_exhaustion_error as fd_exhaustion_error,
resources_inode_capacity as inode_capacity,
resources_signals_fd_exhaustion as signals_fd_exhaustion,
resources_signals_storage_exhaustion as signals_storage_exhaustion,
resources_storage_exhaustion_error as storage_exhaustion_error,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct InodeCapacity {
pub total: u64,
pub free: u64,
}
#[cfg(test)]
mod tests {
use std::io;
use super::*;
#[test]
fn this_hosts_exhaustion_errors_are_recognised() {
assert!(
signals_fd_exhaustion(&fd_exhaustion_error()),
"a descriptor-exhaustion error must be recognised as one"
);
assert!(
signals_storage_exhaustion(&storage_exhaustion_error()),
"a storage-exhaustion error must be recognised as one"
);
}
#[test]
fn the_two_exhaustion_conditions_stay_distinct() {
assert!(!signals_storage_exhaustion(&fd_exhaustion_error()));
assert!(!signals_fd_exhaustion(&storage_exhaustion_error()));
}
#[test]
fn an_error_without_an_os_code_signals_nothing() {
let synthetic = io::Error::other("no operating system said this");
assert!(!signals_fd_exhaustion(&synthetic));
assert!(!signals_storage_exhaustion(&synthetic));
}
#[test]
fn an_unrelated_os_error_signals_nothing() {
let denied = io::Error::new(io::ErrorKind::PermissionDenied, "denied");
assert!(!signals_fd_exhaustion(&denied));
assert!(!signals_storage_exhaustion(&denied));
}
#[test]
fn probing_an_existing_directory_answers_coherently() {
let probed = inode_capacity(&std::env::temp_dir()).expect("probing temp dir must succeed");
if let Some(capacity) = probed {
assert!(capacity.total > 0, "a reported table is never empty");
assert!(
capacity.free <= capacity.total,
"free inodes cannot exceed the table"
);
}
}
}