[pve-devel] [PATCH installer] tui: tests: fix reading ui messages from low-level installer

Christoph Heiss c.heiss at proxmox.com
Tue Nov 12 13:48:17 CET 2024


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 at 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





More information about the pve-devel mailing list