mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 21:47:02 +00:00
fix: local tests with overrides were missing prerequisites
This commit is contained in:
@@ -114,7 +114,8 @@ If you'd like to change anything, create a `Revolt.overrides.toml` file and spec
|
|||||||
> And corresponding Revolt configuration:
|
> And corresponding Revolt configuration:
|
||||||
>
|
>
|
||||||
> ```toml
|
> ```toml
|
||||||
> # Revolt.overrides.toml
|
> # Revolt.overrides.toml
|
||||||
|
> # and Revolt.test-overrides.toml
|
||||||
> [database]
|
> [database]
|
||||||
> mongodb = "mongodb://127.0.0.1:14017"
|
> mongodb = "mongodb://127.0.0.1:14017"
|
||||||
> redis = "redis://127.0.0.1:14079/"
|
> redis = "redis://127.0.0.1:14079/"
|
||||||
|
|||||||
@@ -60,6 +60,9 @@ static CONFIG_SEARCH_PATHS: [&str; 3] = [
|
|||||||
"/Revolt.toml",
|
"/Revolt.toml",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/// Path to search for test overrides
|
||||||
|
static TEST_OVERRIDE_PATH: &str = "Revolt.test-overrides.toml";
|
||||||
|
|
||||||
/// Configuration builder
|
/// Configuration builder
|
||||||
static CONFIG_BUILDER: Lazy<RwLock<Config>> = Lazy::new(|| {
|
static CONFIG_BUILDER: Lazy<RwLock<Config>> = Lazy::new(|| {
|
||||||
RwLock::new({
|
RwLock::new({
|
||||||
@@ -73,6 +76,20 @@ static CONFIG_BUILDER: Lazy<RwLock<Config>> = Lazy::new(|| {
|
|||||||
include_str!("../Revolt.test.toml"),
|
include_str!("../Revolt.test.toml"),
|
||||||
FileFormat::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 {
|
for path in CONFIG_SEARCH_PATHS {
|
||||||
@@ -388,6 +405,11 @@ pub async fn read() -> Config {
|
|||||||
pub async fn config() -> Settings {
|
pub async fn config() -> Settings {
|
||||||
let mut config = read().await.try_deserialize::<Settings>().unwrap();
|
let mut config = read().await.try_deserialize::<Settings>().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
|
// auto-detect production nodes
|
||||||
if config.hosts.api.contains("https") && config.hosts.api.contains("revolt.chat") {
|
if config.hosts.api.contains("https") && config.hosts.api.contains("revolt.chat") {
|
||||||
config.production = true;
|
config.production = true;
|
||||||
@@ -406,12 +428,6 @@ pub async fn setup_logging(release: &'static str, dsn: String) -> Option<sentry:
|
|||||||
std::env::set_var("ROCKET_ADDRESS", "0.0.0.0");
|
std::env::set_var("ROCKET_ADDRESS", "0.0.0.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
if std::env::var("REDIS_URL").is_err() {
|
|
||||||
// Configure redis-kiss library
|
|
||||||
let config = config().await;
|
|
||||||
std::env::set_var("REDIS_URI", config.database.redis);
|
|
||||||
}
|
|
||||||
|
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
log::info!("Starting {release}");
|
log::info!("Starting {release}");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user