upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/test_utils/src
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-06-26 07:56:10 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-06-26 07:56:10 +0100
commit6b06e874119ceca1a9dac1b94dcfe6e06aacd7b9 (patch)
tree54a7a7bdeda29fd792f1335c556d6639cd693c64 /test_utils/src
parentb63bfc9a34657c5767c507deb7c059e24dd22779 (diff)
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
Diffstat (limited to 'test_utils/src')
-rw-r--r--test_utils/src/lib.rs53
1 files changed, 0 insertions, 53 deletions
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};
2 2
3use anyhow::{bail, ensure, Context, Result}; 3use anyhow::{bail, ensure, Context, Result};
4use dialoguer::theme::{ColorfulTheme, Theme}; 4use dialoguer::theme::{ColorfulTheme, Theme};
5use directories::ProjectDirs;
6use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; 5use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag};
7use nostr_sdk::{serde_json, NostrSigner, TagStandard}; 6use nostr_sdk::{serde_json, NostrSigner, TagStandard};
8use once_cell::sync::Lazy; 7use once_cell::sync::Lazy;
@@ -934,55 +933,3 @@ where
934 }, 933 },
935 ) 934 )
936} 935}
937
938/// backup and remove application config and data
939pub fn before() -> Result<()> {
940 backup_existing_config()
941}
942
943/// restore backuped application config and data
944pub fn after() -> Result<()> {
945 restore_config_backup()
946}
947
948/// run func between before and after scripts which backup, reset and restore
949/// application config
950///
951/// TODO: fix issue: if func panics, after() is not run.
952pub fn with_fresh_config<F>(func: F) -> Result<()>
953where
954 F: Fn() -> Result<()>,
955{
956 before()?;
957 func()?;
958 after()
959}
960
961fn backup_existing_config() -> Result<()> {
962 let config_path = get_dirs().config_dir().join("cache.sqlite");
963 let backup_config_path = get_dirs().config_dir().join("cache-backup.sqlite");
964 if !backup_config_path.exists() {
965 std::fs::rename(&config_path, backup_config_path)?;
966 }
967 if config_path.exists() {
968 std::fs::remove_file(&config_path)?;
969 }
970 Ok(())
971}
972
973fn restore_config_backup() -> Result<()> {
974 let config_path = get_dirs().config_dir().join("cache.sqlite");
975 let backup_config_path = get_dirs().config_dir().join("cache-backup.sqlite");
976 if config_path.exists() {
977 std::fs::remove_file(&config_path)?;
978 }
979 if backup_config_path.exists() {
980 std::fs::rename(backup_config_path, config_path)?;
981 }
982 Ok(())
983}
984
985fn get_dirs() -> ProjectDirs {
986 ProjectDirs::from("", "CodeCollaboration", "ngit")
987 .expect("rust directories crate should return ProjectDirs")
988}