@@ -6,12 +6,14 @@ pub use _utils::*;
66
77use command_extra:: CommandExtra ;
88use parallel_disk_usage:: {
9+ data_tree:: Reflection ,
910 json_data:: { JsonData , UnitAndTree } ,
1011 size:: Bytes ,
1112} ;
1213use pipe_trait:: Pipe ;
1314use pretty_assertions:: assert_eq;
1415use 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