test(instance_logs): add buffer push, get, clear, and max-lines tests
This commit is contained in:
1 parent
3ad0652b27
commit
f713c6e752
1 file changed
+46
@@ -29,3 +29,49 @@ pub fn clear(name: &str) {
|
||||
logs.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn push_and_get_all() {
|
||||
let name = "test_push_get";
|
||||
push(name, "line1");
|
||||
push(name, "line2");
|
||||
let lines = get_all(name);
|
||||
assert!(lines.contains(&"line1".to_string()));
|
||||
assert!(lines.contains(&"line2".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_all_missing_instance_returns_empty() {
|
||||
let lines = get_all("nonexistent_instance_xyz");
|
||||
assert!(lines.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clear_removes_instance() {
|
||||
let name = "test_clear";
|
||||
push(name, "data");
|
||||
assert!(!get_all(name).is_empty());
|
||||
clear(name);
|
||||
assert!(get_all(name).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clear_nonexistent_is_noop() {
|
||||
clear("never_existed_xyz");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buffer_respects_max_lines() {
|
||||
let name = "test_max_lines";
|
||||
for i in 0..(MAX_LINES + 100) {
|
||||
push(name, format!("line-{i}"));
|
||||
}
|
||||
let lines = get_all(name);
|
||||
assert_eq!(lines.len(), MAX_LINES);
|
||||
assert!(lines.last().unwrap().contains(&format!("{}", MAX_LINES + 99)));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user