use rsdisk::{self, partition_tables::PartitionTable}; fn reset_mbr() { let mut mbr = rsdisk::partition_tables::mbr::MBR::read("tests/MBR_TEST").unwrap(); let _ = mbr.delete_partition(1); let _ = mbr.delete_partition(2); let _ = mbr.delete_partition(3); let _ = mbr.delete_partition(4); let _ = mbr.write("tests/MBR_TEST"); } fn read_mbr() -> Vec<(u64, u64)> { rsdisk::partition_tables::mbr::MBR::read("tests/MBR_TEST").unwrap().list_partitions().unwrap() } #[test] fn check_mbr() { assert!(matches!(rsdisk::utils::check_partition_type("tests/MBR_TEST"), Ok(rsdisk::partition_tables::PartitionTables::MBR))); } #[test] fn check_gpt() { assert!(matches!(rsdisk::utils::check_partition_type("tests/GPT_TEST"), Ok(rsdisk::partition_tables::PartitionTables::GPT))); } // #[test] // fn wrong_path_refresh_partition_table() { // let err = std::io::Error::new(, ) // assert!(matches!(rsdisk::utils::refresh_partition_table("/wrong/path"), Err(rsdisk::errors::rsdiskErrors::IOErrors("No such file or directory (os error 2)".to_string())))); // } #[test] fn empty_partition_table() { let result = rsdisk::utils::check_partition_type("tests/EMPTY_TEST"); assert!(matches!(result, Err(rsdisk::errors::rsdiskErrors::InvalidPartitionType))); } #[test] fn create_partition_mbr() { reset_mbr(); let mut mbr = rsdisk::partition_tables::mbr::MBR::read("tests/MBR_TEST").unwrap(); mbr.create_partition(1024, 2048); let state = mbr.list_partitions().unwrap(); mbr.write("tests/MBR_TEST"); assert_eq!(state, read_mbr()); } // #[test] // fn resize_partition_mbr() { // reset_mbr(); // let mut mbr = rsdisk::partition_tables::mbr::MBR::read("tests/MBR_TEST").unwrap(); // mbr.resize_partition(0, 54); // (state, read_mbr()); // } #[test] fn mbr_invalid_partition_id_in_resize() { let mut mbr = rsdisk::partition_tables::mbr::MBR::read("tests/MBR_TEST").unwrap(); assert!(matches!(mbr.resize_partition(431, 0), Err(rsdisk::errors::rsdiskErrors::InvalidPartitionID))); } #[test] fn mbr_invalid_partition_id_in_del() { let mut mbr = rsdisk::partition_tables::mbr::MBR::read("tests/MBR_TEST").unwrap(); assert!(matches!(mbr.delete_partition(431), Err(rsdisk::errors::rsdiskErrors::InvalidPartitionID))); } #[test] fn mbr_too_large_partition_size() { let mut mbr = rsdisk::partition_tables::mbr::MBR::read("tests/MBR_TEST").unwrap(); assert!(matches!(mbr.create_partition(u32::MAX as u64, 0), Err(rsdisk::errors::rsdiskErrors::TooBigForPartitionTable(0)))); assert!(matches!(mbr.create_partition(0, u32::MAX as u64 + 1), Err(rsdisk::errors::rsdiskErrors::TooBigForPartitionTable(1)))); assert!(matches!(mbr.resize_partition(1, u32::MAX as u64 + 1), Err(rsdisk::errors::rsdiskErrors::TooBigForPartitionTable(1)))); }