From: Filip Schauer <f.schauer@proxmox.com>
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 [thread overview]
Message-ID: <20260324153553.146040-2-f.schauer@proxmox.com> (raw)
In-Reply-To: <20260324153553.146040-1-f.schauer@proxmox.com>
Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
proxmox-oci/Cargo.toml | 1 +
| 37 +++++++++--------
| 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
--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(())
}
--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
next prev parent reply other threads:[~2026-03-24 15:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-24 15:35 [PATCH proxmox 0/2] oci: tests: refactor to drop static test tarballs Filip Schauer
2026-03-24 15:35 ` Filip Schauer [this message]
2026-03-24 15:35 ` [PATCH proxmox 2/2] oci: tests: generate OCI test images on the fly Filip Schauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260324153553.146040-2-f.schauer@proxmox.com \
--to=f.schauer@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox