Skip to content

Commit

Permalink
refactor(test): utils module to use clean_temp function for cleaning …
Browse files Browse the repository at this point in the history
…temporary directories
  • Loading branch information
georgegiosue committed Apr 16, 2024
1 parent b7767ba commit efc2aaa
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/build/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mod tests {

use super::*;

use crate::utils::replicate_android_project_to_temp;
use crate::utils::{clean_temp, replicate_android_project_to_temp};

#[test]
fn test_build_runtime() {
Expand All @@ -71,7 +71,7 @@ mod tests {
AndroidBuildRuntime::KTS
);

let _ = std::fs::remove_dir_all(groovy_project_path);
let _ = std::fs::remove_dir_all(kotlin_project_path);
clean_temp(groovy_project_path);
clean_temp(kotlin_project_path);
}
}
4 changes: 2 additions & 2 deletions src/github/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mod test {
use super::*;
use crate::{
build::runtime::AndroidBuildRuntime, github::create_github_dotfiles_dir,
utils::replicate_android_project_to_temp,
utils::{clean_temp, replicate_android_project_to_temp},
};

#[test]
Expand All @@ -72,6 +72,6 @@ mod test {
assert_eq!(path.exists(), true);
}

let _ = std::fs::remove_dir_all(kotlin_project_path);
clean_temp(kotlin_project_path);
}
}
6 changes: 3 additions & 3 deletions src/github/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn create_github_dotfiles_dir(project_path: &Path) {
#[cfg(test)]
mod test {

use crate::{build::runtime::AndroidBuildRuntime, utils::replicate_android_project_to_temp};
use crate::{build::runtime::AndroidBuildRuntime, utils::{clean_temp, replicate_android_project_to_temp}};

use super::*;

Expand All @@ -32,7 +32,7 @@ mod test {

assert_eq!(exists_github_dotfiles_dir(&kotlin_project_path), false);

let _ = std::fs::remove_dir_all(kotlin_project_path);
clean_temp(kotlin_project_path);
}

#[test]
Expand All @@ -44,6 +44,6 @@ mod test {

assert_eq!(kotlin_project_path.join(".github").exists(), true);

let _ = fs::remove_dir_all(kotlin_project_path);
clean_temp(kotlin_project_path);
}
}
7 changes: 4 additions & 3 deletions src/source/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ pub mod build_src {
mod test {

use crate::{
build::runtime::AndroidBuildRuntime, utils::replicate_android_project_to_temp,
build::runtime::AndroidBuildRuntime,
utils::{clean_temp, replicate_android_project_to_temp},
};

use super::*;
Expand All @@ -119,7 +120,7 @@ pub mod build_src {

assert_eq!(build_src_kotlin_path.exists(), true);

let _ = std::fs::remove_dir_all(kotlin_project_path);
clean_temp(kotlin_project_path);
}

#[test]
Expand All @@ -146,7 +147,7 @@ pub mod build_src {

assert_eq!(kotlin_files_present, true);

let _ = std::fs::remove_dir_all(kotlin_project_path);
clean_temp(kotlin_project_path);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ pub fn replicate_android_project_to_temp(build_runtime: AndroidBuildRuntime) ->

android_project_temp_dir
}

pub fn clean_temp(android_project_path: PathBuf) {
fs::remove_dir_all(android_project_path.parent().unwrap())
.expect("Error clean project dir from temp directory");
}

0 comments on commit efc2aaa

Please sign in to comment.