]> git.proxmox.com Git - proxmox-backup.git/blame - tests/pxar.rs
Cargo.toml: remove zstd-sys
[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
fe61cc10 27 Command::new(exec_path)
015c5f6b
CE
28 .arg("extract")
29 .arg("./tests/archive.pxar")
bdf0d82c 30 .arg("--target")
015c5f6b
CE
31 .arg(dest_dir)
32 .status()
33 .unwrap_or_else(|err| {
fe61cc10 34 panic!("Failed to invoke '{}': {}", exec_path, err)
015c5f6b
CE
35 });
36
37 /* Use rsync with --dry-run and --itemize-changes to compare
38 src_dir and dest_dir */
39 let stdout = Command::new("rsync")
40 .arg("--dry-run")
41 .arg("--itemize-changes")
4204e535 42 .arg("--archive")
015c5f6b
CE
43 .arg(src_dir)
44 .arg(dest_dir)
45 .stdout(Stdio::piped())
46 .spawn()
47 .unwrap()
48 .stdout
49 .unwrap();
50
51 let reader = BufReader::new(stdout);
52 let linecount = reader.lines().fold(0, |count, _| count + 1 );
53 println!("Rsync listed {} differences to address", linecount);
54
55 // Cleanup archive
56 Command::new("rm")
57 .arg("./tests/archive.pxar")
58 .status()
59 .unwrap_or_else(|err| {
60 panic!("Failed to invoke 'rm': {}", err)
61 });
62
63 // Cleanup destination dir
64 Command::new("rm")
65 .arg("-r")
66 .arg(dest_dir)
67 .status()
68 .unwrap_or_else(|err| {
69 panic!("Failed to invoke 'rm': {}", err)
70 });
71
72 // If source and destination folder contain the same content,
73 // the output of the rsync invokation should yield no lines.
74 if linecount != 0 {
75 panic!("pxar create and extract did not yield the same contents");
76 }
77}