From 9ada7a9afd0b085a91ca5ffa2c746492eb66e903 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Tue, 21 Apr 2026 21:11:10 +0200 Subject: [PATCH] block: factory: Add test for nonexistent path Verify that open_disk() returns BlockErrorKind::Io when the disk image file does not exist. Signed-off-by: Anatol Belski --- block/src/factory.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/block/src/factory.rs b/block/src/factory.rs index 9925dc162..b3514b279 100644 --- a/block/src/factory.rs +++ b/block/src/factory.rs @@ -195,3 +195,32 @@ fn open_qcow2( .map_err(|e| e.with_path(options.path))?, )) } + +#[cfg(test)] +mod unit_tests { + use std::path::Path; + + use super::*; + + fn default_options(path: &Path) -> DiskOpenOptions<'_> { + DiskOpenOptions { + path, + readonly: false, + direct: false, + sparse: false, + backing_files: false, + disable_io_uring: true, + disable_aio: true, + } + } + + #[test] + fn nonexistent_path_returns_error() { + let path = Path::new("/tmp/no_such_disk_image.raw"); + let options = default_options(path); + match open_disk(&options) { + Err(e) => assert_eq!(e.kind(), BlockErrorKind::Io), + Ok(_) => panic!("expected error for nonexistent path"), + } + } +}