yt_sub/
test_helpers.rs

1use std::{
2    fs,
3    path::{Path, PathBuf},
4};
5
6use home::home_dir;
7use uuid::Uuid;
8
9use crate::user_settings_cli::UserSettingsCLI;
10use yt_sub_core::UserSettings;
11
12pub fn test_config_path() -> PathBuf {
13    let uuid = Uuid::new_v4();
14    home_dir()
15        .unwrap()
16        .join(format!(".config/yt-sub-rs-test/config-{}.toml", uuid))
17}
18
19pub fn init_test_settings() -> (UserSettings, Cleaner) {
20    let path = test_config_path();
21    let cl = Cleaner { path: path.clone() };
22    (UserSettings::init(Some(&path)).unwrap(), cl)
23}
24
25pub struct Cleaner {
26    pub path: PathBuf,
27}
28
29impl Drop for Cleaner {
30    fn drop(&mut self) {
31        if !Path::new(&self.path).exists() {
32            return;
33        }
34
35        fs::remove_file(&self.path).expect("Failed to remove file");
36    }
37}