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
+25
View File
@@ -0,0 +1,25 @@
use crate::db;
use include_dir::{Dir, include_dir};
use rusqlite_migration::Migrations;
use std::sync::LazyLock;
use tokio::sync::Mutex;
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>> =
LazyLock::new(|| Migrations::from_directory(&TEST_MIGRATIONS_DIR).unwrap());
static INITIALISED: Mutex<bool> = Mutex::const_new(false);
pub async fn setup_database() {
let mut initialised = INITIALISED.lock().await;
if *initialised {
return;
}
db::init_db().await.unwrap();
let mut conn = db::get_db_connection();
TEST_MIGRATIONS.to_latest(&mut conn).unwrap();
*initialised = true;
}