]> git.proxmox.com Git - proxmox-backup.git/blob - tests/pxar.rs
tests/pxar.rs: Make sure the correct pxar binary is run in the tests.
[proxmox-backup.git] / tests / pxar.rs
1 use std::io::{BufRead, BufReader};
2 use std::process::{Command, Stdio};
3
4 // Test if xattrs are correctly archived and restored
5 #[test]
6 fn pxar_create_and_extract() {
7 let src_dir = "./tests/catar_data/test_xattrs_src/";
8 let dest_dir = "./tests/catar_data/test_xattrs_dest/";
9
10 let exec_path = if cfg!(debug_assertions) {
11 "./target/debug/pxar"
12 } else {
13 "./target/release/pxar"
14 };
15
16 println!("run '{} create archive.pxar {}'", exec_path, src_dir);
17
18 Command::new(exec_path)
19 .arg("create")
20 .arg("./tests/archive.pxar")
21 .arg(src_dir)
22 .status()
23 .unwrap_or_else(|err| {
24 panic!("Failed to invoke '{}': {}", exec_path, err)
25 });
26
27 Command::new(exec_path)
28 .arg("extract")
29 .arg("./tests/archive.pxar")
30 .arg(dest_dir)
31 .status()
32 .unwrap_or_else(|err| {
33 panic!("Failed to invoke '{}': {}", exec_path, err)
34 });
35
36 /* Use rsync with --dry-run and --itemize-changes to compare
37 src_dir and dest_dir */
38 let stdout = Command::new("rsync")
39 .arg("--dry-run")
40 .arg("--itemize-changes")
41 .arg("--recursive")
42 .arg("--acls")
43 .arg("--xattrs")
44 .arg("--owner")
45 .arg("--group")
46 .arg("--hard-links")
47 .arg(src_dir)
48 .arg(dest_dir)
49 .stdout(Stdio::piped())
50 .spawn()
51 .unwrap()
52 .stdout
53 .unwrap();
54
55 let reader = BufReader::new(stdout);
56 let linecount = reader.lines().fold(0, |count, _| count + 1 );
57 println!("Rsync listed {} differences to address", linecount);
58
59 // Cleanup archive
60 Command::new("rm")
61 .arg("./tests/archive.pxar")
62 .status()
63 .unwrap_or_else(|err| {
64 panic!("Failed to invoke 'rm': {}", err)
65 });
66
67 // Cleanup destination dir
68 Command::new("rm")
69 .arg("-r")
70 .arg(dest_dir)
71 .status()
72 .unwrap_or_else(|err| {
73 panic!("Failed to invoke 'rm': {}", err)
74 });
75
76 // If source and destination folder contain the same content,
77 // the output of the rsync invokation should yield no lines.
78 if linecount != 0 {
79 panic!("pxar create and extract did not yield the same contents");
80 }
81 }