From 7929292618ed43f80c57d68883323742def184b2 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 3 Feb 2021 09:34:31 +0100 Subject: [PATCH] tape: add regresion test for media state --- src/tape/test/inventory.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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> {