Skip to content

Commit

Permalink
test(efiboot): add test for add::get_used_ids() helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
iTrooz committed Oct 19, 2023
1 parent ddf619c commit 11ed174
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion efiboot/src/cli/boot/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use efivar::{
use itertools::Itertools;

/// get a boot entry ID that isnt used
fn get_used_ids(manager: &dyn VarManager) -> Vec<u16> {
pub fn get_used_ids(manager: &dyn VarManager) -> Vec<u16> {
manager
.get_all_vars()
.unwrap()
Expand Down
25 changes: 25 additions & 0 deletions efiboot/src/cli/boot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use uuid::Uuid;

use crate::{cli::Command, exit_code::ExitCode};

use super::add::get_used_ids;

#[test]
fn add_on_current_partition() {
//! Test that the basic `efiboot boot add` subcommand works.
Expand Down Expand Up @@ -111,3 +113,26 @@ fn add_on_current_partition() {
let (data, _) = manager.read(&Variable::new("BootOrder")).unwrap();
assert_eq!(data, utils::u16_to_u8(&[0x0000, 0x0001, 0x0002]));
}

#[test]
fn get_used_boot_ids() {
let manager = &mut MemoryStore::new();

manager
.write(&Variable::new("Boot0001"), VariableFlags::default(), &[])
.unwrap();
manager
.write(&Variable::new("Boot1000"), VariableFlags::default(), &[])
.unwrap();
manager
.write(&Variable::new("Boot0500"), VariableFlags::default(), &[])
.unwrap();
manager
.write(&Variable::new("BootFFFF"), VariableFlags::default(), &[])
.unwrap();

let mut used_ids = get_used_ids(manager);
used_ids.sort();

assert_eq!(used_ids, vec![0x0001, 0x0500, 0x1000, 0xFFFF]);
}

0 comments on commit 11ed174

Please sign in to comment.