Add tests for diskpart
This commit is contained in:
parent
9414f873bd
commit
e50b1ff55b
4 changed files with 410 additions and 0 deletions
|
|
@ -85,6 +85,7 @@ impl Component for Left {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mode::InstallDrivers | Mode::SelectDisks | Mode::SelectParts => {
|
Mode::InstallDrivers | Mode::SelectDisks | Mode::SelectParts => {
|
||||||
|
// Menu selection sections
|
||||||
let selection: Option<usize>;
|
let selection: Option<usize>;
|
||||||
match self.mode {
|
match self.mode {
|
||||||
Mode::InstallDrivers => selection = self.list_drivers.state.selected(),
|
Mode::InstallDrivers => selection = self.list_drivers.state.selected(),
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ mod config;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod logging;
|
mod logging;
|
||||||
mod system;
|
mod system;
|
||||||
|
mod tests;
|
||||||
mod tui;
|
mod tui;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|
|
||||||
124
src/tests/mod.rs
Normal file
124
src/tests/mod.rs
Normal file
|
|
@ -0,0 +1,124 @@
|
||||||
|
// 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/>.
|
||||||
|
//
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
284
src/tests/sample_output.rs
Normal file
284
src/tests/sample_output.rs
Normal file
|
|
@ -0,0 +1,284 @@
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub static DETAIL_DISK_GPT: &str = "Disk 2 is now the selected disk.
|
||||||
|
|
||||||
|
Red Hat VirtIO SCSI Disk Device
|
||||||
|
Disk ID: {7EBCAB6D-5D60-4C08-8EBC-D212A0DAF53F}
|
||||||
|
Type : SCSI
|
||||||
|
Status : Online
|
||||||
|
Path : 0
|
||||||
|
Target : 0
|
||||||
|
LUN ID : 0
|
||||||
|
Location Path : PCIROOT(0)#PCI(0205)#PCI(0000)#SCSI(P00T00L00)
|
||||||
|
Current Read-only State : No
|
||||||
|
Read-only : No
|
||||||
|
Boot Disk : No
|
||||||
|
Pagefile Disk : No
|
||||||
|
Hibernation File Disk : No
|
||||||
|
Crashdump Disk : No
|
||||||
|
Clustered Disk : No
|
||||||
|
|
||||||
|
Volume ### Ltr Label Fs Type Size Status Info
|
||||||
|
---------- --- ----------- ----- ---------- ------- --------- --------
|
||||||
|
Volume 4 E Scratch NTFS Partition 59 GB Healthy
|
||||||
|
|
||||||
|
Partition ### Type Size Offset
|
||||||
|
------------- ---------------- ------- -------
|
||||||
|
Partition 1 Reserved 16 MB 16 MB
|
||||||
|
Partition 2 Primary 59 GB 32 MB
|
||||||
|
|
||||||
|
Reached the end of the disk enumeration.
|
||||||
|
|
||||||
|
There is no disk selected.
|
||||||
|
";
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub static DETAIL_DISK_MBR: &str = "Disk 0 is now the selected disk.
|
||||||
|
|
||||||
|
Red Hat VirtIO SCSI Disk Device
|
||||||
|
Disk ID: F0152E21
|
||||||
|
Type : SCSI
|
||||||
|
Status : Online
|
||||||
|
Path : 0
|
||||||
|
Target : 0
|
||||||
|
LUN ID : 0
|
||||||
|
Location Path : PCIROOT(0)#PCI(0204)#PCI(0000)#SCSI(P00T00L00)
|
||||||
|
Current Read-only State : No
|
||||||
|
Read-only : No
|
||||||
|
Boot Disk : Yes
|
||||||
|
Pagefile Disk : Yes
|
||||||
|
Hibernation File Disk : No
|
||||||
|
Crashdump Disk : Yes
|
||||||
|
Clustered Disk : No
|
||||||
|
|
||||||
|
Volume ### Ltr Label Fs Type Size Status Info
|
||||||
|
---------- --- ----------- ----- ---------- ------- --------- --------
|
||||||
|
Volume 1 F System Rese NTFS Partition 100 MB Healthy System
|
||||||
|
Volume 2 C NTFS Partition 49 GB Healthy Boot
|
||||||
|
Volume 3 NTFS Partition 757 MB Healthy Hidden
|
||||||
|
|
||||||
|
Partition ### Type Size Offset
|
||||||
|
------------- ---------------- ------- -------
|
||||||
|
Partition 1 Primary 100 MB 1024 KB
|
||||||
|
Partition 2 Primary 49 GB 101 MB
|
||||||
|
Partition 3 Recovery 757 MB 49 GB
|
||||||
|
";
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub static LIST_DISK_DETAIL_DISKS: &str = "
|
||||||
|
Microsoft DiskPart version 10.0.22621.1
|
||||||
|
|
||||||
|
Copyright (C) Microsoft Corporation.
|
||||||
|
On computer: VIRTPC
|
||||||
|
|
||||||
|
Disk ### Status Size Free Dyn Gpt
|
||||||
|
-------- ------------- ------- ------- --- ---
|
||||||
|
Disk 0 Online 50 GB 1024 KB
|
||||||
|
Disk 2 Online 60 GB 15 MB *
|
||||||
|
|
||||||
|
Disk 0 is now the selected disk.
|
||||||
|
|
||||||
|
Red Hat VirtIO SCSI Disk Device
|
||||||
|
Disk ID: F0152E21
|
||||||
|
Type : SCSI
|
||||||
|
Status : Online
|
||||||
|
Path : 0
|
||||||
|
Target : 0
|
||||||
|
LUN ID : 0
|
||||||
|
Location Path : PCIROOT(0)#PCI(0204)#PCI(0000)#SCSI(P00T00L00)
|
||||||
|
Current Read-only State : No
|
||||||
|
Read-only : No
|
||||||
|
Boot Disk : Yes
|
||||||
|
Pagefile Disk : Yes
|
||||||
|
Hibernation File Disk : No
|
||||||
|
Crashdump Disk : Yes
|
||||||
|
Clustered Disk : No
|
||||||
|
|
||||||
|
Volume ### Ltr Label Fs Type Size Status Info
|
||||||
|
---------- --- ----------- ----- ---------- ------- --------- --------
|
||||||
|
Volume 1 F System Rese NTFS Partition 100 MB Healthy System
|
||||||
|
Volume 2 C NTFS Partition 49 GB Healthy Boot
|
||||||
|
Volume 3 NTFS Partition 757 MB Healthy Hidden
|
||||||
|
|
||||||
|
Partition ### Type Size Offset
|
||||||
|
------------- ---------------- ------- -------
|
||||||
|
Partition 1 Primary 100 MB 1024 KB
|
||||||
|
Partition 2 Primary 49 GB 101 MB
|
||||||
|
Partition 3 Recovery 757 MB 49 GB
|
||||||
|
|
||||||
|
Disk 2 is now the selected disk.
|
||||||
|
|
||||||
|
Red Hat VirtIO SCSI Disk Device
|
||||||
|
Disk ID: {7EBCAB6D-5D60-4C08-8EBC-D212A0DAF53F}
|
||||||
|
Type : SCSI
|
||||||
|
Status : Online
|
||||||
|
Path : 0
|
||||||
|
Target : 0
|
||||||
|
LUN ID : 0
|
||||||
|
Location Path : PCIROOT(0)#PCI(0205)#PCI(0000)#SCSI(P00T00L00)
|
||||||
|
Current Read-only State : No
|
||||||
|
Read-only : No
|
||||||
|
Boot Disk : No
|
||||||
|
Pagefile Disk : No
|
||||||
|
Hibernation File Disk : No
|
||||||
|
Crashdump Disk : No
|
||||||
|
Clustered Disk : No
|
||||||
|
|
||||||
|
Volume ### Ltr Label Fs Type Size Status Info
|
||||||
|
---------- --- ----------- ----- ---------- ------- --------- --------
|
||||||
|
Volume 4 E Scratch NTFS Partition 59 GB Healthy
|
||||||
|
|
||||||
|
Partition ### Type Size Offset
|
||||||
|
------------- ---------------- ------- -------
|
||||||
|
Partition 1 Reserved 16 MB 16 MB
|
||||||
|
Partition 2 Primary 59 GB 32 MB
|
||||||
|
|
||||||
|
Reached the end of the disk enumeration.
|
||||||
|
|
||||||
|
There is no disk selected.
|
||||||
|
";
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub static SELECT_PART_DETAIL_ONE_PART: &str = "
|
||||||
|
Microsoft DiskPart version 10.0.22621.1
|
||||||
|
|
||||||
|
Copyright (C) Microsoft Corporation.
|
||||||
|
On computer: VIRTPC
|
||||||
|
|
||||||
|
Disk 0 is now the selected disk.
|
||||||
|
|
||||||
|
Partition 1 is now the selected partition.
|
||||||
|
|
||||||
|
Partition 1
|
||||||
|
Type : c12a7328-f81f-11d2-ba4b-00a0c93ec93b
|
||||||
|
Hidden : Yes
|
||||||
|
Required: No
|
||||||
|
Attrib : 0X8000000000000000
|
||||||
|
Offset in Bytes: 1048576
|
||||||
|
|
||||||
|
Volume ### Ltr Label Fs Type Size Status Info
|
||||||
|
---------- --- ----------- ----- ---------- ------- --------- --------
|
||||||
|
* Volume 2 S ESP FAT32 Partition 260 MB Healthy System
|
||||||
|
";
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub static SELECT_PART_DETAIL_PARTS: &str = "
|
||||||
|
Microsoft DiskPart version 10.0.22621.1
|
||||||
|
|
||||||
|
Copyright (C) Microsoft Corporation.
|
||||||
|
On computer: VIRTPC
|
||||||
|
|
||||||
|
Disk 0 is now the selected disk.
|
||||||
|
|
||||||
|
Partition 1 is now the selected partition.
|
||||||
|
|
||||||
|
Partition 1
|
||||||
|
Type : c12a7328-f81f-11d2-ba4b-00a0c93ec93b
|
||||||
|
Hidden : Yes
|
||||||
|
Required: No
|
||||||
|
Attrib : 0X8000000000000000
|
||||||
|
Offset in Bytes: 1048576
|
||||||
|
|
||||||
|
Volume ### Ltr Label Fs Type Size Status Info
|
||||||
|
---------- --- ----------- ----- ---------- ------- --------- --------
|
||||||
|
* Volume 2 ESP FAT32 Partition 260 MB Healthy System
|
||||||
|
|
||||||
|
Partition 2 is now the selected partition.
|
||||||
|
|
||||||
|
Partition 2
|
||||||
|
Type : e3c9e316-0b5c-4db8-817d-f92df00215ae
|
||||||
|
Hidden : Yes
|
||||||
|
Required: No
|
||||||
|
Attrib : 0X8000000000000000
|
||||||
|
Offset in Bytes: 273678336
|
||||||
|
|
||||||
|
There is no volume associated with this partition.
|
||||||
|
|
||||||
|
Partition 4 is now the selected partition.
|
||||||
|
|
||||||
|
Partition 4
|
||||||
|
Type : ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
|
||||||
|
Hidden : No
|
||||||
|
Required: No
|
||||||
|
Attrib : 0000000000000000
|
||||||
|
Offset in Bytes: 290455552
|
||||||
|
|
||||||
|
Volume ### Ltr Label Fs Type Size Status Info
|
||||||
|
---------- --- ----------- ----- ---------- ------- --------- --------
|
||||||
|
* Volume 1 C Windows NTFS Partition 47 GB Healthy Boot
|
||||||
|
";
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub static SPLIT_SECTIONS: &[&str] = &[
|
||||||
|
"
|
||||||
|
Microsoft DiskPart version 10.0.22621.1
|
||||||
|
|
||||||
|
Copyright (C) Microsoft Corporation.
|
||||||
|
On computer: VIRTPC
|
||||||
|
|
||||||
|
Disk ### Status Size Free Dyn Gpt
|
||||||
|
-------- ------------- ------- ------- --- ---
|
||||||
|
Disk 0 Online 50 GB 1024 KB
|
||||||
|
Disk 2 Online 60 GB 15 MB *
|
||||||
|
",
|
||||||
|
"Disk 0 is now the selected disk.
|
||||||
|
|
||||||
|
Red Hat VirtIO SCSI Disk Device
|
||||||
|
Disk ID: F0152E21
|
||||||
|
Type : SCSI
|
||||||
|
Status : Online
|
||||||
|
Path : 0
|
||||||
|
Target : 0
|
||||||
|
LUN ID : 0
|
||||||
|
Location Path : PCIROOT(0)#PCI(0204)#PCI(0000)#SCSI(P00T00L00)
|
||||||
|
Current Read-only State : No
|
||||||
|
Read-only : No
|
||||||
|
Boot Disk : Yes
|
||||||
|
Pagefile Disk : Yes
|
||||||
|
Hibernation File Disk : No
|
||||||
|
Crashdump Disk : Yes
|
||||||
|
Clustered Disk : No
|
||||||
|
|
||||||
|
Volume ### Ltr Label Fs Type Size Status Info
|
||||||
|
---------- --- ----------- ----- ---------- ------- --------- --------
|
||||||
|
Volume 1 F System Rese NTFS Partition 100 MB Healthy System
|
||||||
|
Volume 2 C NTFS Partition 49 GB Healthy Boot
|
||||||
|
Volume 3 NTFS Partition 757 MB Healthy Hidden
|
||||||
|
|
||||||
|
Partition ### Type Size Offset
|
||||||
|
------------- ---------------- ------- -------
|
||||||
|
Partition 1 Primary 100 MB 1024 KB
|
||||||
|
Partition 2 Primary 49 GB 101 MB
|
||||||
|
Partition 3 Recovery 757 MB 49 GB
|
||||||
|
",
|
||||||
|
"Disk 2 is now the selected disk.
|
||||||
|
|
||||||
|
Red Hat VirtIO SCSI Disk Device
|
||||||
|
Disk ID: {7EBCAB6D-5D60-4C08-8EBC-D212A0DAF53F}
|
||||||
|
Type : SCSI
|
||||||
|
Status : Online
|
||||||
|
Path : 0
|
||||||
|
Target : 0
|
||||||
|
LUN ID : 0
|
||||||
|
Location Path : PCIROOT(0)#PCI(0205)#PCI(0000)#SCSI(P00T00L00)
|
||||||
|
Current Read-only State : No
|
||||||
|
Read-only : No
|
||||||
|
Boot Disk : No
|
||||||
|
Pagefile Disk : No
|
||||||
|
Hibernation File Disk : No
|
||||||
|
Crashdump Disk : No
|
||||||
|
Clustered Disk : No
|
||||||
|
|
||||||
|
Volume ### Ltr Label Fs Type Size Status Info
|
||||||
|
---------- --- ----------- ----- ---------- ------- --------- --------
|
||||||
|
Volume 4 E Scratch NTFS Partition 59 GB Healthy
|
||||||
|
|
||||||
|
Partition ### Type Size Offset
|
||||||
|
------------- ---------------- ------- -------
|
||||||
|
Partition 1 Reserved 16 MB 16 MB
|
||||||
|
Partition 2 Primary 59 GB 32 MB
|
||||||
|
|
||||||
|
Reached the end of the disk enumeration.
|
||||||
|
|
||||||
|
There is no disk selected.
|
||||||
|
",
|
||||||
|
];
|
||||||
Loading…
Reference in a new issue