diff --git a/README.md b/README.md index 1973ee20..3dd25cf5 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,8 @@ If you'd like to change anything, create a `Revolt.overrides.toml` file and spec > And corresponding Revolt configuration: > > ```toml -> # Revolt.overrides.toml +> # Revolt.overrides.toml +> # and Revolt.test-overrides.toml > [database] > mongodb = "mongodb://127.0.0.1:14017" > redis = "redis://127.0.0.1:14079/" diff --git a/crates/core/config/src/lib.rs b/crates/core/config/src/lib.rs index b4b3bed2..7c050499 100644 --- a/crates/core/config/src/lib.rs +++ b/crates/core/config/src/lib.rs @@ -60,6 +60,9 @@ static CONFIG_SEARCH_PATHS: [&str; 3] = [ "/Revolt.toml", ]; +/// Path to search for test overrides +static TEST_OVERRIDE_PATH: &str = "Revolt.test-overrides.toml"; + /// Configuration builder static CONFIG_BUILDER: Lazy> = Lazy::new(|| { RwLock::new({ @@ -73,6 +76,20 @@ static CONFIG_BUILDER: Lazy> = Lazy::new(|| { include_str!("../Revolt.test.toml"), FileFormat::Toml, )); + + // recursively search upwards for an overrides file (if there is one) + if let Ok(cwd) = std::env::current_dir() { + let mut path = Some(cwd.as_path()); + while let Some(current_path) = path { + let target_path = current_path.join(TEST_OVERRIDE_PATH); + if target_path.exists() { + builder = builder + .add_source(File::new(target_path.to_str().unwrap(), FileFormat::Toml)); + } + + path = current_path.parent(); + } + } } for path in CONFIG_SEARCH_PATHS { @@ -388,6 +405,11 @@ pub async fn read() -> Config { pub async fn config() -> Settings { let mut config = read().await.try_deserialize::().unwrap(); + // inject REDIS_URI for redis-kiss library + if std::env::var("REDIS_URL").is_err() { + std::env::set_var("REDIS_URI", config.database.redis.clone()); + } + // auto-detect production nodes if config.hosts.api.contains("https") && config.hosts.api.contains("revolt.chat") { config.production = true; @@ -406,12 +428,6 @@ pub async fn setup_logging(release: &'static str, dsn: String) -> Option