@@ -65,6 +65,7 @@ impl<Size> HardlinkList<Size> {
6565/// <!-- Should have been `std::os::unix::fs::MetadataExt::ino` but it would error on Windows -->
6666/// [ino]: https://doc.rust-lang.org/std/os/unix/fs/trait.MetadataExt.html#tymethod.ino
6767#[ derive( Debug , Display , Error ) ]
68+ #[ cfg_attr( test, derive( PartialEq , Eq ) ) ]
6869#[ display( bound( Size : Debug ) ) ]
6970#[ display( "Size for inode {ino} changed from {recorded:?} to {detected:?}" ) ]
7071pub struct SizeConflictError < Size > {
@@ -79,6 +80,7 @@ pub struct SizeConflictError<Size> {
7980/// [nlink]: https://doc.rust-lang.org/std/os/unix/fs/trait.MetadataExt.html#tymethod.nlink
8081/// [ino]: https://doc.rust-lang.org/std/os/unix/fs/trait.MetadataExt.html#tymethod.ino
8182#[ derive( Debug , Display , Error ) ]
83+ #[ cfg_attr( test, derive( PartialEq , Eq ) ) ]
8284#[ display( "Number of links of inode {ino} changed from {recorded:?} to {detected:?}" ) ]
8385pub struct NumberOfLinksConflictError {
8486 pub ino : InodeNumber ,
@@ -88,6 +90,7 @@ pub struct NumberOfLinksConflictError {
8890
8991/// Error that occurs when it fails to add an item to [`HardlinkList`].
9092#[ derive( Debug , Display , Error ) ]
93+ #[ cfg_attr( test, derive( PartialEq , Eq ) ) ]
9194#[ display( bound( Size : Debug ) ) ]
9295#[ non_exhaustive]
9396pub enum AddError < Size > {
@@ -144,7 +147,7 @@ where
144147
145148#[ cfg( test) ]
146149mod tests {
147- use super :: HardlinkList ;
150+ use super :: { AddError , HardlinkList , NumberOfLinksConflictError , SizeConflictError } ;
148151 use crate :: size:: Bytes ;
149152 use pipe_trait:: Pipe ;
150153 use pretty_assertions:: { assert_eq, assert_ne} ;
@@ -261,4 +264,36 @@ mod tests {
261264 assert_ne ! ( a, b) ;
262265 assert_ne ! ( b, a) ;
263266 }
267+
268+ #[ test]
269+ fn detect_size_change ( ) {
270+ let list = HardlinkList :: < Bytes > :: new ( ) ;
271+ list. add ( 123 . into ( ) , 100 . into ( ) , 1 , "a" . as_ref ( ) )
272+ . expect ( "add the first path" ) ;
273+ let actual = list
274+ . add ( 123 . into ( ) , 110 . into ( ) , 1 , "b" . as_ref ( ) )
275+ . expect_err ( "add the second path" ) ;
276+ let expected = AddError :: SizeConflict ( SizeConflictError {
277+ ino : 123 . into ( ) ,
278+ recorded : 100 . into ( ) ,
279+ detected : 110 . into ( ) ,
280+ } ) ;
281+ assert_eq ! ( actual, expected) ;
282+ }
283+
284+ #[ test]
285+ fn detect_number_of_links_change ( ) {
286+ let list = HardlinkList :: < Bytes > :: new ( ) ;
287+ list. add ( 123 . into ( ) , 100 . into ( ) , 1 , "a" . as_ref ( ) )
288+ . expect ( "add the first path" ) ;
289+ let actual = list
290+ . add ( 123 . into ( ) , 100 . into ( ) , 2 , "b" . as_ref ( ) )
291+ . expect_err ( "add the second path" ) ;
292+ let expected = AddError :: NumberOfLinksConflict ( NumberOfLinksConflictError {
293+ ino : 123 . into ( ) ,
294+ recorded : 1 ,
295+ detected : 2 ,
296+ } ) ;
297+ assert_eq ! ( actual, expected) ;
298+ }
264299}
0 commit comments