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 <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-06-30 17:45:55 +02:00
committed by Rob Bradford
parent 3937c224a7
commit 9e441eb899

View File

@@ -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)