From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer] tui: tests: fix reading ui messages from low-level installer
Date: Tue, 12 Nov 2024 13:48:17 +0100 [thread overview]
Message-ID: <20241112124821.578920-1-c.heiss@proxmox.com> (raw)
This actually broke with commit 723afe2 - this patch was quite old
(18.10.2023) and these tests were introduced some time after sending it,
thus is not adjusted for it.
Fix itself is pretty simple, simply ignore non-JSON/invalid message from
the low-level installer, much like the actual progression code does it.
Fixes: 723afe2 ("run env: always re-create run env file in test mode")
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
.../src/views/install_progress.rs | 34 +++++++++++--------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/proxmox-tui-installer/src/views/install_progress.rs b/proxmox-tui-installer/src/views/install_progress.rs
index 6c8df58..4b4a418 100644
--- a/proxmox-tui-installer/src/views/install_progress.rs
+++ b/proxmox-tui-installer/src/views/install_progress.rs
@@ -273,6 +273,22 @@ mod tests {
use super::*;
use std::env;
+ fn next_msg<R: BufRead>(reader: &mut R) -> Option<UiMessage> {
+ let mut line = String::new();
+ reader.read_line(&mut line).expect("a line");
+
+ match serde_json::from_str::<UiMessage>(&line) {
+ Ok(msg) => Some(msg),
+ Err(err) => {
+ eprintln!("invalid json: '{err}'");
+ // Skip over all spurious output that may be produced by the low-level
+ // installer, in the same manner as InstallProgressView::progress_task()
+ // above does the actual processing.
+ next_msg(reader)
+ }
+ }
+ }
+
#[test]
fn run_low_level_installer_test_session() {
env::set_current_dir("..").expect("failed to change working directory");
@@ -292,18 +308,8 @@ mod tests {
writeln!(writer).expect("failed to write install config: {err}");
- let mut next_msg = || {
- let mut line = String::new();
- reader.read_line(&mut line).expect("a line");
-
- match serde_json::from_str::<UiMessage>(&line) {
- Ok(msg) => Some(msg),
- Err(err) => panic!("unexpected error: '{err}'"),
- }
- };
-
assert_eq!(
- next_msg(),
+ next_msg(&mut reader),
Some(UiMessage::Prompt {
query: "Reply anything?".to_owned()
}),
@@ -317,7 +323,7 @@ mod tests {
writeln!(writer).expect("failed to write prompt answer");
assert_eq!(
- next_msg(),
+ next_msg(&mut reader),
Some(UiMessage::Info {
message: "Test Message - got ok".to_owned()
}),
@@ -325,7 +331,7 @@ mod tests {
for i in (1..=1000).step_by(3) {
assert_eq!(
- next_msg(),
+ next_msg(&mut reader),
Some(UiMessage::Progress {
ratio: (i as f32) / 1000.,
text: format!("foo {i}"),
@@ -334,7 +340,7 @@ mod tests {
}
assert_eq!(
- next_msg(),
+ next_msg(&mut reader),
Some(UiMessage::Finished {
state: "ok".to_owned(),
message: "Installation finished - reboot now?".to_owned(),
--
2.47.0
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next reply other threads:[~2024-11-12 12:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-12 12:48 Christoph Heiss [this message]
2024-11-12 13:51 ` [pve-devel] applied: " 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=20241112124821.578920-1-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.