]>
Commit | Line | Data |
---|---|---|
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 | println!("run '{} extract archive.pxar {}'", exec_path, dest_dir); | |
28 | ||
29 | Command::new(exec_path) | |
30 | .arg("extract") | |
31 | .arg("./tests/archive.pxar") | |
32 | .arg("--target") | |
33 | .arg(dest_dir) | |
34 | .status() | |
35 | .unwrap_or_else(|err| { | |
36 | panic!("Failed to invoke '{}': {}", exec_path, err) | |
37 | }); | |
38 | ||
39 | println!("run 'rsync --dry-run --itemize-changes --archive {} {}' to verify'", src_dir, dest_dir); | |
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") | |
45 | .arg("--archive") | |
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); | |
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 | } | |
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 | } |