Skip to content

Commit 6e70001

Browse files
committed
refactor: in test use assert_dir_eq where applicable
1 parent ee1ae73 commit 6e70001

File tree

6 files changed

+72
-58
lines changed

6 files changed

+72
-58
lines changed

mithril-aggregator/src/services/snapshotter/compressed_archive_snapshotter.rs

+30-28
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ mod tests {
309309

310310
use mithril_common::digesters::DummyCardanoDbBuilder;
311311
use mithril_common::test_utils::assert_equivalent;
312-
use mithril_common::{current_function, temp_dir_create};
312+
use mithril_common::{assert_dir_eq, current_function, temp_dir_create};
313313

314314
use crate::services::ancillary_signer::MockAncillarySigner;
315315
use crate::test_tools::TestLogger;
@@ -509,7 +509,6 @@ mod tests {
509509
}
510510

511511
mod snapshot_ancillary {
512-
use mithril_common::digesters::VOLATILE_DIR;
513512
use mithril_common::test_utils::fake_keys;
514513

515514
use super::*;
@@ -524,19 +523,24 @@ mod tests {
524523
.build();
525524
let snapshotter =
526525
snapshotter_for_test(&test_dir, cardano_db.get_dir(), CompressionAlgorithm::Gzip);
526+
let ancillary_snapshot_dir = test_dir.join("ancillary_snapshot");
527+
fs::create_dir(&ancillary_snapshot_dir).unwrap();
527528

528529
snapshotter
529-
.get_files_and_directories_for_ancillary_snapshot(1, &test_dir)
530+
.get_files_and_directories_for_ancillary_snapshot(1, &ancillary_snapshot_dir)
530531
.unwrap();
531-
assert!(test_dir.join(IMMUTABLE_DIR).exists());
532-
assert!(test_dir.join(IMMUTABLE_DIR).join("00002.chunk").exists());
533-
assert!(test_dir.join(IMMUTABLE_DIR).join("00002.primary").exists());
534-
assert!(test_dir
535-
.join(IMMUTABLE_DIR)
536-
.join("00002.secondary")
537-
.exists());
538-
assert!(test_dir.join(LEDGER_DIR).exists());
539-
assert!(test_dir.join(LEDGER_DIR).join("737").exists());
532+
533+
assert_dir_eq!(
534+
&ancillary_snapshot_dir,
535+
format!(
536+
"* {IMMUTABLE_DIR}/
537+
** 00002.chunk
538+
** 00002.primary
539+
** 00002.secondary
540+
* {LEDGER_DIR}/
541+
** 737"
542+
)
543+
);
540544
}
541545

542546
#[tokio::test]
@@ -616,22 +620,20 @@ mod tests {
616620
.unwrap();
617621

618622
let unpack_dir = snapshot.unpack_gzip(&test_dir);
619-
620-
let expected_immutable_path = unpack_dir.join(IMMUTABLE_DIR);
621-
assert!(expected_immutable_path.join("00003.chunk").exists());
622-
assert!(expected_immutable_path.join("00003.primary").exists());
623-
assert!(expected_immutable_path.join("00003.secondary").exists());
624-
assert_eq!(3, list_files(&expected_immutable_path).len());
625-
626-
// Only the last ledger file should be included
627-
let expected_ledger_path = unpack_dir.join(LEDGER_DIR);
628-
assert!(expected_ledger_path.join("737").exists());
629-
assert_eq!(1, list_files(&expected_ledger_path).len());
630-
631-
let expected_volatile_path = unpack_dir.join(VOLATILE_DIR);
632-
assert!(!expected_volatile_path.exists());
633-
634-
assert!(!unpack_dir.join("whatever").exists());
623+
assert_dir_eq!(
624+
&unpack_dir,
625+
// Only the last ledger file should be included
626+
format!(
627+
"* {IMMUTABLE_DIR}/
628+
** 00003.chunk
629+
** 00003.primary
630+
** 00003.secondary
631+
* {LEDGER_DIR}/
632+
** 737
633+
* {}",
634+
AncillaryFilesManifest::ANCILLARY_MANIFEST_FILE_NAME
635+
)
636+
);
635637
}
636638

637639
#[tokio::test]

mithril-aggregator/src/tools/file_archiver/appender.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ mod tests {
263263
DummyCardanoDbBuilder, IMMUTABLE_DIR, LEDGER_DIR, VOLATILE_DIR,
264264
};
265265
use mithril_common::entities::CompressionAlgorithm;
266-
use mithril_common::temp_dir_create;
266+
use mithril_common::{assert_dir_eq, temp_dir_create};
267267

268268
use crate::tools::file_archiver::test_tools::*;
269269
use crate::tools::file_archiver::{ArchiveParameters, FileArchiver};
@@ -280,8 +280,8 @@ mod tests {
280280

281281
let directory_to_archive_path = create_dir(&source, "directory_to_archive");
282282
let file_to_archive_path = create_file(&source, "file_to_archive.txt");
283-
let directory_not_to_archive_path = create_dir(&source, "directory_not_to_archive");
284-
let file_not_to_archive_path = create_file(&source, "file_not_to_archive.txt");
283+
create_dir(&source, "directory_not_to_archive");
284+
create_file(&source, "file_not_to_archive.txt");
285285

286286
let file_archiver = FileArchiver::new_for_test(test_dir.join("verification"));
287287

@@ -305,10 +305,11 @@ mod tests {
305305

306306
let unpack_path = archive.unpack_gzip(&test_dir);
307307

308-
assert!(unpack_path.join(directory_to_archive_path).is_dir());
309-
assert!(unpack_path.join(file_to_archive_path).is_file());
310-
assert!(!unpack_path.join(directory_not_to_archive_path).exists());
311-
assert!(!unpack_path.join(file_not_to_archive_path).exists());
308+
assert_dir_eq!(
309+
&unpack_path,
310+
"* directory_to_archive/
311+
* file_to_archive.txt"
312+
);
312313
}
313314

314315
#[test]
@@ -371,8 +372,11 @@ mod tests {
371372

372373
let unpack_path = archive.unpack_gzip(&test_dir);
373374

374-
assert!(unpack_path.join(directory_to_archive_path).is_dir());
375-
assert!(unpack_path.join(file_to_archive_path).is_file());
375+
assert_dir_eq!(
376+
&unpack_path,
377+
"* directory_to_archive/
378+
** file_to_archive.txt"
379+
);
376380
}
377381

378382
#[test]
@@ -572,7 +576,7 @@ mod tests {
572576
let mtime = appended_entry.header().mtime().unwrap();
573577
assert!(
574578
mtime >= start_time_stamp,
575-
"entry mtime should be greater than or equal to the timestamp before the archive\
579+
"entry mtime should be greater than or equal to the timestamp before the archive \
576580
creation:\n {mtime} < {start_time_stamp}"
577581
);
578582
}

mithril-client/src/cardano_database_client/download_unpack/download_task.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub struct LocationToDownload {
163163
#[cfg(test)]
164164
mod tests {
165165
use mithril_common::entities::FileUri;
166-
use mithril_common::test_utils::{fake_keys, temp_dir_create};
166+
use mithril_common::test_utils::{assert_dir_eq, fake_keys, temp_dir_create};
167167

168168
use crate::file_downloader::MockFileDownloaderBuilder;
169169
use crate::test_utils::TestLogger;
@@ -467,9 +467,7 @@ mod tests {
467467
.await
468468
.unwrap();
469469

470-
assert!(target_dir.join("dummy_ledger").exists());
471-
assert!(!target_dir.join("not_in_ancillary").exists());
472-
assert!(!temp_ancillary_target_dir(&target_dir, "download-id").exists());
470+
assert_dir_eq!(&target_dir, "* dummy_ledger");
473471
}
474472
}
475473
}

mithril-client/src/file_downloader/mock_builder.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl MockFileDownloaderBuilder {
220220

221221
#[cfg(test)]
222222
mod tests {
223-
use mithril_common::temp_dir_create;
223+
use mithril_common::{assert_dir_eq, temp_dir_create};
224224

225225
use crate::file_downloader::FileDownloader;
226226

@@ -261,9 +261,6 @@ mod tests {
261261
)
262262
.unwrap();
263263

264-
assert!(target_dir.join("file1.txt").exists());
265-
assert!(target_dir.join("file2.txt").exists());
266-
assert!(target_dir.join("not_in_manifest.txt").exists());
267264
const EMPTY_SHA256_HASH: &str =
268265
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
269266
assert_eq!(
@@ -281,5 +278,16 @@ mod tests {
281278
.expect("Manifest should be signed"),
282279
)
283280
.expect("Signed manifest should have a valid signature");
281+
282+
assert_dir_eq!(
283+
&target_dir,
284+
format!(
285+
"* {}
286+
* file1.txt
287+
* file2.txt
288+
* not_in_manifest.txt",
289+
AncillaryFilesManifest::ANCILLARY_MANIFEST_FILE_NAME
290+
)
291+
);
284292
}
285293
}

mithril-client/src/snapshot_client.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ mod tests {
427427

428428
use super::*;
429429

430-
use mithril_common::temp_dir_create;
430+
use mithril_common::{assert_dir_eq, temp_dir_create};
431431

432432
fn dummy_download_event() -> DownloadEvent {
433433
DownloadEvent::Full {
@@ -771,9 +771,7 @@ mod tests {
771771
.await
772772
.expect("Should succeed when ancillary verification is successful");
773773

774-
assert!(test_dir.join("dummy_ledger").exists());
775-
assert!(!test_dir.join("not_in_ancillary").exists());
776-
assert!(!SnapshotClient::ancillary_subdir(&test_dir, "test-download-id").exists());
774+
assert_dir_eq!(&test_dir, "* dummy_ledger");
777775
}
778776
}
779777
}

mithril-client/src/utils/ancillary_verifier.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl ValidatedAncillaryManifest {
118118
mod tests {
119119
use std::io::Write;
120120

121-
use mithril_common::temp_dir_create;
121+
use mithril_common::{assert_dir_eq, temp_dir_create};
122122

123123
use super::*;
124124

@@ -325,13 +325,17 @@ mod tests {
325325
.await
326326
.unwrap();
327327

328-
assert!(!source_dir.join(&file_in_root_dir).exists());
329-
assert!(!source_dir.join(&file_in_subdir).exists());
330-
assert!(source_dir.join(&not_moved_path).exists());
331-
332-
assert!(target_dir.join(&file_in_root_dir).exists());
333-
assert!(target_dir.join(&file_in_subdir).exists());
334-
assert!(!target_dir.join(&not_moved_path).exists());
328+
assert_dir_eq!(
329+
&source_dir,
330+
"* subdir/
331+
* not_moved.txt"
332+
);
333+
assert_dir_eq!(
334+
&target_dir,
335+
"* subdir/
336+
** file2.txt
337+
* file1.txt"
338+
);
335339
}
336340

337341
#[tokio::test]

0 commit comments

Comments
 (0)