Skip to content

Commit 2d0e08e

Browse files
committed
refactor: longer dot chain
1 parent b77203d commit 2d0e08e

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

tests/deduplicate_hardlinks.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub use _utils::*;
77
use command_extra::CommandExtra;
88
use parallel_disk_usage::{
99
data_tree::Reflection,
10-
json_data::{JsonData, JsonDataBody},
10+
json_data::{JsonData, JsonTree},
1111
size::Bytes,
1212
};
1313
use pipe_trait::Pipe;
@@ -30,7 +30,7 @@ fn deduplicate_multiple_hardlinks_to_a_single_file() {
3030
let links = 10;
3131
let workspace = SampleWorkspace::multiple_hardlinks_to_a_single_file(100_000, links);
3232

33-
let json = Command::new(PDU)
33+
let tree = Command::new(PDU)
3434
.with_current_dir(&workspace)
3535
.with_arg("--quantity=apparent-size")
3636
.with_arg("--deduplicate-hardlinks")
@@ -40,18 +40,18 @@ fn deduplicate_multiple_hardlinks_to_a_single_file() {
4040
.expect("spawn command")
4141
.pipe(stdout_text)
4242
.pipe_as_ref(serde_json::from_str::<JsonData>)
43-
.expect("parse stdout as JsonData");
43+
.expect("parse stdout as JsonData")
44+
.body
45+
.pipe(JsonTree::<Bytes>::try_from)
46+
.expect("get tree of bytes");
4447

45-
let JsonDataBody::Bytes(tree) = &json.body else {
46-
panic!("expecting Bytes but got {:?}", &json.body);
47-
};
48+
let actual_size = tree.size;
4849

4950
let file_size = workspace
5051
.join("file.txt")
5152
.pipe_as_ref(read_apparent_size)
5253
.pipe(Bytes::new);
5354

54-
let actual_size = tree.size;
5555
let expected_size = workspace
5656
.pipe_as_ref(read_apparent_size)
5757
.pipe(Bytes::new)
@@ -85,7 +85,7 @@ fn do_not_deduplicate_multiple_hardlinks_to_a_single_file() {
8585
let links = 10;
8686
let workspace = SampleWorkspace::multiple_hardlinks_to_a_single_file(100_000, links);
8787

88-
let json = Command::new(PDU)
88+
let actual_size = Command::new(PDU)
8989
.with_current_dir(&workspace)
9090
.with_arg("--quantity=apparent-size")
9191
.with_arg("--json-output")
@@ -94,12 +94,11 @@ fn do_not_deduplicate_multiple_hardlinks_to_a_single_file() {
9494
.expect("spawn command")
9595
.pipe(stdout_text)
9696
.pipe_as_ref(serde_json::from_str::<JsonData>)
97-
.expect("parse stdout as JsonData");
98-
99-
let actual_size = match &json.body {
100-
JsonDataBody::Blocks(_) => panic!("expecting Bytes, but got {:?}", &json.body),
101-
JsonDataBody::Bytes(tree) => tree.size,
102-
};
97+
.expect("parse stdout as JsonData")
98+
.body
99+
.pipe(JsonTree::<Bytes>::try_from)
100+
.expect("get tree of bytes")
101+
.size;
103102

104103
let expected_size = workspace
105104
.join("file.txt")

0 commit comments

Comments
 (0)