mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Trying to setup tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
pub mod devices;
|
||||
pub mod notifications;
|
||||
|
||||
use include_dir::{Dir, include_dir};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
use crate::model;
|
||||
|
||||
pub fn list() -> Vec<model::notifications::Notification> {
|
||||
unimplemented!("Not ready yet");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::tests_common;
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_default() {
|
||||
tests_common::setup_database().await;
|
||||
let notifications = list();
|
||||
assert_eq!(notifications.len(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ mod scanner;
|
||||
mod settings;
|
||||
mod web_server;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests_common;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), String> {
|
||||
// Initialize logging
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
use crate::db;
|
||||
use include_dir::{Dir, include_dir};
|
||||
use log::{debug, error};
|
||||
use rusqlite::Connection;
|
||||
use rusqlite_migration::Migrations;
|
||||
use std::result::Result;
|
||||
use std::sync::LazyLock;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::settings;
|
||||
|
||||
static TEST_MIGRATIONS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/tests/database_migrations");
|
||||
static TEST_MIGRATIONS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/tests_database_migrations");
|
||||
|
||||
// Define migrations. These are applied atomically.
|
||||
static TEST_MIGRATIONS: LazyLock<Migrations<'static>> =
|
||||
@@ -21,8 +17,8 @@ pub async fn setup_database() {
|
||||
if *initialised {
|
||||
return;
|
||||
}
|
||||
|
||||
let conn = db::init_db().unwrap();
|
||||
db::init_db().await.unwrap();
|
||||
let mut conn = db::get_db_connection();
|
||||
TEST_MIGRATIONS.to_latest(&mut conn).unwrap();
|
||||
|
||||
*initialised = true;
|
||||
Reference in New Issue
Block a user