deja-vu/core/src/tests/mod.rs

125 lines
4.2 KiB
Rust

// 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 <https://www.gnu.org/licenses/>.
//
pub mod sample_output;
#[cfg(test)]
mod diskpart {
use super::super::system;
use super::sample_output;
#[test]
fn get_disk_details_gpt() {
let disk = system::diskpart::get_disk_details(2, 0, 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 get_disk_details_mbr() {
let disk = system::diskpart::get_disk_details(2, 0, 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 get_partition_details() {
// Left
let partition_1 = system::disk::Partition {
id: 1,
fs_type: String::from("FAT32"),
label: String::from("ESP"),
part_type: String::from("c12a7328-f81f-11d2-ba4b-00a0c93ec93b"),
size: 272629760,
..Default::default()
};
let partition_2 = system::disk::Partition {
id: 2,
part_type: String::from("e3c9e316-0b5c-4db8-817d-f92df00215ae"),
size: 16777216,
..Default::default()
};
let partition_4 = system::disk::Partition {
id: 4,
fs_type: String::from("NTFS"),
label: String::from("Windows"),
letter: String::from("C"),
part_type: String::from("ebd0a0a2-b9e5-4433-87c0-68b6b72699c7"),
size: 50465865728,
..Default::default()
};
// Right
let mut disk = system::disk::Disk::default();
disk.parts.push(system::disk::Partition {
id: 1,
..Default::default()
});
disk.parts.push(system::disk::Partition {
id: 2,
..Default::default()
});
disk.parts.push(system::disk::Partition {
id: 4,
..Default::default()
});
disk.parts = system::diskpart::get_partition_details(
2,
Some(sample_output::DETAIL_DISK_GPT),
Some(sample_output::SELECT_PART_DETAIL_PARTS),
);
assert_eq!(disk.parts.len(), 3);
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: String::from("FAT32"),
label: String::from("ESP"),
letter: String::from("S"),
part_type: String::from("c12a7328-f81f-11d2-ba4b-00a0c93ec93b"),
..Default::default()
};
system::diskpart::parse_partition_details(
&mut disk.parts,
&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);
}
}