From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 3/6] auto: tests: allow testing for serde parse errors of answer files
Date: Thu, 27 Mar 2025 16:17:14 +0100 [thread overview]
Message-ID: <20250327151718.1084841-4-c.heiss@proxmox.com> (raw)
In-Reply-To: <20250327151718.1084841-1-c.heiss@proxmox.com>
In certain cases, it can be useful for (expected) parse failures, where
the error message then also comes directly from serde.
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
proxmox-auto-installer/tests/parse-answer.rs | 21 +++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/proxmox-auto-installer/tests/parse-answer.rs b/proxmox-auto-installer/tests/parse-answer.rs
index 6d5f228..57e20b3 100644
--- a/proxmox-auto-installer/tests/parse-answer.rs
+++ b/proxmox-auto-installer/tests/parse-answer.rs
@@ -2,7 +2,6 @@ use serde_json::Value;
use std::fs;
use std::path::{Path, PathBuf};
-use proxmox_auto_installer::answer;
use proxmox_auto_installer::answer::Answer;
use proxmox_auto_installer::udevinfo::UdevInfo;
use proxmox_auto_installer::utils::parse_answer;
@@ -19,11 +18,8 @@ fn get_test_resource_path() -> Result<PathBuf, String> {
fn get_answer(path: impl AsRef<Path>) -> Result<Answer, String> {
let answer_raw = fs::read_to_string(path).unwrap();
- let answer: answer::Answer = toml::from_str(&answer_raw)
- .map_err(|err| format!("error parsing answer.toml: {err}"))
- .unwrap();
-
- Ok(answer)
+ toml::from_str(&answer_raw)
+ .map_err(|err| format!("error parsing answer.toml: {}", err.message()))
}
fn setup_test_basic(path: impl AsRef<Path>) -> (SetupInfo, LocaleInfo, RuntimeInfo, UdevInfo) {
@@ -79,14 +75,21 @@ fn run_named_fail_parse_test(name: &str) {
let answer_path = resource_path.join(format!("parse_answer_fail/{name}.toml"));
- let answer = get_answer(&answer_path).unwrap();
- let config = parse_answer(&answer, &udev_info, &runtime_info, &locales, &setup_info);
-
let err_json: Value = {
let path = resource_path.join(format!("parse_answer_fail/{name}.json"));
read_json(path).unwrap()
};
+ let answer = match get_answer(&answer_path) {
+ Ok(answer) => answer,
+ Err(err) => {
+ assert_eq!(err, err_json.get("parse-error").unwrap().as_str().unwrap());
+ return;
+ }
+ };
+
+ let config = parse_answer(&answer, &udev_info, &runtime_info, &locales, &setup_info);
+
assert!(config.is_err());
assert_eq!(
config.unwrap_err().to_string(),
--
2.48.1
_______________________________________________
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:[~2025-03-27 15:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-27 15:17 [pve-devel] [PATCH installer 0/6] fix #5811: add option to retrieve FQDN from DHCP configuration Christoph Heiss
2025-03-27 15:17 ` [pve-devel] [PATCH installer 1/6] auto: utils: avoid a force unwrap() Christoph Heiss
2025-04-04 12:51 ` [pve-devel] applied: " Thomas Lamprecht
2025-03-27 15:17 ` [pve-devel] [PATCH installer 2/6] auto: tests: parse-answer: allow per-test runtime env Christoph Heiss
2025-04-04 12:51 ` [pve-devel] applied: " Thomas Lamprecht
2025-03-27 15:17 ` Christoph Heiss [this message]
2025-04-04 12:51 ` [pve-devel] applied: [PATCH installer 3/6] auto: tests: allow testing for serde parse errors of answer files Thomas Lamprecht
2025-03-27 15:17 ` [pve-devel] [PATCH installer 4/6] tui, common: move network option tests to correct crate Christoph Heiss
2025-04-04 12:54 ` Thomas Lamprecht
2025-03-27 15:17 ` [pve-devel] [PATCH installer 5/6] common: options: allow user-supplied domain for network options Christoph Heiss
2025-03-27 15:17 ` [pve-devel] [PATCH installer 6/6] fix #5811: auto: add option to retrieve FQDN from DHCP configuration Christoph Heiss
2025-04-01 13:15 ` Daniel Kral
2025-04-01 13:25 ` Christoph Heiss
2025-04-01 13:29 ` Stefan Hanreich
2025-04-01 13:44 ` Daniel Kral
2025-04-01 14:58 ` Thomas Lamprecht
2025-04-01 13:45 ` [pve-devel] [PATCH installer 0/6] fix #5811: " Daniel Kral
2025-04-01 14:05 ` Christoph Heiss
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=20250327151718.1084841-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal