diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-06-26 07:56:10 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-06-26 07:56:10 +0100 |
| commit | 6b06e874119ceca1a9dac1b94dcfe6e06aacd7b9 (patch) | |
| tree | 54a7a7bdeda29fd792f1335c556d6639cd693c64 /test_utils | |
| parent | b63bfc9a34657c5767c507deb7c059e24dd22779 (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')
| -rw-r--r-- | test_utils/src/lib.rs | 53 |
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 | ||
| 3 | use anyhow::{bail, ensure, Context, Result}; | 3 | use anyhow::{bail, ensure, Context, Result}; |
| 4 | use dialoguer::theme::{ColorfulTheme, Theme}; | 4 | use dialoguer::theme::{ColorfulTheme, Theme}; |
| 5 | use directories::ProjectDirs; | ||
| 6 | use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; | 5 | use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; |
| 7 | use nostr_sdk::{serde_json, NostrSigner, TagStandard}; | 6 | use nostr_sdk::{serde_json, NostrSigner, TagStandard}; |
| 8 | use once_cell::sync::Lazy; | 7 | use once_cell::sync::Lazy; |
| @@ -934,55 +933,3 @@ where | |||
| 934 | }, | 933 | }, |
| 935 | ) | 934 | ) |
| 936 | } | 935 | } |
| 937 | |||
| 938 | /// backup and remove application config and data | ||
| 939 | pub fn before() -> Result<()> { | ||
| 940 | backup_existing_config() | ||
| 941 | } | ||
| 942 | |||
| 943 | /// restore backuped application config and data | ||
| 944 | pub 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. | ||
| 952 | pub fn with_fresh_config<F>(func: F) -> Result<()> | ||
| 953 | where | ||
| 954 | F: Fn() -> Result<()>, | ||
| 955 | { | ||
| 956 | before()?; | ||
| 957 | func()?; | ||
| 958 | after() | ||
| 959 | } | ||
| 960 | |||
| 961 | fn 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 | |||
| 973 | fn 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 | |||
| 985 | fn get_dirs() -> ProjectDirs { | ||
| 986 | ProjectDirs::from("", "CodeCollaboration", "ngit") | ||
| 987 | .expect("rust directories crate should return ProjectDirs") | ||
| 988 | } | ||