[pve-devel] [PATCH installer 3/4] auto-installer: tests: add diff'ed assertions for answer parsing tests

Christoph Heiss c.heiss at proxmox.com
Tue Dec 3 13:23:27 CET 2024


Adds the `pretty_assertions` crate [0] as dev-dependency, which does
this very nicely. This makes failures way easier to observe and quickly
reason about.

See also [1] for the initial discussion about this.

[0] https://docs.rs/pretty_assertions
[1] https://lore.proxmox.com/pve-devel/a35eafb9-cbba-4d79-8535-d2bc7c5560ee@proxmox.com/

Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
 debian/control                               | 1 +
 proxmox-auto-installer/Cargo.toml            | 3 +++
 proxmox-auto-installer/tests/parse-answer.rs | 6 +++---
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/debian/control b/debian/control
index fd0f4df..ee1fc44 100644
--- a/debian/control
+++ b/debian/control
@@ -25,6 +25,7 @@ Build-Depends: cargo:native,
                librust-sha2-0.10-dev,
                librust-toml-0.8-dev,
                librust-ureq-2.10-dev,
+               librust-pretty-assertions-1.4-dev,
                libtest-mockmodule-perl,
                patchelf,
                perl,
diff --git a/proxmox-auto-installer/Cargo.toml b/proxmox-auto-installer/Cargo.toml
index 7e3d90c..d06478f 100644
--- a/proxmox-auto-installer/Cargo.toml
+++ b/proxmox-auto-installer/Cargo.toml
@@ -21,3 +21,6 @@ toml.workspace = true
 
 clap = { version = "4.0", features = ["derive"] }
 glob = "0.3"
+
+[dev-dependencies]
+pretty_assertions = "1.4"
diff --git a/proxmox-auto-installer/tests/parse-answer.rs b/proxmox-auto-installer/tests/parse-answer.rs
index f6450cf..68b3834 100644
--- a/proxmox-auto-installer/tests/parse-answer.rs
+++ b/proxmox-auto-installer/tests/parse-answer.rs
@@ -1,7 +1,6 @@
-use std::path::{Path, PathBuf};
-
 use serde_json::Value;
 use std::fs;
+use std::path::{Path, PathBuf};
 
 use proxmox_auto_installer::answer;
 use proxmox_auto_installer::answer::Answer;
@@ -61,7 +60,8 @@ fn run_named_test(name: &str) {
     let json_path = resource_path.join(format!("parse_answer/{name}.json"));
     let compare_raw = fs::read_to_string(&json_path).unwrap();
     let compare: Value = serde_json::from_str(&compare_raw).unwrap();
-    assert_eq!(config, compare);
+
+    pretty_assertions::assert_eq!(config, compare);
 }
 
 mod tests {
-- 
2.47.0





More information about the pve-devel mailing list