[pve-devel] [PATCH v2 proxmox 3/5] apt: tests: create temporary test directories in CARGO_TARGET_TMPDIR
Fiona Ebner
f.ebner at proxmox.com
Fri Jun 2 10:48:22 CEST 2023
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
New in v2.
proxmox-apt/tests/repositories.rs | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/proxmox-apt/tests/repositories.rs b/proxmox-apt/tests/repositories.rs
index 4b3c9de..6319a62 100644
--- a/proxmox-apt/tests/repositories.rs
+++ b/proxmox-apt/tests/repositories.rs
@@ -19,15 +19,11 @@ fn test_parse_write() -> Result<(), Error> {
fn test_parse_write_dir(read_dir: &str) -> Result<(), Error> {
let test_dir = std::env::current_dir()?.join("tests");
+ let tmp_dir = PathBuf::from(env!("CARGO_TARGET_TMPDIR").to_string());
let read_dir = test_dir.join(read_dir);
- let write_dir = test_dir.join("sources.list.d.actual");
+ let write_dir = tmp_dir.join("sources.list.d.actual");
let expected_dir = test_dir.join("sources.list.d.expected");
- if write_dir.is_dir() {
- std::fs::remove_dir_all(&write_dir)
- .map_err(|err| format_err!("unable to remove dir {:?} - {}", write_dir, err))?;
- }
-
std::fs::create_dir_all(&write_dir)
.map_err(|err| format_err!("unable to create dir {:?} - {}", write_dir, err))?;
@@ -66,6 +62,7 @@ fn test_parse_write_dir(read_dir: &str) -> Result<(), Error> {
expected_count += 1;
let expected_path = entry?.path();
+
let actual_path = write_dir.join(expected_path.file_name().unwrap());
let expected_contents = std::fs::read(&expected_path)
@@ -91,13 +88,9 @@ fn test_parse_write_dir(read_dir: &str) -> Result<(), Error> {
#[test]
fn test_digest() -> Result<(), Error> {
let test_dir = std::env::current_dir()?.join("tests");
+ let tmp_dir = PathBuf::from(env!("CARGO_TARGET_TMPDIR").to_string());
let read_dir = test_dir.join("sources.list.d");
- let write_dir = test_dir.join("sources.list.d.digest");
-
- if write_dir.is_dir() {
- std::fs::remove_dir_all(&write_dir)
- .map_err(|err| format_err!("unable to remove dir {:?} - {}", write_dir, err))?;
- }
+ let write_dir = tmp_dir.join("sources.list.d.digest");
std::fs::create_dir_all(&write_dir)
.map_err(|err| format_err!("unable to create dir {:?} - {}", write_dir, err))?;
--
2.39.2
More information about the pve-devel
mailing list