]> git.proxmox.com Git - proxmox-backup.git/blob - tests/pxar.rs
tests/verify-api.rs: remove unused use clause
[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("--target")
31 .arg(dest_dir)
32 .status()
33 .unwrap_or_else(|err| {
34 panic!("Failed to invoke '{}': {}", exec_path, err)
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")
42 .arg("--archive")
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 }