]> git.proxmox.com Git - proxmox-backup.git/blame - tests/pxar.rs
unbreak build
[proxmox-backup.git] / tests / pxar.rs
CommitLineData
015c5f6b
CE
1use std::io::{BufRead, BufReader};
2use std::process::{Command, Stdio};
3
4// Test if xattrs are correctly archived and restored
5#[test]
6fn 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
fe61cc10
CE
10 let exec_path = if cfg!(debug_assertions) {
11 "./target/debug/pxar"
12 } else {
13 "./target/release/pxar"
14 };
015c5f6b 15
fe61cc10
CE
16 println!("run '{} create archive.pxar {}'", exec_path, src_dir);
17
18 Command::new(exec_path)
015c5f6b
CE
19 .arg("create")
20 .arg("./tests/archive.pxar")
21 .arg(src_dir)
22 .status()
23 .unwrap_or_else(|err| {
fe61cc10 24 panic!("Failed to invoke '{}': {}", exec_path, err)
015c5f6b
CE
25 });
26
840616ca
FG
27 println!("run '{} extract archive.pxar {}'", exec_path, dest_dir);
28
fe61cc10 29 Command::new(exec_path)
015c5f6b
CE
30 .arg("extract")
31 .arg("./tests/archive.pxar")
bdf0d82c 32 .arg("--target")
015c5f6b
CE
33 .arg(dest_dir)
34 .status()
35 .unwrap_or_else(|err| {
fe61cc10 36 panic!("Failed to invoke '{}': {}", exec_path, err)
015c5f6b
CE
37 });
38
840616ca 39 println!("run 'rsync --dry-run --itemize-changes --archive {} {}' to verify'", src_dir, dest_dir);
015c5f6b
CE
40 /* Use rsync with --dry-run and --itemize-changes to compare
41 src_dir and dest_dir */
42 let stdout = Command::new("rsync")
43 .arg("--dry-run")
44 .arg("--itemize-changes")
4204e535 45 .arg("--archive")
015c5f6b
CE
46 .arg(src_dir)
47 .arg(dest_dir)
48 .stdout(Stdio::piped())
49 .spawn()
50 .unwrap()
51 .stdout
52 .unwrap();
53
54 let reader = BufReader::new(stdout);
840616ca
FG
55 let mut line_iter = reader.lines().map(|l| l.unwrap());
56 let mut linecount = 0;
57 while let Some(curr) = line_iter.next() {
58 println!("{}", curr);
59 linecount += 1;
60 }
015c5f6b
CE
61 println!("Rsync listed {} differences to address", linecount);
62
63 // Cleanup archive
64 Command::new("rm")
65 .arg("./tests/archive.pxar")
66 .status()
67 .unwrap_or_else(|err| {
68 panic!("Failed to invoke 'rm': {}", err)
69 });
70
71 // Cleanup destination dir
72 Command::new("rm")
73 .arg("-r")
74 .arg(dest_dir)
75 .status()
76 .unwrap_or_else(|err| {
77 panic!("Failed to invoke 'rm': {}", err)
78 });
79
80 // If source and destination folder contain the same content,
81 // the output of the rsync invokation should yield no lines.
82 if linecount != 0 {
83 panic!("pxar create and extract did not yield the same contents");
84 }
85}