diff --git a/.gitignore b/.gitignore index 73fab07..47913b8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ # will have compiled files and executables debug/ target/ +config/settings.development.yml +config/settings.production.yml # These are backup files generated by rustfmt **/*.rs.bk diff --git a/src/config/reportinator.rs b/src/config/reportinator.rs index a575bfa..1665e62 100644 --- a/src/config/reportinator.rs +++ b/src/config/reportinator.rs @@ -52,6 +52,6 @@ pub fn config<'a>() -> &'a Config { CONFIG.get().unwrap() } -pub fn set_config(config: Config) { - CONFIG.set(config).expect("Failed to set config"); +pub fn set_config(config: Config) -> Result<(), Config> { + CONFIG.set(config) } diff --git a/src/domain_objects/report_request.rs b/src/domain_objects/report_request.rs index 1672755..0081a6c 100644 --- a/src/domain_objects/report_request.rs +++ b/src/domain_objects/report_request.rs @@ -131,6 +131,10 @@ impl Display for ReportRequest { #[cfg(test)] mod tests { use super::*; + use crate::config::{ + reportinator::{self, Config as ReportinatorConfig}, + Config, + }; use nostr_sdk::nips::nip56::Report; use serde_json::json; use std::str::FromStr; @@ -138,6 +142,12 @@ mod tests { fn setup_test_environment( event_target: bool, ) -> (ReportRequest, ReportTarget, PublicKey, Option) { + let config = Config::new("config").unwrap(); + let app_config = config.get::().unwrap(); + if let Err(_config) = reportinator::set_config(app_config) { + // We need the config for this test. Ignore the error if it was already set + } + let reported_secret = "a39b6f282044c4812c1729a783f32d974ed13072632f08201f52d083593d6e76"; let reported_keys = Keys::parse(reported_secret).unwrap(); diff --git a/src/main.rs b/src/main.rs index dccff24..483168b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,17 +18,16 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter}; #[tokio::main] async fn main() -> Result<()> { - let config = Config::new("config")?; - tracing_subscriber::registry() .with(fmt::layer()) .with(EnvFilter::from_default_env()) .init(); + let config = Config::new("config")?; let app_config = config.get::()?; // There are places that are non-trivial to pass app_config to, // so we will set a global here for the interim. - config::reportinator::set_config(app_config.clone()); + config::reportinator::set_config(app_config.clone()).expect("Failed to set config"); let reportinator_public_key = app_config.keys.public_key(); info!(