From 01c4e0512f3fc25ba8977314de2dc17d88dcfe61 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Tue, 21 Apr 2026 21:15:18 +0200 Subject: [PATCH] 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 --- block/src/factory.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/src/factory.rs b/block/src/factory.rs index b3514b279..58d2255e0 100644 --- a/block/src/factory.rs +++ b/block/src/factory.rs @@ -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); + } }