mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
About to change clap usage to builder (instead of derive)
This commit is contained in:
@@ -1,7 +1,19 @@
|
|||||||
use crate::model;
|
use chrono::Local;
|
||||||
|
|
||||||
|
use crate::model::{self, notifications::Notification};
|
||||||
|
|
||||||
pub fn list() -> Vec<model::notifications::Notification> {
|
pub fn list() -> Vec<model::notifications::Notification> {
|
||||||
unimplemented!("Not ready yet");
|
let mut result = Vec::new();
|
||||||
|
result.push(Notification {
|
||||||
|
id: 1,
|
||||||
|
created_on: Local::now().to_utc(),
|
||||||
|
is_new: true,
|
||||||
|
notification_type: model::notifications::NotificationType::NewDeviceFound,
|
||||||
|
title: "title".to_string(),
|
||||||
|
body: "body".to_string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use clap::Parser;
|
|||||||
use config::{Config, ConfigError, File};
|
use config::{Config, ConfigError, File};
|
||||||
use duration_string::DurationString;
|
use duration_string::DurationString;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use log::{error, info};
|
use log::{debug, error, info};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
@@ -67,9 +67,14 @@ const DEFAULT_CONFIG_FILE_PATH: &str = "./oott.toml";
|
|||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
pub fn new() -> Result<Self, ConfigError> {
|
pub fn new() -> Result<Self, ConfigError> {
|
||||||
let args = Args::parse();
|
debug!("Starting configuration");
|
||||||
|
|
||||||
let config_path = args.config.unwrap_or(DEFAULT_CONFIG_FILE_PATH.to_string());
|
let args_result = Args::try_parse();
|
||||||
|
|
||||||
|
let config_path = match args_result {
|
||||||
|
Ok(value) => value.config.unwrap_or(DEFAULT_CONFIG_FILE_PATH.to_string()),
|
||||||
|
Err(_) => DEFAULT_CONFIG_FILE_PATH.to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
info!("Reading configuration from {}", config_path);
|
info!("Reading configuration from {}", config_path);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::db;
|
use crate::db;
|
||||||
use include_dir::{Dir, include_dir};
|
use include_dir::{Dir, include_dir};
|
||||||
|
use log::{debug, info};
|
||||||
use rusqlite_migration::Migrations;
|
use rusqlite_migration::Migrations;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
@@ -13,13 +14,17 @@ static TEST_MIGRATIONS: LazyLock<Migrations<'static>> =
|
|||||||
static INITIALISED: Mutex<bool> = Mutex::const_new(false);
|
static INITIALISED: Mutex<bool> = Mutex::const_new(false);
|
||||||
|
|
||||||
pub async fn setup_database() {
|
pub async fn setup_database() {
|
||||||
|
debug!("About to setup database for testing.");
|
||||||
let mut initialised = INITIALISED.lock().await;
|
let mut initialised = INITIALISED.lock().await;
|
||||||
if *initialised {
|
if *initialised {
|
||||||
|
debug!("Database was already initialised, nothing to do.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
db::init_db().await.unwrap();
|
db::init_db().await.unwrap();
|
||||||
|
info!("Initializing database for testing.");
|
||||||
let mut conn = db::get_db_connection();
|
let mut conn = db::get_db_connection();
|
||||||
|
debug!("Running migrations for testing.");
|
||||||
TEST_MIGRATIONS.to_latest(&mut conn).unwrap();
|
TEST_MIGRATIONS.to_latest(&mut conn).unwrap();
|
||||||
|
debug!("Testing migrations run on database.");
|
||||||
*initialised = true;
|
*initialised = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user