Watch
0
0
Fork
You've already forked hyperhive
0

name what is true in three more comments, and test the old event log's removal

This commit is contained in:
iris 2026-11-16 05:13:19 +01:00 • committed by mara
commit 49ee678117

View file

@ -170,3 +170,44 @@ fn remove_old_event_log(harness: &Path) {
}
}
}
#[cfg(test)]
mod tests {
use super::remove_old_event_log;
#[test]
fn the_old_event_log_and_its_wal_files_are_removed_and_nothing_else() {
let dir = tempfile::tempdir().unwrap();
for name in [
"hyperhive-events.sqlite",
"hyperhive-events.sqlite-wal",
"hyperhive-events.sqlite-shm",
"hyperhive-turn-stats.sqlite",
] {
std::fs::write(dir.path().join(name), b"x").unwrap();
}
remove_old_event_log(dir.path());
assert!(!dir.path().join("hyperhive-events.sqlite").exists());
assert!(!dir.path().join("hyperhive-events.sqlite-wal").exists());
assert!(!dir.path().join("hyperhive-events.sqlite-shm").exists());
assert!(dir.path().join("hyperhive-turn-stats.sqlite").exists());
}
#[test]
fn a_harness_dir_without_the_log_is_left_alone() {
let dir = tempfile::tempdir().unwrap();
remove_old_event_log(dir.path());
assert_eq!(std::fs::read_dir(dir.path()).unwrap().count(), 0);
}
/// A removal that fails for another reason is logged and the rest still go.
#[test]
fn a_failed_removal_does_not_stop_the_others() {
let dir = tempfile::tempdir().unwrap();
std::fs::create_dir(dir.path().join("hyperhive-events.sqlite")).unwrap();
std::fs::write(dir.path().join("hyperhive-events.sqlite-wal"), b"x").unwrap();
remove_old_event_log(dir.path());
assert!(dir.path().join("hyperhive-events.sqlite").is_dir());
assert!(!dir.path().join("hyperhive-events.sqlite-wal").exists());
}
}