@@ -512,9 +512,11 @@ mod find {
512512 }
513513
514514 #[ test]
515- fn empty_blob_can_always_be_found ( ) -> crate :: Result {
515+ fn empty_blob_can_be_found_if_it_exists ( ) -> crate :: Result {
516516 let repo = basic_repo ( ) ?;
517517 let empty_blob = gix:: hash:: ObjectId :: empty_blob ( repo. object_hash ( ) ) ;
518+
519+ // The basic_repo fixture contains an empty blob, so these should work
518520 assert_eq ! ( repo. find_object( empty_blob) ?. into_blob( ) . data. len( ) , 0 ) ;
519521 assert ! ( repo. has_object( empty_blob) ) ;
520522 assert_eq ! (
@@ -523,7 +525,7 @@ mod find {
523525 kind: gix_object:: Kind :: Blob ,
524526 size: 0 ,
525527 } ,
526- "empty blob is considered a loose object "
528+ "empty blob is found when it exists in the repository "
527529 ) ;
528530 assert_eq ! (
529531 repo. try_find_object( empty_blob) ?
@@ -539,10 +541,22 @@ mod find {
539541 kind: gix_object:: Kind :: Blob ,
540542 size: 0 ,
541543 } ) ,
542- "empty blob is considered a loose object "
544+ "empty blob is found when it exists in the repository "
543545 ) ;
544546 Ok ( ( ) )
545547 }
548+
549+ #[ test]
550+ fn empty_blob_method_creates_correct_object ( ) -> crate :: Result {
551+ let repo = basic_repo ( ) ?;
552+ let empty_blob = repo. empty_blob ( ) ;
553+
554+ // The empty_blob method should create an object with the right ID and empty data
555+ assert_eq ! ( empty_blob. id, gix:: hash:: ObjectId :: empty_blob( repo. object_hash( ) ) ) ;
556+ assert_eq ! ( empty_blob. data. len( ) , 0 ) ;
557+
558+ Ok ( ( ) )
559+ }
546560}
547561
548562#[ test]
@@ -551,33 +565,22 @@ fn empty_objects_are_always_present_but_not_in_plumbing() -> crate::Result {
551565 let empty_blob_id = gix:: hash:: ObjectId :: empty_blob ( repo. object_hash ( ) ) ;
552566
553567 assert ! (
554- repo. has_object( empty_blob_id) ,
555- "empty object is always present even if it's not "
568+ ! repo. has_object( empty_blob_id) ,
569+ "empty blob is not present unless it actually exists "
556570 ) ;
557571 assert ! ( !repo. objects. contains( & empty_blob_id) ) ;
558572
559- let header = repo. find_header ( empty_blob_id) ?;
560- assert_eq ! ( header. kind( ) , gix_object:: Kind :: Blob ) ;
561- assert_eq ! ( header. size( ) , 0 ) ;
573+ // Empty blob should cause errors when it doesn't exist
574+ assert ! ( repo. find_header( empty_blob_id) . is_err( ) ) ;
562575 assert_eq ! ( repo. objects. try_header( & empty_blob_id) ?, None ) ;
563576
564- let header = repo. try_find_header ( empty_blob_id) ?. expect ( "should find header" ) ;
565- assert_eq ! ( header. kind( ) , gix_object:: Kind :: Blob ) ;
566- assert_eq ! ( header. size( ) , 0 ) ;
567-
568- let obj = repo. find_object ( empty_blob_id) ?;
569- assert_eq ! ( obj. kind, gix_object:: Kind :: Blob ) ;
570- assert_eq ! ( obj. data. len( ) , 0 ) ;
577+ assert_eq ! ( repo. try_find_header( empty_blob_id) ?, None ) ;
578+ assert ! ( repo. find_object( empty_blob_id) . is_err( ) ) ;
571579
572580 let mut buf = Vec :: new ( ) ;
573581 assert_eq ! ( repo. objects. try_find( & empty_blob_id, & mut buf) ?, None ) ;
574582
575- let obj = repo. try_find_object ( empty_blob_id) ?. expect ( "should find object" ) ;
576- assert_eq ! ( obj. kind, gix_object:: Kind :: Blob ) ;
577- assert_eq ! ( obj. data. len( ) , 0 ) ;
578-
579- let blob = obj. try_into_blob ( ) ?;
580- assert_eq ! ( blob. data. len( ) , 0 ) ;
583+ assert ! ( repo. try_find_object( empty_blob_id) ?. is_none( ) ) ;
581584
582585 Ok ( ( ) )
583586}
0 commit comments