From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 2B6191FF168 for ; Tue, 12 Nov 2024 13:48:33 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3538C2908A; Tue, 12 Nov 2024 13:48:31 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Tue, 12 Nov 2024 13:48:17 +0100 Message-ID: <20241112124821.578920-1-c.heiss@proxmox.com> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.030 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH installer] tui: tests: fix reading ui messages from low-level installer X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "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 --- .../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(reader: &mut R) -> Option { + let mut line = String::new(); + reader.read_line(&mut line).expect("a line"); + + match serde_json::from_str::(&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::(&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