From 107da8d780ccdc5f7a21b379bfae01f07381a0aa Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 19 Oct 2023 17:43:17 +0200 Subject: [PATCH] efiboot(test): add more tests for `efiboot boot next` subcommands --- efiboot/src/cli/boot/tests/next.rs | 78 +++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/efiboot/src/cli/boot/tests/next.rs b/efiboot/src/cli/boot/tests/next.rs index 348c9d88..467b427b 100644 --- a/efiboot/src/cli/boot/tests/next.rs +++ b/efiboot/src/cli/boot/tests/next.rs @@ -1,5 +1,9 @@ use clap::Parser; -use efivar::{efi::Variable, store::MemoryStore, utils, VarReader}; +use efivar::{ + efi::{Variable, VariableFlags}, + store::MemoryStore, + utils, VarReader, VarWriter, +}; use crate::{ cli::{boot::tests::add_entry, Command}, @@ -38,3 +42,75 @@ fn set_inexistent_next() { assert!(!manager.exists(&Variable::new("BootNext")).unwrap()); } + +#[test] +fn unset_next() { + let manager = &mut MemoryStore::new(); + + manager + .write( + &Variable::new("BootNext"), + VariableFlags::default(), + &utils::u16_to_u8(&[0x0001]), + ) + .unwrap(); + + assert_eq!( + ExitCode::SUCCESS, + crate::run( + Command::parse_from(["efiboot", "boot", "next", "unset"]), + manager, + ) + ); + + assert!(!manager.exists(&Variable::new("BootNext")).unwrap()); +} + +#[test] +fn unset_inexistent_next() { + let manager = &mut MemoryStore::new(); + + assert_eq!( + ExitCode::FAILURE, + crate::run( + Command::parse_from(["efiboot", "boot", "next", "unset"]), + manager, + ) + ); + + assert!(!manager.exists(&Variable::new("BootNext")).unwrap()); +} + +#[test] +fn get_next() { + let manager = &mut MemoryStore::new(); + + manager + .write( + &Variable::new("BootNext"), + VariableFlags::default(), + &utils::u16_to_u8(&[0x0001]), + ) + .unwrap(); + + assert_eq!( + ExitCode::SUCCESS, + crate::run( + Command::parse_from(["efiboot", "boot", "next", "get"]), + manager, + ) + ); +} + +#[test] +fn get_inexistent_next() { + let manager = &mut MemoryStore::new(); + + assert_eq!( + ExitCode::FAILURE, + crate::run( + Command::parse_from(["efiboot", "boot", "next", "get"]), + manager, + ) + ); +}