]> git.proxmox.com Git - proxmox-backup.git/commitdiff
tests/pxar.rs: Integrity test for pxar
authorChristian Ebner <c.ebner@proxmox.com>
Mon, 20 May 2019 16:08:56 +0000 (18:08 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 21 May 2019 04:26:34 +0000 (06:26 +0200)
Test the integrity of the restored folder content of data previously archived with pxar

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
tests/catar_data/test_xattrs_src/file.txt [new file with mode: 0644]
tests/pxar.rs [new file with mode: 0644]

diff --git a/tests/catar_data/test_xattrs_src/file.txt b/tests/catar_data/test_xattrs_src/file.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/pxar.rs b/tests/pxar.rs
new file mode 100644 (file)
index 0000000..d440ee6
--- /dev/null
@@ -0,0 +1,75 @@
+use std::io::{BufRead, BufReader};
+use std::process::{Command, Stdio};
+
+// Test if xattrs are correctly archived and restored
+#[test]
+fn pxar_create_and_extract() {
+    let src_dir = "./tests/catar_data/test_xattrs_src/";
+    let dest_dir = "./tests/catar_data/test_xattrs_dest/";
+
+    println!("run pxar create archive.pxar '{}'", src_dir);
+
+    Command::new("./target/debug/pxar")
+        .arg("create")
+        .arg("./tests/archive.pxar")
+        .arg(src_dir)
+        .status()
+        .unwrap_or_else(|err| {
+            panic!("Failed to invoke './target/debug/pxar': {}", err)
+        });
+
+    Command::new("./target/debug/pxar")
+        .arg("extract")
+        .arg("./tests/archive.pxar")
+        .arg(dest_dir)
+        .status()
+        .unwrap_or_else(|err| {
+            panic!("Failed to invoke './target/debug/pxar': {}", err)
+        });
+
+    /* Use rsync with --dry-run and --itemize-changes to compare
+       src_dir and dest_dir */
+    let stdout = Command::new("rsync")
+        .arg("--dry-run")
+        .arg("--itemize-changes")
+        .arg("--recursive")
+        .arg("--acls")
+        .arg("--xattrs")
+        .arg("--owner")
+        .arg("--group")
+        .arg("--hard-links")
+        .arg(src_dir)
+        .arg(dest_dir)
+        .stdout(Stdio::piped())
+        .spawn()
+        .unwrap()
+        .stdout
+        .unwrap();
+
+    let reader = BufReader::new(stdout);
+    let linecount = reader.lines().fold(0, |count, _| count + 1 );
+    println!("Rsync listed {} differences to address", linecount);
+
+    // Cleanup archive
+    Command::new("rm")
+        .arg("./tests/archive.pxar")
+        .status()
+        .unwrap_or_else(|err| {
+            panic!("Failed to invoke 'rm': {}", err)
+        });
+
+    // Cleanup destination dir
+    Command::new("rm")
+        .arg("-r")
+        .arg(dest_dir)
+        .status()
+        .unwrap_or_else(|err| {
+            panic!("Failed to invoke 'rm': {}", err)
+        });
+
+    // If source and destination folder contain the same content,
+    // the output of the rsync invokation should yield no lines.
+    if linecount != 0 {
+        panic!("pxar create and extract did not yield the same contents");
+    }
+}