summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/config.rs b/src/config.rs
index 186ef82..49bd995 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -57,7 +57,8 @@ impl Config {
let _ = std::fs::create_dir_all(parent);
}
- format!("sqlite://{}", db_path.display())
+ // Use the correct SQLx format: sqlite:path
+ format!("sqlite:{}", db_path.display())
}
#[allow(dead_code)]
@@ -79,9 +80,11 @@ impl Config {
mod tests {
use super::*;
use std::env;
- use std::sync::Once;
+ use std::sync::OnceLock;
+ use std::sync::{Mutex, Once};
static INIT: Once = Once::new();
+ static TEST_MUTEX: OnceLock<Mutex<()>> = OnceLock::new();
fn setup() {
INIT.call_once(|| {
@@ -95,6 +98,9 @@ mod tests {
}
});
+ // Get the test mutex to ensure sequential execution
+ let _guard = TEST_MUTEX.get_or_init(|| Mutex::new(())).lock().unwrap();
+
// Clear environment variables before each test
unsafe {
env::remove_var("DATABASE_URL");
@@ -110,7 +116,7 @@ mod tests {
setup();
let home = env::var("HOME").unwrap_or_else(|_| "/tmp".to_string());
- let expected_path = format!("sqlite://{home}/.local/share/silmataivas/silmataivas.db");
+ let expected_path = format!("sqlite:{home}/.local/share/silmataivas/silmataivas.db");
let config = Config::from_env();
assert_eq!(config.database_url, expected_path);
@@ -124,10 +130,15 @@ mod tests {
env::set_var("XDG_DATA_HOME", "/custom/data/path");
}
- let expected_path = "sqlite:///custom/data/path/silmataivas/silmataivas.db";
+ let expected_path = "sqlite:/custom/data/path/silmataivas/silmataivas.db";
let config = Config::from_env();
assert_eq!(config.database_url, expected_path);
+
+ // Clean up after this test
+ unsafe {
+ env::remove_var("XDG_DATA_HOME");
+ }
}
#[test]
@@ -135,11 +146,16 @@ mod tests {
setup();
unsafe {
- env::set_var("DATABASE_URL", "sqlite:///explicit/path.db");
+ env::set_var("DATABASE_URL", "sqlite:/explicit/path.db");
}
let config = Config::from_env();
- assert_eq!(config.database_url, "sqlite:///explicit/path.db");
+ assert_eq!(config.database_url, "sqlite:/explicit/path.db");
+
+ // Clean up after this test
+ unsafe {
+ env::remove_var("DATABASE_URL");
+ }
}
#[test]
@@ -156,5 +172,12 @@ mod tests {
assert_eq!(config.server_port, 8080);
assert_eq!(config.server_host, "127.0.0.1");
assert_eq!(config.log_level, "debug");
+
+ // Clean up after this test
+ unsafe {
+ env::remove_var("PORT");
+ env::remove_var("HOST");
+ env::remove_var("LOG_LEVEL");
+ }
}
}