From 9e441eb8993af7fbee0e66b669b1d7a387364a06 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Tue, 30 Jun 2026 17:45:55 +0200 Subject: [PATCH] block: qcow: Add unit tests for detect_image_type Cover the qcow2 magic and the non qcow magic cases of the AlignedFile detect_image_type, which now reads the magic positionally. Assisted-by: Claude:Opus-4.8 Signed-off-by: Anatol Belski --- block/src/formats/qcow/internal/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/src/formats/qcow/internal/mod.rs b/block/src/formats/qcow/internal/mod.rs index 53fe9eb4a..1e443852f 100644 --- a/block/src/formats/qcow/internal/mod.rs +++ b/block/src/formats/qcow/internal/mod.rs @@ -1007,6 +1007,18 @@ mod unit_tests { QcowDisk::new(file, false, backing_files, true, false) } + #[test] + fn detect_image_type_recognizes_qcow2_magic() { + let mut file = basic_file(&valid_header_v3()); + assert_eq!(detect_image_type(&mut file).unwrap(), ImageType::Qcow2); + } + + #[test] + fn detect_image_type_treats_other_magic_as_raw() { + let mut file = basic_file(&[0u8; 16]); + assert_eq!(detect_image_type(&mut file).unwrap(), ImageType::Raw); + } + #[test] fn default_header_v2() { let header = QcowHeader::create_for_size_and_path(2, 0x10_0000, None)