From 6b06e874119ceca1a9dac1b94dcfe6e06aacd7b9 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 26 Jun 2024 07:56:10 +0100 Subject: refactor: remove fresh test config as config is now stored using git config and cache is conditionally stored in local ./git folder under test conditions --- test_utils/src/lib.rs | 53 --------------------------------------------------- 1 file changed, 53 deletions(-) (limited to 'test_utils') diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index ade60fc..64e3fff 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs @@ -2,7 +2,6 @@ use std::{ffi::OsStr, path::PathBuf, str::FromStr}; use anyhow::{bail, ensure, Context, Result}; use dialoguer::theme::{ColorfulTheme, Theme}; -use directories::ProjectDirs; use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; use nostr_sdk::{serde_json, NostrSigner, TagStandard}; use once_cell::sync::Lazy; @@ -934,55 +933,3 @@ where }, ) } - -/// backup and remove application config and data -pub fn before() -> Result<()> { - backup_existing_config() -} - -/// restore backuped application config and data -pub fn after() -> Result<()> { - restore_config_backup() -} - -/// run func between before and after scripts which backup, reset and restore -/// application config -/// -/// TODO: fix issue: if func panics, after() is not run. -pub fn with_fresh_config(func: F) -> Result<()> -where - F: Fn() -> Result<()>, -{ - before()?; - func()?; - after() -} - -fn backup_existing_config() -> Result<()> { - let config_path = get_dirs().config_dir().join("cache.sqlite"); - let backup_config_path = get_dirs().config_dir().join("cache-backup.sqlite"); - if !backup_config_path.exists() { - std::fs::rename(&config_path, backup_config_path)?; - } - if config_path.exists() { - std::fs::remove_file(&config_path)?; - } - Ok(()) -} - -fn restore_config_backup() -> Result<()> { - let config_path = get_dirs().config_dir().join("cache.sqlite"); - let backup_config_path = get_dirs().config_dir().join("cache-backup.sqlite"); - if config_path.exists() { - std::fs::remove_file(&config_path)?; - } - if backup_config_path.exists() { - std::fs::rename(backup_config_path, config_path)?; - } - Ok(()) -} - -fn get_dirs() -> ProjectDirs { - ProjectDirs::from("", "CodeCollaboration", "ngit") - .expect("rust directories crate should return ProjectDirs") -} -- cgit v1.2.3