block: factory: Add test for RAW image detection

Verify that open_disk() detects a plain temporary file as RAW and
returns a working backend with synchronous fallback.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-04-21 21:15:18 +02:00
committed by Rob Bradford
parent 9ada7a9afd
commit 01c4e0512f

View File

@@ -200,6 +200,8 @@ fn open_qcow2(
mod unit_tests {
use std::path::Path;
use vmm_sys_util::tempfile::TempFile;
use super::*;
fn default_options(path: &Path) -> DiskOpenOptions<'_> {
@@ -223,4 +225,14 @@ mod unit_tests {
Ok(_) => panic!("expected error for nonexistent path"),
}
}
#[test]
fn detect_raw_image() {
let tmp = TempFile::new().unwrap();
tmp.as_file().set_len(1 << 20).unwrap();
let path = tmp.as_path().to_owned();
let options = default_options(&path);
let opened = open_disk(&options).unwrap();
assert_eq!(opened.image_type, ImageType::Raw);
}
}