tape: add regresion test for media state

This commit is contained in:
Dietmar Maurer 2021-02-03 09:34:31 +01:00
parent 0d4e4cae7f
commit 7929292618

View File

@ -10,6 +10,10 @@ use proxmox::tools::{
}; };
use crate::{ use crate::{
api2::types::{
MediaLocation,
MediaStatus,
},
tape::{ tape::{
Inventory, Inventory,
file_formats::{ file_formats::{
@ -29,6 +33,37 @@ fn create_testdir(name: &str) -> Result<PathBuf, Error> {
Ok(testdir) 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] #[test]
fn test_list_pool_media() -> Result<(), Error> { fn test_list_pool_media() -> Result<(), Error> {