From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 9425D1FF144 for ; Tue, 24 Mar 2026 16:36:34 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1125116BCE; Tue, 24 Mar 2026 16:36:55 +0100 (CET) From: Filip Schauer To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox 1/2] oci: tests: return Result from tests to avoid unwrap calls Date: Tue, 24 Mar 2026 16:35:49 +0100 Message-ID: <20260324153553.146040-2-f.schauer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260324153553.146040-1-f.schauer@proxmox.com> References: <20260324153553.146040-1-f.schauer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1774366562569 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.010 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: AWTDO5LGPFVF6XSBZRLWAIIG5DAEO6WN X-Message-ID-Hash: AWTDO5LGPFVF6XSBZRLWAIIG5DAEO6WN X-MailFrom: f.schauer@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Filip Schauer --- proxmox-oci/Cargo.toml | 1 + proxmox-oci/tests/extract_replace.rs | 37 +++++++++-------- proxmox-oci/tests/extract_whiteouts.rs | 57 +++++++++++++++----------- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/proxmox-oci/Cargo.toml b/proxmox-oci/Cargo.toml index b0c1cf38..8b922f37 100644 --- a/proxmox-oci/Cargo.toml +++ b/proxmox-oci/Cargo.toml @@ -22,4 +22,5 @@ zstd.workspace = true proxmox-io.workspace = true [dev-dependencies] +anyhow.workspace = true proxmox-sys.workspace = true diff --git a/proxmox-oci/tests/extract_replace.rs b/proxmox-oci/tests/extract_replace.rs index eb41f9e3..5f684c8a 100644 --- a/proxmox-oci/tests/extract_replace.rs +++ b/proxmox-oci/tests/extract_replace.rs @@ -1,57 +1,62 @@ use std::fs::{read_to_string, remove_dir_all}; +use anyhow::Result; + use proxmox_oci::{parse_and_extract_image, Arch}; use proxmox_sys::fs::make_tmp_dir; #[test] -fn test_replace_file() { - let extract_dir = make_tmp_dir("/tmp/", None).unwrap(); +fn test_replace_file() -> Result<()> { + let extract_dir = make_tmp_dir("/tmp/", None)?; parse_and_extract_image( &"tests/oci_image_data/oci_test_replace_file.tar".into(), &extract_dir, Some(&Arch::Amd64), - ) - .unwrap(); + )?; let replaced_path = extract_dir.join("etc/a"); assert!(replaced_path.is_file()); - assert_eq!(read_to_string(replaced_path).unwrap(), "2"); + assert_eq!(read_to_string(replaced_path)?, "2"); // Cleanup - remove_dir_all(extract_dir).unwrap(); + remove_dir_all(extract_dir)?; + + Ok(()) } #[test] -fn test_replace_file_with_dir() { - let extract_dir = make_tmp_dir("/tmp/", None).unwrap(); +fn test_replace_file_with_dir() -> Result<()> { + let extract_dir = make_tmp_dir("/tmp/", None)?; parse_and_extract_image( &"tests/oci_image_data/oci_test_replace_file_with_dir.tar".into(), &extract_dir, Some(&Arch::Amd64), - ) - .unwrap(); + )?; assert!(extract_dir.join("etc/a").is_dir()); // Cleanup - remove_dir_all(extract_dir).unwrap(); + remove_dir_all(extract_dir)?; + + Ok(()) } #[test] -fn test_replace_dir_with_file() { - let extract_dir = make_tmp_dir("/tmp/", None).unwrap(); +fn test_replace_dir_with_file() -> Result<()> { + let extract_dir = make_tmp_dir("/tmp/", None)?; parse_and_extract_image( &"tests/oci_image_data/oci_test_replace_dir_with_file.tar".into(), &extract_dir, Some(&Arch::Amd64), - ) - .unwrap(); + )?; assert!(extract_dir.join("etc/a").is_file()); // Cleanup - remove_dir_all(extract_dir).unwrap(); + remove_dir_all(extract_dir)?; + + Ok(()) } diff --git a/proxmox-oci/tests/extract_whiteouts.rs b/proxmox-oci/tests/extract_whiteouts.rs index 71ec4dea..20156de0 100644 --- a/proxmox-oci/tests/extract_whiteouts.rs +++ b/proxmox-oci/tests/extract_whiteouts.rs @@ -1,92 +1,99 @@ use std::fs::remove_dir_all; +use anyhow::Result; + use proxmox_oci::{parse_and_extract_image, Arch}; use proxmox_sys::fs::make_tmp_dir; #[test] -fn test_whiteout_root_breakout() { - let extract_dir = make_tmp_dir("/tmp/", None).unwrap(); +fn test_whiteout_root_breakout() -> Result<()> { + let extract_dir = make_tmp_dir("/tmp/", None)?; parse_and_extract_image( &"tests/oci_image_data/oci_test_whiteout_root_breakout.tar".into(), &extract_dir, Some(&Arch::Amd64), - ) - .unwrap(); + )?; // Check that the whiteout did not remove the root directory assert!(extract_dir.exists()); // Cleanup - remove_dir_all(extract_dir).unwrap(); + remove_dir_all(extract_dir)?; + + Ok(()) } #[test] -fn test_whiteout_root_parent_breakout() { - let extract_dir = make_tmp_dir("/tmp/", None).unwrap(); +fn test_whiteout_root_parent_breakout() -> Result<()> { + let extract_dir = make_tmp_dir("/tmp/", None)?; parse_and_extract_image( &"tests/oci_image_data/oci_test_whiteout_root_parent_breakout.tar".into(), &extract_dir, Some(&Arch::Amd64), - ) - .unwrap(); + )?; // Check that the whiteout did not remove the root directory assert!(extract_dir.exists()); // Cleanup - remove_dir_all(extract_dir).unwrap(); + remove_dir_all(extract_dir)?; + + Ok(()) } #[test] -fn test_whiteout_current_directory() { - let extract_dir = make_tmp_dir("/tmp/", None).unwrap(); +fn test_whiteout_current_directory() -> Result<()> { + let extract_dir = make_tmp_dir("/tmp/", None)?; parse_and_extract_image( &"tests/oci_image_data/oci_test_whiteout_current_directory.tar".into(), &extract_dir, Some(&Arch::Amd64), - ) - .unwrap(); + )?; assert!(!extract_dir.join("etc").exists()); // Cleanup - remove_dir_all(extract_dir).unwrap(); + remove_dir_all(extract_dir)?; + + Ok(()) } #[test] -fn test_whiteout_symlink() { - let extract_dir = make_tmp_dir("/tmp/", None).unwrap(); +fn test_whiteout_symlink() -> Result<()> { + let extract_dir = make_tmp_dir("/tmp/", None)?; parse_and_extract_image( &"tests/oci_image_data/oci_test_whiteout_symlink.tar".into(), &extract_dir, Some(&Arch::Amd64), - ) - .unwrap(); + )?; assert!(extract_dir.join("etc/passwd").exists()); assert!(!extract_dir.join("localetc").exists()); // Cleanup - remove_dir_all(extract_dir).unwrap(); + remove_dir_all(extract_dir)?; + + Ok(()) } #[test] -fn test_whiteout_dead_symlink_parent() { - let extract_dir = make_tmp_dir("/tmp/", None).unwrap(); +fn test_whiteout_dead_symlink_parent() -> Result<()> { + let extract_dir = make_tmp_dir("/tmp/", None)?; parse_and_extract_image( &"tests/oci_image_data/oci_test_whiteout_dead_symlink_parent.tar".into(), &extract_dir, Some(&Arch::Amd64), - ) - .unwrap(); + )?; assert!(extract_dir.join("etc/passwd").exists()); // Cleanup - remove_dir_all(extract_dir).unwrap(); + remove_dir_all(extract_dir)?; + + Ok(()) } -- 2.47.3