mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
committed by
Rob Bradford
parent
cba2b7f773
commit
9ada7a9afd
@@ -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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user