Skip to content

Commit 54ebb50

Browse files
committed
test: cover the find_immutables_dir function to show recursivity
1 parent 78f6fcd commit 54ebb50

File tree

1 file changed

+27
-0
lines changed
  • internal/cardano-node/mithril-cardano-node-internal-database/src/entities

1 file changed

+27
-0
lines changed

internal/cardano-node/mithril-cardano-node-internal-database/src/entities/immutable_file.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,33 @@ mod tests {
426426
);
427427
}
428428

429+
#[test]
430+
fn find_immutables_dir_returns_none_if_no_immutable_dir_found() {
431+
let database_path = temp_dir_create!();
432+
assert!(find_immutables_dir(&database_path).is_none());
433+
}
434+
435+
#[test]
436+
fn find_immutables_dir_returns_immutable_dir_if_found_at_root() {
437+
let database_path = temp_dir_create!();
438+
fs::create_dir(database_path.join(IMMUTABLE_DIR)).unwrap();
439+
440+
let immutable_dir =
441+
find_immutables_dir(&database_path).expect("Immutable directory should be found");
442+
assert_eq!(immutable_dir, database_path.join(IMMUTABLE_DIR));
443+
}
444+
445+
#[test]
446+
fn find_immutables_dir_returns_immutable_dir_if_found_at_any_depth() {
447+
let database_path = temp_dir_create!();
448+
let subdir = database_path.join("one/two/three");
449+
fs::create_dir_all(subdir.join(IMMUTABLE_DIR)).unwrap();
450+
451+
let immutable_dir =
452+
find_immutables_dir(&database_path).expect("Immutable directory should be found");
453+
assert_eq!(immutable_dir, subdir.join(IMMUTABLE_DIR));
454+
}
455+
429456
#[test]
430457
fn at_least_one_immutable_files_exist_in_dir_throw_error_if_immutable_dir_is_empty() {
431458
let database_path = temp_dir_create!();

0 commit comments

Comments
 (0)