diff --git a/block/src/factory.rs b/block/src/factory.rs index 58d2255e0..0a3ddc974 100644 --- a/block/src/factory.rs +++ b/block/src/factory.rs @@ -198,11 +198,13 @@ fn open_qcow2( #[cfg(test)] mod unit_tests { + use std::io::Write; use std::path::Path; use vmm_sys_util::tempfile::TempFile; use super::*; + use crate::qcow::{QcowFile, RawFile}; fn default_options(path: &Path) -> DiskOpenOptions<'_> { DiskOpenOptions { @@ -235,4 +237,18 @@ mod unit_tests { let opened = open_disk(&options).unwrap(); assert_eq!(opened.image_type, ImageType::Raw); } + + #[test] + fn detect_qcow2_image() { + let tmp = TempFile::new().unwrap(); + { + let raw = RawFile::new(tmp.as_file().try_clone().unwrap(), false); + let mut qcow = QcowFile::new(raw, 3, 100 * 1024 * 1024, true).unwrap(); + qcow.flush().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::Qcow2); + } }