// This file is part of Deja-vu. // // Deja-vu is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Deja-vu is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Deja-vu. If not, see . // mod sample_output; #[cfg(test)] mod diskpart { use super::super::system; use super::sample_output; #[test] fn add_disk_details_gpt() { let mut disk = system::disk::Disk::default(); system::diskpart::add_disk_details(&mut disk, Some(sample_output::DETAIL_DISK_GPT)); assert_eq!(disk.model, "Red Hat VirtIO SCSI Disk Device"); assert_eq!(disk.part_type, system::disk::PartitionTableType::Guid); assert_eq!(disk.conn_type, "SCSI"); } #[test] fn add_disk_details_mbr() { let mut disk = system::disk::Disk::default(); system::diskpart::add_disk_details(&mut disk, Some(sample_output::DETAIL_DISK_MBR)); assert_eq!(disk.model, "Red Hat VirtIO SCSI Disk Device"); assert_eq!(disk.part_type, system::disk::PartitionTableType::Legacy); assert_eq!(disk.conn_type, "SCSI"); } #[test] fn add_partition_details() { let mut disk = system::disk::Disk::default(); disk.parts.push(system::disk::Partition { id: String::from("1"), ..Default::default() }); disk.parts.push(system::disk::Partition { id: String::from("2"), ..Default::default() }); disk.parts.push(system::disk::Partition { id: String::from("4"), ..Default::default() }); let partition_1 = system::disk::Partition { id: String::from("1"), fs_type: Some(String::from("FAT32")), label: Some(String::from("ESP")), letter: None, part_type: String::from("c12a7328-f81f-11d2-ba4b-00a0c93ec93b"), ..Default::default() }; let partition_2 = system::disk::Partition { id: String::from("2"), part_type: String::from("e3c9e316-0b5c-4db8-817d-f92df00215ae"), ..Default::default() }; let partition_4 = system::disk::Partition { id: String::from("4"), fs_type: Some(String::from("NTFS")), label: Some(String::from("Windows")), letter: Some(String::from("C")), part_type: String::from("ebd0a0a2-b9e5-4433-87c0-68b6b72699c7"), ..Default::default() }; system::diskpart::add_partition_details( &mut disk, Some(sample_output::DETAIL_DISK_GPT), Some(sample_output::SELECT_PART_DETAIL_PARTS), ); assert_eq!(partition_1, disk.parts[0]); assert_eq!(partition_2, disk.parts[1]); assert_eq!(partition_4, disk.parts[2]); } #[test] fn parse_disk_numbers() { let disk_numbers = system::diskpart::parse_disk_numbers(&sample_output::LIST_DISK_DETAIL_DISKS); assert_eq!(vec!["0", "2"], disk_numbers); } #[test] fn parse_partition_details() { let mut disk = system::disk::Disk::default(); disk.parts.push(system::disk::Partition::default()); let partition_1 = system::disk::Partition { fs_type: Some(String::from("FAT32")), label: Some(String::from("ESP")), letter: Some(String::from("S")), part_type: String::from("c12a7328-f81f-11d2-ba4b-00a0c93ec93b"), ..Default::default() }; system::diskpart::parse_partition_details( &mut disk, &sample_output::SELECT_PART_DETAIL_ONE_PART, ); assert_eq!(partition_1, disk.parts[0]); } #[test] fn split_output() { let sections = system::diskpart::split_diskpart_disk_output(sample_output::LIST_DISK_DETAIL_DISKS); assert_eq!(sample_output::SPLIT_SECTIONS, sections); } }