]> git.proxmox.com Git - pxar.git/commitdiff
add some random access tests with hardlinks
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 26 Jun 2020 12:12:57 +0000 (14:12 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 26 Jun 2020 12:12:57 +0000 (14:12 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
tests/simple/fs.rs
tests/simple/main.rs

index 6747ec69d66d99f5dfc479e780b02461b426005d..7b1f5956264cca92662cb90debe7aae893467d24 100644 (file)
@@ -315,7 +315,7 @@ pub fn test_fs() -> Entry {
                         .entry(EntryKind::Directory(vec![
                             Entry::new("bzip2")
                                 .metadata(Metadata::file_builder(0o755))
-                                .entry(EntryKind::File(b"This is an executable".to_vec()))
+                                .entry(EntryKind::File(b"This is the bzip2 executable".to_vec()))
                                 .link_key("/usr/bin/bzip2"),
                             Entry::new("cat")
                                 .metadata(Metadata::file_builder(0o755))
index 337c7fa48305029ee0c7ed3710bf9cd37924a957..c73ca10974de021d6329a3861f80019149644ed3 100644 (file)
@@ -1,10 +1,13 @@
+use std::io::Read;
 use std::path::Path;
 
 use anyhow::{bail, Error};
 
+use pxar::accessor::sync as accessor;
 use pxar::decoder::sync as decoder;
 use pxar::encoder::sync as encoder;
 use pxar::encoder::SeqWrite;
+use pxar::EntryKind as PxarEntryKind;
 
 mod fs;
 
@@ -45,4 +48,40 @@ fn test1() {
         fs::Entry::decode_from(&mut decoder).expect("failed to decode previously encoded archive");
 
     assert_eq!(test_fs, decoded_fs);
+
+    let accessor = accessor::Accessor::new(&file[..], file.len() as u64)
+        .expect("failed to create random access reader for encoded archive");
+
+    check_bunzip2(&accessor);
+}
+
+fn check_bunzip2(accessor: &accessor::Accessor<&[u8]>) {
+    let root = accessor
+        .open_root()
+        .expect("failed to open root of encoded archive");
+
+    let bunzip2 = root
+        .lookup("usr/bin/bunzip2")
+        .expect("failed to lookup usr/bin/bunzip2 in test data")
+        .expect("missing usr/bin/bunzip2 in test data");
+    match bunzip2.kind() {
+        PxarEntryKind::Hardlink(link) => assert_eq!(link.as_os_str(), "/usr/bin/bzip2"),
+        _ => panic!("expected usr/bin/bunzip2 in test data to be a hardlink"),
+    }
+    let bzip2 = accessor
+        .follow_hardlink(&bunzip2)
+        .expect("failed to follow usr/bin/bunzip2 hardlink in test data");
+    assert!(bzip2.is_regular_file());
+    let mut content = String::new();
+    let len = bzip2
+        .contents()
+        .expect("failed to get contents of bzip2 file")
+        .read_to_string(&mut content)
+        .expect("failed to read bzip2 file into a string");
+    match bzip2.kind() {
+        PxarEntryKind::File { size, .. } => assert_eq!(len as u64, *size),
+        _ => panic!("expected usr/bin/bzip2 in test data to be a regular file"),
+    }
+
+    assert_eq!(content, "This is the bzip2 executable");
 }