diff --git a/proxmox-rrd/tests/file_format_test.rs b/proxmox-rrd/tests/file_format_test.rs new file mode 100644 index 00000000..cecb242d --- /dev/null +++ b/proxmox-rrd/tests/file_format_test.rs @@ -0,0 +1,59 @@ +use std::path::Path; +use std::process::Command; + +use anyhow::{bail, Error}; + +use proxmox_rrd::rrd::RRD; +use proxmox::tools::fs::CreateOptions; + +fn compare_file(fn1: &str, fn2: &str) -> Result<(), Error> { + + let status = Command::new("/usr/bin/cmp") + .arg(fn1) + .arg(fn2) + .status() + .expect("failed to execute process"); + + if !status.success() { + bail!("file compare failed"); + } + + Ok(()) +} + +const RRD_V1_FN: &str = "./tests/testdata/cpu.rrd_v1"; +const RRD_V2_FN: &str = "./tests/testdata/cpu.rrd_v2"; + +// make sure we can load and convert RRD v1 +#[test] +fn upgrade_from_rrd_v1() -> Result<(), Error> { + + let rrd = RRD::load(Path::new(RRD_V1_FN))?; + + const RRD_V2_NEW_FN: &str = "./tests/testdata/cpu.rrd_v2.upgraded"; + let new_path = Path::new(RRD_V2_NEW_FN); + rrd.save(new_path, CreateOptions::new())?; + + let result = compare_file(RRD_V2_FN, RRD_V2_NEW_FN); + let _ = std::fs::remove_file(RRD_V2_NEW_FN); + result?; + + Ok(()) +} + +// make sure we can load and save RRD v2 +#[test] +fn load_and_save_rrd_v2() -> Result<(), Error> { + + let rrd = RRD::load(Path::new(RRD_V2_FN))?; + + const RRD_V2_NEW_FN: &str = "./tests/testdata/cpu.rrd_v2.saved"; + let new_path = Path::new(RRD_V2_NEW_FN); + rrd.save(new_path, CreateOptions::new())?; + + let result = compare_file(RRD_V2_FN, RRD_V2_NEW_FN); + let _ = std::fs::remove_file(RRD_V2_NEW_FN); + result?; + + Ok(()) +} diff --git a/proxmox-rrd/tests/testdata/cpu.rrd_v1 b/proxmox-rrd/tests/testdata/cpu.rrd_v1 new file mode 100644 index 00000000..99d43d34 Binary files /dev/null and b/proxmox-rrd/tests/testdata/cpu.rrd_v1 differ diff --git a/proxmox-rrd/tests/testdata/cpu.rrd_v2 b/proxmox-rrd/tests/testdata/cpu.rrd_v2 new file mode 100644 index 00000000..5e4dfc77 Binary files /dev/null and b/proxmox-rrd/tests/testdata/cpu.rrd_v2 differ