From: Wolfgang Bumiller Date: Mon, 19 Jul 2021 11:00:16 +0000 (+0200) Subject: doc and tests fixup X-Git-Tag: v2.0.10~179 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=a3399f4337f9e54b068e2545be63d7197a87c7e7;p=proxmox-backup.git doc and tests fixup Signed-off-by: Wolfgang Bumiller --- diff --git a/pbs-client/src/tools/key_source.rs b/pbs-client/src/tools/key_source.rs index 340fe234..aeb99feb 100644 --- a/pbs-client/src/tools/key_source.rs +++ b/pbs-client/src/tools/key_source.rs @@ -360,6 +360,18 @@ pub fn get_encryption_key_password() -> Result, Error> { bail!("no password input mechanism available"); } +#[cfg(test)] +fn create_testdir(name: &str) -> Result { + let mut testdir: PathBuf = String::from("./target/testout").into(); + testdir.push(std::module_path!()); + testdir.push(name); + + let _ = std::fs::remove_dir_all(&testdir); + let _ = std::fs::create_dir_all(&testdir); + + Ok(testdir.to_str().unwrap().to_string()) +} + #[test] // WARNING: there must only be one test for crypto_parameters as the default key handling is not // safe w.r.t. concurrency @@ -373,9 +385,11 @@ fn test_crypto_parameters_handling() -> Result<(), Error> { let some_master_key = vec![3;1]; let default_master_key = vec![4;1]; - let keypath = "./target/testout/keyfile.test"; - let master_keypath = "./target/testout/masterkeyfile.test"; - let invalid_keypath = "./target/testout/invalid_keyfile.test"; + let testdir = create_testdir("key_source")?; + + let keypath = format!("{}/keyfile.test", testdir); + let master_keypath = format!("{}/masterkeyfile.test", testdir); + let invalid_keypath = format!("{}/invalid_keyfile.test", testdir); let no_key_res = CryptoParams { enc_key: None, diff --git a/pbs-tools/Cargo.toml b/pbs-tools/Cargo.toml index e149f048..0492338d 100644 --- a/pbs-tools/Cargo.toml +++ b/pbs-tools/Cargo.toml @@ -32,3 +32,6 @@ walkdir = "2" proxmox = { version = "0.11.5", default-features = false, features = [ "tokio" ] } pbs-buildcfg = { path = "../pbs-buildcfg" } + +[dev-dependencies] +tokio = { version = "1.6", features = [ "macros" ] } diff --git a/pbs-tools/src/xattr.rs b/pbs-tools/src/xattr.rs index 500af326..5e7845e7 100644 --- a/pbs-tools/src/xattr.rs +++ b/pbs-tools/src/xattr.rs @@ -191,7 +191,7 @@ mod tests { #[test] fn test_fsetxattr_fgetxattr() { - let path = "./tests/xattrs.txt"; + let path = "./test-xattrs.txt"; let file = OpenOptions::new() .write(true) .create(true) diff --git a/pbs-tools/src/zip.rs b/pbs-tools/src/zip.rs index c0bf76cd..605480a8 100644 --- a/pbs-tools/src/zip.rs +++ b/pbs-tools/src/zip.rs @@ -418,9 +418,10 @@ where /// 'add_entry'. To Finish the file, call 'finish' /// Example: /// ```no_run -/// use proxmox_backup::tools::zip::*; -/// use tokio::fs::File; /// use anyhow::{Error, Result}; +/// use tokio::fs::File; +/// +/// use pbs_tools::zip::{ZipEncoder, ZipEntry}; /// /// #[tokio::main] /// async fn main() -> Result<(), Error> { diff --git a/src/tools/statistics.rs b/src/tools/statistics.rs index 2a0e429c..36e64667 100644 --- a/src/tools/statistics.rs +++ b/src/tools/statistics.rs @@ -79,8 +79,8 @@ where Some(covariance/(len_x as f64)) } -/// Returns the factors (a,b) of a linear regression y = a + bx -/// for the variables [x,y] or None if the lists are not the same length +/// Returns the factors `(a,b)` of a linear regression `y = a + bx` +/// for the variables `[x,y]` or `None` if the lists are not the same length /// ``` /// # use proxmox_backup::tools::statistics::linear_regression; ///