[pbs-devel] [RFC PATCH proxmox-backup 2/2] tape/inventory: fix the tape tests as user by mocking the lock

Dominik Csapak d.csapak at proxmox.com
Fri Sep 3 09:17:52 CEST 2021


locking during the tests as regular user failed because we try to
chown to the backup user (which is not always possible).

Instead, do not lock at all, by mocking the 'open_backup_lockfile' with
an empty struct that implements the locking trait

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/tape/inventory.rs | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/tape/inventory.rs b/src/tape/inventory.rs
index d56b2144..f45cec71 100644
--- a/src/tape/inventory.rs
+++ b/src/tape/inventory.rs
@@ -40,7 +40,28 @@ use proxmox::tools::{
 };
 
 use pbs_systemd::time::compute_next_event;
-use pbs_config::{open_backup_lockfile, BackupLockGuard};
+use pbs_config::BackupLockGuard;
+
+#[cfg(not(test))]
+use pbs_config::open_backup_lockfile;
+
+#[cfg(test)]
+mod lock_mocking {
+    struct MockedLock;
+
+    impl pbs_config::BackupLockGuardTrait for MockedLock {}
+
+    pub fn open_backup_lockfile<P: AsRef<std::path::Path>>(
+        _path: P,
+        _timeout: Option<std::time::Duration>,
+        _exclusive: bool,
+    ) -> Result<pbs_config::BackupLockGuard, anyhow::Error> {
+        Ok(Box::new(MockedLock))
+    }
+}
+
+#[cfg(test)]
+use lock_mocking::*;
 
 use crate::{
     api2::types::{
-- 
2.30.2






More information about the pbs-devel mailing list