@@ -512,9 +512,11 @@ mod find {
512
512
}
513
513
514
514
#[ test]
515
- fn empty_blob_can_always_be_found ( ) -> crate :: Result {
515
+ fn empty_blob_can_be_found_if_it_exists ( ) -> crate :: Result {
516
516
let repo = basic_repo ( ) ?;
517
517
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
518
520
assert_eq ! ( repo. find_object( empty_blob) ?. into_blob( ) . data. len( ) , 0 ) ;
519
521
assert ! ( repo. has_object( empty_blob) ) ;
520
522
assert_eq ! (
@@ -523,7 +525,7 @@ mod find {
523
525
kind: gix_object:: Kind :: Blob ,
524
526
size: 0 ,
525
527
} ,
526
- "empty blob is considered a loose object "
528
+ "empty blob is found when it exists in the repository "
527
529
) ;
528
530
assert_eq ! (
529
531
repo. try_find_object( empty_blob) ?
@@ -539,10 +541,22 @@ mod find {
539
541
kind: gix_object:: Kind :: Blob ,
540
542
size: 0 ,
541
543
} ) ,
542
- "empty blob is considered a loose object "
544
+ "empty blob is found when it exists in the repository "
543
545
) ;
544
546
Ok ( ( ) )
545
547
}
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
+ }
546
560
}
547
561
548
562
#[ test]
@@ -551,33 +565,22 @@ fn empty_objects_are_always_present_but_not_in_plumbing() -> crate::Result {
551
565
let empty_blob_id = gix:: hash:: ObjectId :: empty_blob ( repo. object_hash ( ) ) ;
552
566
553
567
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 "
556
570
) ;
557
571
assert ! ( !repo. objects. contains( & empty_blob_id) ) ;
558
572
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( ) ) ;
562
575
assert_eq ! ( repo. objects. try_header( & empty_blob_id) ?, None ) ;
563
576
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( ) ) ;
571
579
572
580
let mut buf = Vec :: new ( ) ;
573
581
assert_eq ! ( repo. objects. try_find( & empty_blob_id, & mut buf) ?, None ) ;
574
582
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( ) ) ;
581
584
582
585
Ok ( ( ) )
583
586
}
0 commit comments