Skip to content

Commit 7862158

Browse files
committed
test: hardlinks summary
1 parent 326540e commit 7862158

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

tests/deduplicate_hardlinks.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub use _utils::*;
77
use command_extra::CommandExtra;
88
use parallel_disk_usage::{
99
data_tree::Reflection,
10+
hardlink::hardlink_list::Summary,
1011
json_data::{JsonData, JsonTree},
1112
size::Bytes,
1213
};
@@ -77,14 +78,28 @@ fn multiple_hardlinks_to_a_single_file_with_deduplication() {
7778
.collect()
7879
};
7980
assert_eq!(actual_children, expected_children);
81+
82+
let actual_shared_summary = tree.shared.summary;
83+
let expected_shared_summary = {
84+
let mut summary = Summary::default();
85+
summary.inodes = 1;
86+
summary.exclusive_inodes = 1;
87+
summary.all_links = 1 + links;
88+
summary.detected_links = 1 + links as usize;
89+
summary.exclusive_links = 1 + links as usize;
90+
summary.shared_size = file_size;
91+
summary.exclusive_shared_size = file_size;
92+
Some(summary)
93+
};
94+
assert_eq!(actual_shared_summary, expected_shared_summary);
8095
}
8196

8297
#[test]
8398
fn multiple_hardlinks_to_a_single_file_without_deduplication() {
8499
let links = 10;
85100
let workspace = SampleWorkspace::multiple_hardlinks_to_a_single_file(100_000, links);
86101

87-
let actual_size = Command::new(PDU)
102+
let tree = Command::new(PDU)
88103
.with_current_dir(&workspace)
89104
.with_arg("--quantity=apparent-size")
90105
.with_arg("--json-output")
@@ -96,17 +111,18 @@ fn multiple_hardlinks_to_a_single_file_without_deduplication() {
96111
.expect("parse stdout as JsonData")
97112
.body
98113
.pipe(JsonTree::<Bytes>::try_from)
99-
.expect("get tree of bytes")
100-
.size;
114+
.expect("get tree of bytes");
101115

116+
let actual_size = tree.size;
102117
let expected_size = workspace
103118
.join("file.txt")
104119
.pipe_as_ref(read_apparent_size)
105120
.mul(links + 1)
106121
.add(read_apparent_size(&workspace))
107122
.pipe(Bytes::new);
108-
109123
assert_eq!(actual_size, expected_size);
124+
125+
assert_eq!(tree.shared.summary, None);
110126
}
111127

112128
#[test]

0 commit comments

Comments
 (0)