Skip to content

Commit 54e399f

Browse files
cruesslerByron
authored andcommitted
Add test for entry that does not exist
1 parent 08a86dc commit 54e399f

File tree

1 file changed

+13
-4
lines changed
  • gix-object/tests/object/tree

1 file changed

+13
-4
lines changed

gix-object/tests/object/tree/iter.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn lookup_entry_toplevel() -> crate::Result {
6767
let filename: BString = "bin".into();
6868
let oid = hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
6969

70-
assert_eq!(entry, Entry { mode, filename, oid });
70+
assert_eq!(entry, Some(Entry { mode, filename, oid }));
7171

7272
Ok(())
7373
}
@@ -80,7 +80,16 @@ fn lookup_entry_nested_path() -> crate::Result {
8080
let filename: BString = "a".into();
8181
let oid = hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
8282

83-
assert_eq!(entry, Entry { mode, filename, oid });
83+
assert_eq!(entry, Some(Entry { mode, filename, oid }));
84+
85+
Ok(())
86+
}
87+
88+
#[test]
89+
fn lookup_entry_that_does_not_exist() -> crate::Result {
90+
let entry = utils::lookup_entry_by_path("file/does-not-exist")?;
91+
92+
assert_eq!(entry, None);
8493

8594
Ok(())
8695
}
@@ -95,14 +104,14 @@ mod utils {
95104
Ok(gix_odb::at(root.join(".git/objects"))?)
96105
}
97106

98-
pub(super) fn lookup_entry_by_path(path: &str) -> gix_testtools::Result<gix_object::tree::Entry> {
107+
pub(super) fn lookup_entry_by_path(path: &str) -> gix_testtools::Result<Option<gix_object::tree::Entry>> {
99108
let odb = tree_odb()?;
100109
let root_tree_id = hex_to_id("ff7e7d2aecae1c3fb15054b289a4c58aa65b8646");
101110

102111
let mut buf = Vec::new();
103112
let root_tree = odb.find_tree_iter(&root_tree_id, &mut buf)?;
104113

105114
let mut buf = Vec::new();
106-
Ok(root_tree.lookup_entry_by_path(&odb, &mut buf, path).unwrap().unwrap())
115+
Ok(root_tree.lookup_entry_by_path(&odb, &mut buf, path).unwrap())
107116
}
108117
}

0 commit comments

Comments
 (0)