Trying to setup tests

This commit is contained in:
rzuasti
2026-02-17 19:34:26 -05:00
parent 08465fb847
commit bc6a613a23
5 changed files with 26 additions and 8 deletions
+1
View File
@@ -1,4 +1,5 @@
pub mod devices;
pub mod notifications;
use include_dir::{Dir, include_dir};
use lazy_static::lazy_static;
+18
View File
@@ -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);
}
}
+3
View File
@@ -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;