Skip to content

Commit 1f0d118

Browse files
committed
ostree-ext/tar/export: add test_unmap_path and update test_map_path to use as_os_str()
We want to compare the actual os_str here, because `Eq` on Paths canonicalizes and removes any trailing '/', but ostree makes a distinction between trailing '/' or not. For example: ``` let p1 = Path::new("/foo"); let p2 = Path::new("/foo/"); assert_eq!(p1, p2); println!("{:?} {:?}", p1.as_os_str(), p2.as_os_str()); ``` Will print: "/foo" "/foo/" Signed-off-by: John Eckersberg <[email protected]>
1 parent db29e2f commit 1f0d118

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

ostree-ext/src/tar/export.rs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -820,19 +820,53 @@ mod tests {
820820

821821
#[test]
822822
fn test_map_path() {
823-
assert_eq!(map_path("/".into()), Utf8Path::new("/"));
824823
assert_eq!(
825-
map_path("./usr/etc/blah".into()),
826-
Utf8Path::new("./etc/blah")
824+
map_path("/".into()).as_os_str(),
825+
Utf8Path::new("/").as_os_str()
826+
);
827+
assert_eq!(
828+
map_path("./usr/etc/blah".into()).as_os_str(),
829+
Utf8Path::new("./etc/blah").as_os_str()
827830
);
828831
for unchanged in ["boot", "usr/bin", "usr/lib/foo"].iter().map(Utf8Path::new) {
829-
assert_eq!(unchanged, map_path_v1(unchanged));
832+
assert_eq!(unchanged.as_os_str(), map_path_v1(unchanged).as_os_str());
830833
}
831834

832-
assert_eq!(Utf8Path::new("etc"), map_path_v1(Utf8Path::new("usr/etc")));
833835
assert_eq!(
834-
Utf8Path::new("etc/foo"),
835-
map_path_v1(Utf8Path::new("usr/etc/foo"))
836+
Utf8Path::new("etc").as_os_str(),
837+
map_path_v1(Utf8Path::new("usr/etc")).as_os_str()
838+
);
839+
assert_eq!(
840+
Utf8Path::new("etc/foo").as_os_str(),
841+
map_path_v1(Utf8Path::new("usr/etc/foo")).as_os_str()
842+
);
843+
}
844+
845+
#[test]
846+
fn test_unmap_path() {
847+
assert_eq!(
848+
unmap_path("/".into()).as_os_str(),
849+
Utf8Path::new("/").as_os_str()
850+
);
851+
assert_eq!(
852+
unmap_path("/etc".into()).as_os_str(),
853+
Utf8Path::new("/etc").as_os_str()
854+
);
855+
assert_eq!(
856+
unmap_path("/usr/etc".into()).as_os_str(),
857+
Utf8Path::new("/usr/etc").as_os_str()
858+
);
859+
assert_eq!(
860+
unmap_path("usr/etc".into()).as_os_str(),
861+
Utf8Path::new("usr/etc").as_os_str()
862+
);
863+
assert_eq!(
864+
unmap_path("etc".into()).as_os_str(),
865+
Utf8Path::new("usr/etc").as_os_str()
866+
);
867+
assert_eq!(
868+
unmap_path("etc/blah".into()).as_os_str(),
869+
Utf8Path::new("usr/etc/blah").as_os_str()
836870
);
837871
}
838872

0 commit comments

Comments
 (0)