Skip to content

Commit fe72ec6

Browse files
committed
test: children
1 parent 12fa7c7 commit fe72ec6

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

tests/deduplicate_hardlinks.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ pub use _utils::*;
66

77
use command_extra::CommandExtra;
88
use parallel_disk_usage::{
9+
data_tree::Reflection,
910
json_data::{JsonData, UnitAndTree},
1011
size::Bytes,
1112
};
1213
use pipe_trait::Pipe;
1314
use pretty_assertions::assert_eq;
1415
use std::{
16+
iter,
1517
ops::{Add, Mul},
1618
process::{Command, Stdio},
1719
};
@@ -39,18 +41,42 @@ fn deduplicate_multiple_hardlinks_to_a_single_file() {
3941
.pipe_as_ref(serde_json::from_str::<JsonData>)
4042
.expect("parse stdout as JsonData");
4143

42-
let actual_size = match &json.unit_and_tree {
43-
UnitAndTree::Blocks(_) => panic!("expecting Bytes, but got {:?}", &json.unit_and_tree),
44-
UnitAndTree::Bytes(tree) => tree.size,
44+
let UnitAndTree::Bytes(tree) = &json.unit_and_tree else {
45+
panic!("expecting Bytes but got {:?}", &json.unit_and_tree);
4546
};
4647

47-
let expected_size = workspace
48+
let file_size = workspace
4849
.join("file.txt")
4950
.pipe_as_ref(read_apparent_size)
50-
.add(read_apparent_size(&workspace))
5151
.pipe(Bytes::new);
5252

53+
let actual_size = tree.size;
54+
let expected_size = workspace
55+
.pipe_as_ref(read_apparent_size)
56+
.pipe(Bytes::new)
57+
.add(file_size);
5358
assert_eq!(actual_size, expected_size);
59+
60+
let actual_children = {
61+
let mut children = tree.children.clone();
62+
children.sort_by(|a, b| a.name.cmp(&b.name));
63+
children
64+
};
65+
let expected_children: Vec<_> = {
66+
let links = (0..10).map(|num| format!("link.{num}"));
67+
let node = |name| Reflection {
68+
name,
69+
size: file_size,
70+
children: Vec::new(),
71+
};
72+
"file.txt"
73+
.to_string()
74+
.pipe(iter::once)
75+
.chain(links)
76+
.map(node)
77+
.collect()
78+
};
79+
assert_eq!(actual_children, expected_children);
5480
}
5581

5682
#[test]

0 commit comments

Comments
 (0)