tests: do not use TempDir::into_path() which would persist the directory

https://docs.rs/tempfile/3.3.0/tempfile/struct.TempDir.html#method.into_path
This commit is contained in:
Yuya Nishihara 2022-09-07 12:53:45 +09:00
parent 872081c867
commit 3b835df66e

View file

@ -106,9 +106,9 @@ fn test_bad_locking_children(use_git: bool) {
tx.commit();
// Simulate a write of a commit that happens on one machine
let machine1_root = testutils::new_temp_dir().into_path();
copy_directory(workspace_root, &machine1_root);
let machine1_workspace = Workspace::load(&settings, machine1_root.clone()).unwrap();
let machine1_root = testutils::new_temp_dir();
copy_directory(workspace_root, machine1_root.path());
let machine1_workspace = Workspace::load(&settings, machine1_root.path().to_owned()).unwrap();
let machine1_repo = machine1_workspace
.repo_loader()
.load_at_head()
@ -121,9 +121,9 @@ fn test_bad_locking_children(use_git: bool) {
machine1_tx.commit();
// Simulate a write of a commit that happens on another machine
let machine2_root = testutils::new_temp_dir().into_path();
copy_directory(workspace_root, &machine2_root);
let machine2_workspace = Workspace::load(&settings, machine2_root.clone()).unwrap();
let machine2_root = testutils::new_temp_dir();
copy_directory(workspace_root, machine2_root.path());
let machine2_workspace = Workspace::load(&settings, machine2_root.path().to_owned()).unwrap();
let machine2_repo = machine2_workspace
.repo_loader()
.load_at_head()
@ -137,9 +137,14 @@ fn test_bad_locking_children(use_git: bool) {
// Simulate that the distributed file system now has received the changes from
// both machines
let merged_path = testutils::new_temp_dir().into_path();
merge_directories(&machine1_root, workspace_root, &machine2_root, &merged_path);
let merged_workspace = Workspace::load(&settings, merged_path).unwrap();
let merged_path = testutils::new_temp_dir();
merge_directories(
machine1_root.path(),
workspace_root,
machine2_root.path(),
merged_path.path(),
);
let merged_workspace = Workspace::load(&settings, merged_path.path().to_owned()).unwrap();
let merged_repo = merged_workspace
.repo_loader()
.load_at_head()
@ -173,15 +178,15 @@ fn test_bad_locking_interrupted(use_git: bool) {
// operation and then copying that back afterwards, leaving the existing
// op-head(s) in place.
let op_heads_dir = repo.repo_path().join("op_heads");
let backup_path = testutils::new_temp_dir().into_path();
copy_directory(&op_heads_dir, &backup_path);
let backup_path = testutils::new_temp_dir();
copy_directory(&op_heads_dir, backup_path.path());
let mut tx = repo.start_transaction("test");
testutils::create_random_commit(&settings, &repo)
.set_parents(vec![initial.id().clone()])
.write_to_repo(tx.mut_repo());
let op_id = tx.commit().operation().id().clone();
copy_directory(&backup_path, &op_heads_dir);
copy_directory(backup_path.path(), &op_heads_dir);
// Reload the repo and check that only the new head is present.
let reloaded_repo = ReadonlyRepo::load_at_head(&settings, repo.repo_path().clone()).unwrap();
assert_eq!(reloaded_repo.op_id(), &op_id);