From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 3/4] auto-installer: tests: add diff'ed assertions for answer parsing tests
Date: Tue, 3 Dec 2024 13:23:27 +0100 [thread overview]
Message-ID: <20241203122331.383398-4-c.heiss@proxmox.com> (raw)
In-Reply-To: <20241203122331.383398-1-c.heiss@proxmox.com>
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@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
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2024-12-03 12:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-03 12:23 [pve-devel] [PATCH installer 0/4] auto, tui: improve rust unit test setup Christoph Heiss
2024-12-03 12:23 ` [pve-devel] [PATCH installer 1/4] auto-installer: tests: add tests for raid level case-insensitivity Christoph Heiss
2024-12-03 12:23 ` [pve-devel] [PATCH installer 2/4] auto-installer: tests: create separate unit test for each answer file Christoph Heiss
2024-12-03 12:23 ` Christoph Heiss [this message]
2024-12-03 12:23 ` [pve-devel] [PATCH installer 4/4] tui: use pretty_assertions for object equal asserts Christoph Heiss
2024-12-03 17:20 ` [pve-devel] applied-series: [PATCH installer 0/4] auto, tui: improve rust unit test setup Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241203122331.383398-4-c.heiss@proxmox.com \
--to=c.heiss@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox