diff --git a/src/config.rs b/src/config.rs index 75ff9b4..e5708b7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -134,7 +134,8 @@ where Ok(config) } -fn reset(db: &T) -> Result<()> +#[cfg(test)] +pub fn reset(db: &T) -> Result<()> where T: ConnectionSource, { @@ -150,14 +151,6 @@ where Ok(()) } -pub fn overwrite(db: &T, new_config: &Config) -> Result<()> -where - T: ConnectionSource, -{ - reset(db)?; - amend(db, new_config) -} - pub fn amend(db: &T, new_config: &Config) -> Result<()> where T: ConnectionSource, diff --git a/src/db/mod.rs b/src/db/mod.rs index e5e072c..045b724 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -4,8 +4,7 @@ use diesel::sqlite::SqliteConnection; use diesel_migrations; use error_chain::bail; use log::info; -use std::fs; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::sync::{Arc, Mutex, MutexGuard}; use crate::errors::*; @@ -86,20 +85,22 @@ impl ConnectionSource for DB { } } +#[cfg(test)] pub fn _get_test_db(name: &str) -> DB { use crate::config; let config_path = Path::new("test/config.toml"); let config = config::parse_toml_file(&config_path).unwrap(); - let mut db_path = PathBuf::new(); + let mut db_path = std::path::PathBuf::new(); db_path.push("test"); db_path.push(name); if db_path.exists() { - fs::remove_file(&db_path).unwrap(); + std::fs::remove_file(&db_path).unwrap(); } let db = DB::new(&db_path).unwrap(); - config::overwrite(&db, &config).unwrap(); + config::reset(&db).unwrap(); + config::amend(&db, &config).unwrap(); db } diff --git a/src/main.rs b/src/main.rs index 15fe16b..c3232b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -192,7 +192,8 @@ fn run() -> Result<()> { let config_file_path = config_file_name.map(|p| Path::new(p.as_str()).to_path_buf()); if let Some(path) = config_file_path { let config = config::parse_toml_file(&path)?; - config::overwrite(db.deref(), &config)?; + info!("Applying configuration"); + config::amend(db.deref(), &config)?; } let config = config::read(db.deref())?; let auth_secret = config::get_auth_secret(db.deref())?;