added more helper func, cfg validation and testing
Release / Build and Release (push) Successful in 1m4s

This commit is contained in:
2026-03-31 07:54:21 +02:00
parent c1b3d9134e
commit f640f116ec
14 changed files with 999 additions and 56 deletions
+52
View File
@@ -47,3 +47,55 @@ impl WaybarModule for MemoryModule {
})
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::state::{AppState, MemoryState, mock_state};
#[test]
fn test_memory_normal() {
let state = mock_state(AppState {
memory: MemoryState {
used_gb: 8.0,
total_gb: 32.0,
},
..Default::default()
});
let config = Config::default();
let output = MemoryModule.run(&config, &state, &[]).unwrap();
assert!(output.text.contains("8.00"));
assert!(output.text.contains("32.00"));
assert_eq!(output.class.as_deref(), Some("normal"));
assert_eq!(output.percentage, Some(25)); // 8/32 = 25%
}
#[test]
fn test_memory_high() {
let state = mock_state(AppState {
memory: MemoryState {
used_gb: 26.0,
total_gb: 32.0,
},
..Default::default()
});
let config = Config::default();
let output = MemoryModule.run(&config, &state, &[]).unwrap();
assert_eq!(output.class.as_deref(), Some("high")); // 81%
}
#[test]
fn test_memory_zero_total() {
let state = mock_state(AppState {
memory: MemoryState {
used_gb: 0.0,
total_gb: 0.0,
},
..Default::default()
});
let config = Config::default();
let output = MemoryModule.run(&config, &state, &[]).unwrap();
assert_eq!(output.class.as_deref(), Some("normal"));
assert_eq!(output.percentage, Some(0));
}
}