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 <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-04-21 21:11:10 +02:00
committed by Rob Bradford
parent cba2b7f773
commit 9ada7a9afd

View File

@@ -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"),
}
}
}