#[cfg(test)]
mod store_dedup_tests {
use crate::store::ECStore;
#[test]
fn test_deduplicate_disks() {
let mut disks = Vec::new();
disks.push(rustfs_madmin::Disk {
endpoint: "node1".to_string(),
drive_path: "/mnt/disk1".to_string(),
pool_index: 0,
set_index: 0,
disk_index: 0,
total_space: 1_000_000_000_000,
..Default::default()
});
for _ in 0..231 {
disks.push(rustfs_madmin::Disk {
endpoint: "node1".to_string(),
drive_path: "/mnt/disk1".to_string(),
pool_index: 0,
set_index: 0,
disk_index: 0,
total_space: 1_000_000_000_000,
..Default::default()
});
}
assert_eq!(disks.len(), 232);
let deduped = ECStore::deduplicate_disks(disks);
assert_eq!(deduped.len(), 1, "Should deduplicate to 1 unique disk");
}
#[test]
fn test_deduplicate_multiple_unique_disks() {
let disks = vec![
rustfs_madmin::Disk {
endpoint: "node1".to_string(),
drive_path: "/mnt/disk1".to_string(),
pool_index: 0,
set_index: 0,
disk_index: 0,
total_space: 1_000_000_000_000,
..Default::default()
},
rustfs_madmin::Disk {
endpoint: "node1".to_string(),
drive_path: "/mnt/disk2".to_string(),
pool_index: 0,
set_index: 0,
disk_index: 1,
total_space: 1_000_000_000_000,
..Default::default()
},
rustfs_madmin::Disk {
endpoint: "node1".to_string(),
drive_path: "/mnt/disk1".to_string(),
pool_index: 0,
set_index: 0,
disk_index: 0,
total_space: 1_000_000_000_000,
..Default::default()
},
];
let deduped = ECStore::deduplicate_disks(disks);
assert_eq!(deduped.len(), 2, "Should keep 2 unique disks");
}
}