diff --git a/src/tape/test/inventory.rs b/src/tape/test/inventory.rs index af8d80b5..3aa58265 100644 --- a/src/tape/test/inventory.rs +++ b/src/tape/test/inventory.rs @@ -10,6 +10,10 @@ use proxmox::tools::{ }; use crate::{ + api2::types::{ + MediaLocation, + MediaStatus, + }, tape::{ Inventory, file_formats::{ @@ -29,6 +33,37 @@ fn create_testdir(name: &str) -> Result { Ok(testdir) } +#[test] +fn test_media_state_db() -> Result<(), Error> { + + let testdir = create_testdir("test_media_state_db")?; + + let mut inventory = Inventory::load(&testdir)?; + + let uuid1: Uuid = inventory.generate_free_tape("tape1", 0); + + assert_eq!(inventory.status_and_location(&uuid1), (MediaStatus::Unknown, MediaLocation::Offline)); + + inventory.set_media_status_full(&uuid1)?; + + assert_eq!(inventory.status_and_location(&uuid1), (MediaStatus::Full, MediaLocation::Offline)); + + inventory.set_media_location_vault(&uuid1, "Office2")?; + assert_eq!(inventory.status_and_location(&uuid1), + (MediaStatus::Full, MediaLocation::Vault(String::from("Office2")))); + + inventory.set_media_location_offline(&uuid1)?; + assert_eq!(inventory.status_and_location(&uuid1), (MediaStatus::Full, MediaLocation::Offline)); + + inventory.set_media_status_damaged(&uuid1)?; + assert_eq!(inventory.status_and_location(&uuid1), (MediaStatus::Damaged, MediaLocation::Offline)); + + inventory.clear_media_status(&uuid1)?; + assert_eq!(inventory.status_and_location(&uuid1), (MediaStatus::Unknown, MediaLocation::Offline)); + + Ok(()) +} + #[test] fn test_list_pool_media() -> Result<(), Error> {