Skip to content

Commit

Permalink
refactor: refactor temp directory management
Browse files Browse the repository at this point in the history
- update `user_test_data_path` to use `temp_dir_root_name` instead of `git_user`
- refactor `create_temp_dir` function to use `temp_dir_root_name` instead of hardcoding the root name
  • Loading branch information
falcucci committed Sep 18, 2024
1 parent defa652 commit f0b7e55
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ struct Assets;

lazy_static! {
static ref TEMP_DIR: PathBuf = temp_dir();
static ref GIT_USER: String = {
let repo = Repository::open_from_env().expect("Could not read git repository");
let config = repo.config().expect("Could not read config for repo");
config
.get_string("user.name")
.expect("Could not read user name")
};
static ref TEMP_DIR_ROOT_NAME: String = format!("vide_test_{}", std::process::id());
}

fn create_temp_dir() -> PathBuf {
std::env::temp_dir().join(TEMP_DIR_ROOT_NAME.as_str())
}

fn assert_no_regressions(width: u32, height: u32, scene: Scene) {
Expand All @@ -47,10 +45,10 @@ fn assert_no_regressions(width: u32, height: u32, scene: Scene) {
.last()
.unwrap()
.to_string();
let user_test_data_path = format!("./test_data/{}/", *GIT_USER);
let user_test_data_path = create_temp_dir();
create_dir_all(&user_test_data_path).unwrap();

let expected_path = format!("{}/{}.png", user_test_data_path, test_name);
let expected_path = format!("{}/{}.png", user_test_data_path.display(), test_name);
let expected = ImageReader::open(&expected_path).ok().map(|reader| {
reader
.decode()
Expand Down

0 comments on commit f0b7e55

Please sign in to comment.