use crate::metrics::disks::{refresh, DiskState};
#[test]
fn test_disk_state_fields_stored_correctly() {
let d = DiskState {
name: "sda1".to_string(),
total: 512_000_000_000,
used: 128_000_000_000,
mount: "/".to_string(),
};
assert_eq!(d.name, "sda1");
assert_eq!(d.total, 512_000_000_000);
assert_eq!(d.used, 128_000_000_000);
assert_eq!(d.mount, "/");
}
#[test]
fn test_disks_refresh_does_not_panic() {
let mut disks: Vec<DiskState> = Vec::new();
refresh(&mut disks);
}
#[test]
fn test_disks_refresh_returns_at_least_one_entry() {
let mut disks: Vec<DiskState> = Vec::new();
refresh(&mut disks);
assert!(!disks.is_empty(), "expected at least one mounted filesystem");
}
#[test]
fn test_disks_refresh_used_lte_total() {
let mut disks: Vec<DiskState> = Vec::new();
refresh(&mut disks);
for d in &disks {
assert!(
d.used <= d.total,
"disk '{}' used ({}) > total ({})",
d.name,
d.used,
d.total
);
}
}
#[test]
fn test_disks_refresh_names_and_mounts_non_empty() {
let mut disks: Vec<DiskState> = Vec::new();
refresh(&mut disks);
for d in &disks {
assert!(!d.name.is_empty(), "disk name must not be empty");
assert!(!d.mount.is_empty(), "disk mount path must not be empty");
}
}