]> git.proxmox.com Git - proxmox.git/blob - proxmox-rrd/tests/file_format_test.rs
372a407776f42c7a59857bc3cab86461c2e070f4
[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_V1_FN: &str = "./tests/testdata/cpu.rrd_v1";
24 const RRD_V2_FN: &str = "./tests/testdata/cpu.rrd_v2";
25
26 // make sure we can load and convert RRD v1
27 #[test]
28 fn upgrade_from_rrd_v1() -> Result<(), Error> {
29 let rrd = RRD::load(Path::new(RRD_V1_FN), true)?;
30
31 const RRD_V2_NEW_FN: &str = "./tests/testdata/cpu.rrd_v2.upgraded";
32 let new_path = Path::new(RRD_V2_NEW_FN);
33 rrd.save(new_path, CreateOptions::new(), true)?;
34
35 let result = compare_file(RRD_V2_FN, RRD_V2_NEW_FN);
36 let _ = std::fs::remove_file(RRD_V2_NEW_FN);
37 result?;
38
39 Ok(())
40 }
41
42 // make sure we can load and save RRD v2
43 #[test]
44 fn load_and_save_rrd_v2() -> Result<(), Error> {
45 let rrd = RRD::load(Path::new(RRD_V2_FN), true)?;
46
47 const RRD_V2_NEW_FN: &str = "./tests/testdata/cpu.rrd_v2.saved";
48 let new_path = Path::new(RRD_V2_NEW_FN);
49 rrd.save(new_path, CreateOptions::new(), true)?;
50
51 let result = compare_file(RRD_V2_FN, RRD_V2_NEW_FN);
52 let _ = std::fs::remove_file(RRD_V2_NEW_FN);
53 result?;
54
55 Ok(())
56 }