]> git.proxmox.com Git - proxmox.git/blob - proxmox-rrd/tests/file_format_test.rs
rrd: feature-gate support for the v1 format
[proxmox.git] / proxmox-rrd / tests / file_format_test.rs
1 use std::path::Path;
2 use std::process::Command;
3
4 use anyhow::{bail, Error};
5
6 use proxmox_rrd::rrd::RRD;
7 use proxmox_sys::fs::CreateOptions;
8
9 fn compare_file(fn1: &str, fn2: &str) -> Result<(), Error> {
10 let status = Command::new("/usr/bin/cmp")
11 .arg(fn1)
12 .arg(fn2)
13 .status()
14 .expect("failed to execute process");
15
16 if !status.success() {
17 bail!("file compare failed");
18 }
19
20 Ok(())
21 }
22
23 const RRD_V2_FN: &str = "./tests/testdata/cpu.rrd_v2";
24
25 // make sure we can load and convert RRD v1
26 #[test]
27 #[cfg(feature = "rrd_v1")]
28 fn upgrade_from_rrd_v1() -> Result<(), Error> {
29 const RRD_V1_FN: &str = "./tests/testdata/cpu.rrd_v1";
30 let rrd = RRD::load(Path::new(RRD_V1_FN), true)?;
31
32 const RRD_V2_NEW_FN: &str = "./tests/testdata/cpu.rrd_v2.upgraded";
33 let new_path = Path::new(RRD_V2_NEW_FN);
34 rrd.save(new_path, CreateOptions::new(), true)?;
35
36 let result = compare_file(RRD_V2_FN, RRD_V2_NEW_FN);
37 let _ = std::fs::remove_file(RRD_V2_NEW_FN);
38 result?;
39
40 Ok(())
41 }
42
43 // make sure we can load and save RRD v2
44 #[test]
45 fn load_and_save_rrd_v2() -> Result<(), Error> {
46 let rrd = RRD::load(Path::new(RRD_V2_FN), true)?;
47
48 const RRD_V2_NEW_FN: &str = "./tests/testdata/cpu.rrd_v2.saved";
49 let new_path = Path::new(RRD_V2_NEW_FN);
50 rrd.save(new_path, CreateOptions::new(), true)?;
51
52 let result = compare_file(RRD_V2_FN, RRD_V2_NEW_FN);
53 let _ = std::fs::remove_file(RRD_V2_NEW_FN);
54 result?;
55
56 Ok(())
57 }