Skip to content

Commit 0719e86

Browse files
committed
Address Review comments & enhance tests
Tests now only tests one of the two checker methods and remove a test that has lost meaning.
1 parent a602708 commit 0719e86

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

mithril-client-cli/src/utils/cardano_db_download_checker.rs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::ops::Not;
21
use std::{
32
fs,
3+
ops::Not,
44
path::{Path, PathBuf},
55
};
66

@@ -34,7 +34,7 @@ pub enum CardanoDbDownloadCheckerError {
3434
/// The directory where the files from cardano db are expanded is not empty.
3535
/// An error is raised to let the user handle what it wants to do with those
3636
/// files.
37-
#[error("Unpack directory '{0}' is not empty, please clean up it's content.")]
37+
#[error("Unpack directory '{0}' is not empty, please clean up its content.")]
3838
UnpackDirectoryNotEmpty(PathBuf),
3939

4040
/// Cannot write in the given directory.
@@ -45,7 +45,7 @@ pub enum CardanoDbDownloadCheckerError {
4545
impl CardanoDbDownloadChecker {
4646
/// Ensure that the given path exist, create it otherwise
4747
pub fn ensure_dir_exist(pathdir: &Path) -> MithrilResult<()> {
48-
if !pathdir.exists() {
48+
if pathdir.exists().not() {
4949
fs::create_dir_all(pathdir).map_err(|e| {
5050
CardanoDbDownloadCheckerError::UnpackDirectoryIsNotWritable(
5151
pathdir.to_owned(),
@@ -64,12 +64,12 @@ impl CardanoDbDownloadChecker {
6464
size: u64,
6565
compression_algorithm: CompressionAlgorithm,
6666
) -> MithrilResult<()> {
67-
Self::check_path_is_dir_and_writable(pathdir)?;
67+
Self::check_path_is_an_empty_dir(pathdir)?;
6868
Self::check_dir_writable(pathdir)?;
6969
Self::check_disk_space(pathdir, size, compression_algorithm)
7070
}
7171

72-
fn check_path_is_dir_and_writable(pathdir: &Path) -> MithrilResult<()> {
72+
fn check_path_is_an_empty_dir(pathdir: &Path) -> MithrilResult<()> {
7373
if pathdir.is_dir().not() {
7474
anyhow::bail!("Given path is not a directory: {}", pathdir.display());
7575
}
@@ -158,7 +158,6 @@ mod test {
158158
create_temporary_empty_directory("fail_if_pathdir_is_file").join("target_directory");
159159
fs::File::create(&pathdir).unwrap();
160160

161-
CardanoDbDownloadChecker::ensure_dir_exist(&pathdir).unwrap();
162161
CardanoDbDownloadChecker::check_prerequisites(
163162
&pathdir,
164163
12,
@@ -167,27 +166,12 @@ mod test {
167166
.expect_err("check_prerequisites should fail");
168167
}
169168

170-
#[test]
171-
fn return_ok_if_unpack_directory_does_not_exist() {
172-
let pathdir =
173-
create_temporary_empty_directory("directory_does_not_exist").join("target_directory");
174-
175-
CardanoDbDownloadChecker::ensure_dir_exist(&pathdir).unwrap();
176-
CardanoDbDownloadChecker::check_prerequisites(
177-
&pathdir,
178-
12,
179-
CompressionAlgorithm::default(),
180-
)
181-
.expect("check_prerequisites should not fail");
182-
}
183-
184169
#[test]
185170
fn return_ok_if_unpack_directory_exist_and_empty() {
186171
let pathdir =
187172
create_temporary_empty_directory("existing_directory").join("target_directory");
188173
fs::create_dir_all(&pathdir).unwrap();
189174

190-
CardanoDbDownloadChecker::ensure_dir_exist(&pathdir).unwrap();
191175
CardanoDbDownloadChecker::check_prerequisites(
192176
&pathdir,
193177
12,
@@ -202,7 +186,6 @@ mod test {
202186
fs::create_dir_all(&pathdir).unwrap();
203187
fs::File::create(pathdir.join("file.txt")).unwrap();
204188

205-
CardanoDbDownloadChecker::ensure_dir_exist(&pathdir).unwrap();
206189
let error = CardanoDbDownloadChecker::check_prerequisites(
207190
&pathdir,
208191
12,
@@ -224,9 +207,9 @@ mod test {
224207
fn return_error_if_not_enough_available_space() {
225208
let pathdir =
226209
create_temporary_empty_directory("enough_available_space").join("target_directory");
210+
fs::create_dir_all(&pathdir).unwrap();
227211
let archive_size = u64::MAX;
228212

229-
CardanoDbDownloadChecker::ensure_dir_exist(&pathdir).unwrap();
230213
let error = CardanoDbDownloadChecker::check_prerequisites(
231214
&pathdir,
232215
archive_size,

0 commit comments

Comments
 (0)