Skip to content

Commit c6f512b

Browse files
committed
Add a test that check existing dir removal when created a TestDir
1 parent 481f922 commit c6f512b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

mithril-common/src/test_utils/temp_dir.rs

+25
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ impl TempDir {
115115
#[cfg(test)]
116116
mod tests {
117117
use super::*;
118+
use std::{fs, io::Write, ops::Not};
118119

119120
#[test]
120121
fn non_short_path_are_in_a_mithril_test_slash_module_folder_structure() {
@@ -204,4 +205,28 @@ mod tests {
204205

205206
assert_ne!(path1, path2);
206207
}
208+
209+
#[test]
210+
fn creating_temp_dir_remove_existing_content() {
211+
let builder = TempDir::new("temp_dir", "creating_temp_dir_remove_existing_content");
212+
let (existing_dir, existing_file) = {
213+
let path = builder.build_path();
214+
(path.join("existing_subdir"), path.join("existing_file.md"))
215+
};
216+
217+
fs::create_dir_all(&existing_dir).unwrap();
218+
let mut file = fs::File::create(&existing_file).unwrap();
219+
file.write_all(b"file content").unwrap();
220+
221+
builder.build();
222+
223+
assert!(
224+
existing_file.exists().not(),
225+
"should have cleaned up existing files"
226+
);
227+
assert!(
228+
existing_dir.exists().not(),
229+
"should have cleaned up existing subdirectory"
230+
);
231+
}
207232
}

0 commit comments

Comments
 (0)