From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id DD8DE1FF138 for ; Mon, 20 Jul 2026 11:51:48 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id A65832148A; Mon, 20 Jul 2026 11:51:48 +0200 (CEST) From: Filip Schauer To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox v2 1/2] oci: tests: return Result from tests to avoid unwrap calls Date: Mon, 20 Jul 2026 11:50:19 +0200 Message-ID: <20260720095030.64797-2-f.schauer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260720095030.64797-1-f.schauer@proxmox.com> References: <20260720095030.64797-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: 1784541080262 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.083 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust 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: NSF27CMTQ4CCJGKHISEDNHH32BLDWV7V X-Message-ID-Hash: NSF27CMTQ4CCJGKHISEDNHH32BLDWV7V 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 54eddff4..cfb4d8bd 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::{Arch, parse_and_extract_image}; 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 77328ba0..5bba7dba 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::{Arch, parse_and_extract_image}; 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