all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH installer] tui: tests: fix reading ui messages from low-level installer
@ 2024-11-12 12:48 Christoph Heiss
  2024-11-12 13:51 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Heiss @ 2024-11-12 12:48 UTC (permalink / raw)
  To: pve-devel

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pve-devel] applied: [PATCH installer] tui: tests: fix reading ui messages from low-level installer
  2024-11-12 12:48 [pve-devel] [PATCH installer] tui: tests: fix reading ui messages from low-level installer Christoph Heiss
@ 2024-11-12 13:51 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2024-11-12 13:51 UTC (permalink / raw)
  To: Proxmox VE development discussion, Christoph Heiss

Am 12.11.24 um 13:48 schrieb Christoph Heiss:
> 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(-)
> 
>

applied, thanks!


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-11-12 13:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-12 12:48 [pve-devel] [PATCH installer] tui: tests: fix reading ui messages from low-level installer Christoph Heiss
2024-11-12 13:51 ` [pve-devel] applied: " Thomas Lamprecht

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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal