MCPcopy Create free account
hub / github.com/bootc-dev/bootc / test_parse_lsblk_mbr

Function test_parse_lsblk_mbr

crates/blockdev/src/blockdev.rs:804–837  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

802
803 #[test]
804 fn test_parse_lsblk_mbr() {
805 let fixture = include_str!("../tests/fixtures/lsblk-mbr.json");
806 let devs: DevicesOutput = serde_json::from_str(fixture).unwrap();
807 let dev = devs.blockdevices.into_iter().next().unwrap();
808 // The parent device has no partition number and is MBR
809 assert_eq!(dev.partn, None);
810 assert_eq!(dev.pttype.as_deref().unwrap(), "dos");
811 let children = dev.children.as_deref().unwrap();
812 assert_eq!(children.len(), 3);
813 // First partition: FAT16 boot partition (MBR type 0x06, an ESP type)
814 let first_child = &children[0];
815 assert_eq!(first_child.partn, Some(1));
816 assert_eq!(first_child.parttype.as_deref().unwrap(), "0x06");
817 assert_eq!(first_child.partuuid.as_deref().unwrap(), "a1b2c3d4-01");
818 assert_eq!(first_child.fstype.as_deref().unwrap(), "vfat");
819 // MBR partitions have no partlabel
820 assert!(first_child.partlabel.is_none());
821 // Second partition: Linux root (MBR type 0x83)
822 let second_child = &children[1];
823 assert_eq!(second_child.partn, Some(2));
824 assert_eq!(second_child.parttype.as_deref().unwrap(), "0x83");
825 assert_eq!(second_child.partuuid.as_deref().unwrap(), "a1b2c3d4-02");
826 // Third partition: EFI System Partition (MBR type 0xef)
827 let third_child = &children[2];
828 assert_eq!(third_child.partn, Some(3));
829 assert_eq!(third_child.parttype.as_deref().unwrap(), "0xef");
830 assert_eq!(third_child.partuuid.as_deref().unwrap(), "a1b2c3d4-03");
831 // Verify find_device_by_partno works on MBR
832 let part1 = dev.find_device_by_partno(1).unwrap();
833 assert_eq!(part1.partn, Some(1));
834 // find_partition_of_esp returns the first matching ESP type (0x06 on partition 1)
835 let esp = dev.find_partition_of_esp().unwrap();
836 assert_eq!(esp.partn, Some(1));
837 }
838
839 /// Helper to construct a minimal MBR disk Device with given child partition types.
840 fn make_mbr_disk(parttypes: &[&str]) -> Device {

Callers

nothing calls this directly

Calls 4

find_device_by_partnoMethod · 0.80
find_partition_of_espMethod · 0.80
nextMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected