Skip to content

Commit

Permalink
Load config for test
Browse files Browse the repository at this point in the history
  • Loading branch information
dcadenas committed Jul 25, 2024
1 parent 237e0aa commit 4a12292
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/config/reportinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
10 changes: 10 additions & 0 deletions src/domain_objects/report_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,23 @@ 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;

fn setup_test_environment(
event_target: bool,
) -> (ReportRequest, ReportTarget, PublicKey, Option<String>) {
let config = Config::new("config").unwrap();
let app_config = config.get::<ReportinatorConfig>().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();

Expand Down
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<ReportinatorConfig>()?;
// 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!(
Expand Down

0 comments on commit 4a12292

Please sign in to comment.