Clean up tests

This commit is contained in:
Silas Brack 2026-03-08 13:31:35 +01:00
parent fa4dc716db
commit 5cdaeddc0e
3 changed files with 12 additions and 169 deletions

View file

@ -106,67 +106,19 @@ pub async fn run(args: &Args) {
mod tests {
use super::*;
#[test]
fn test_merge_empty_scans() {
let scans: Vec<(String, Vec<(String, i64)>)> = vec![];
let index = merge_volume_scans(&scans);
assert!(index.is_empty());
}
#[test]
fn test_merge_single_volume() {
let scans = vec![(
"http://vol1".to_string(),
vec![
("key1".to_string(), 100),
("key2".to_string(), 200),
],
)];
let index = merge_volume_scans(&scans);
assert_eq!(index.len(), 2);
assert_eq!(index.get("key1"), Some(&(vec!["http://vol1".to_string()], 100)));
assert_eq!(index.get("key2"), Some(&(vec!["http://vol1".to_string()], 200)));
}
#[test]
fn test_merge_key_on_multiple_volumes() {
let scans = vec![
("http://vol1".to_string(), vec![("shared".to_string(), 100)]),
("http://vol2".to_string(), vec![("shared".to_string(), 100)]),
("http://vol3".to_string(), vec![("shared".to_string(), 100)]),
];
let index = merge_volume_scans(&scans);
assert_eq!(index.len(), 1);
let (volumes, size) = index.get("shared").unwrap();
assert_eq!(volumes.len(), 3);
assert!(volumes.contains(&"http://vol1".to_string()));
assert!(volumes.contains(&"http://vol2".to_string()));
assert!(volumes.contains(&"http://vol3".to_string()));
assert_eq!(*size, 100);
}
#[test]
fn test_merge_takes_max_size() {
// Same key with different sizes on different volumes (corruption or update race)
// Edge case: same key with different sizes across volumes
// (can happen due to incomplete writes or corruption)
// We take the max size as the authoritative value
let scans = vec![
("http://vol1".to_string(), vec![("key".to_string(), 50)]),
("http://vol2".to_string(), vec![("key".to_string(), 200)]),
("http://vol3".to_string(), vec![("key".to_string(), 100)]),
];
let index = merge_volume_scans(&scans);
let (_, size) = index.get("key").unwrap();
let (volumes, size) = index.get("key").unwrap();
assert_eq!(volumes.len(), 3);
assert_eq!(*size, 200, "should take maximum size across volumes");
}
#[test]
fn test_merge_disjoint_keys() {
let scans = vec![
("http://vol1".to_string(), vec![("a".to_string(), 10)]),
("http://vol2".to_string(), vec![("b".to_string(), 20)]),
];
let index = merge_volume_scans(&scans);
assert_eq!(index.len(), 2);
assert_eq!(index.get("a").unwrap().0, vec!["http://vol1".to_string()]);
assert_eq!(index.get("b").unwrap().0, vec!["http://vol2".to_string()]);
}
}