Tests now use migrations

This commit is contained in:
Joe Bellus 2022-02-12 02:13:34 -05:00
parent 16db73c4fc
commit 6da7782310
2 changed files with 6 additions and 23 deletions

View File

@ -4,11 +4,10 @@ CREATE TABLE application (
app_name TEXT NOT NULL, app_name TEXT NOT NULL,
url TEXT NOT NULL, url TEXT NOT NULL,
description TEXT, description TEXT,
active Boolean NOT NULL DEFAULT 1, active Boolean DEFAULT 1 NOT NULL,
glyph TEXT, glyph TEXT,
application_category_id INTEGER, application_category_id INTEGER,
alive Boolean NOT NULL DEFAULT 1, enable_healthcheck Boolean DEFAULT 0 NOT NULL
enable_healthcheck Boolean NOT NULL DEFAULT 0
); );
CREATE TABLE application_category ( CREATE TABLE application_category (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,

View File

@ -89,11 +89,6 @@ pub mod test_prelude {
pub use crate::error::Result; pub use crate::error::Result;
pub use actix_web::dev::ServiceResponse; pub use actix_web::dev::ServiceResponse;
pub use actix_web::{test, web, App}; pub use actix_web::{test, web, App};
use sea_orm::sea_query::TableCreateStatement;
use sea_orm::ConnectionTrait;
use sea_orm::Database;
use sea_orm::DbBackend;
use sea_orm::Schema;
pub use sea_orm::{ pub use sea_orm::{
entity::prelude::*, entity::*, tests_cfg::*, DatabaseBackend, MockDatabase, MockExecResult, entity::prelude::*, entity::*, tests_cfg::*, DatabaseBackend, MockDatabase, MockExecResult,
Transaction, Transaction,
@ -102,22 +97,11 @@ pub mod test_prelude {
/// Sets up a testing state with an in-memory database and creates the scheme. /// Sets up a testing state with an in-memory database and creates the scheme.
pub async fn setup_state() -> Result<actix_web::web::Data<AppState>> { pub async fn setup_state() -> Result<actix_web::web::Data<AppState>> {
let db = Database::connect("sqlite::memory:").await?; let pool = sqlx::SqlitePool::connect(":memory:").await?;
let schema = Schema::new(DbBackend::Sqlite); sqlx::migrate!("./migrations").run(&pool).await?;
tracing::info!("Database migrated");
let stmt: TableCreateStatement = schema.create_table_from_entity(application::Entity); let db = sea_orm::SqlxSqliteConnector::from_sqlx_sqlite_pool(pool);
db.execute(db.get_database_backend().build(&stmt)).await?;
let stmt: TableCreateStatement =
schema.create_table_from_entity(application_category::Entity);
db.execute(db.get_database_backend().build(&stmt)).await?;
let stmt: TableCreateStatement = schema.create_table_from_entity(bookmark::Entity);
db.execute(db.get_database_backend().build(&stmt)).await?;
let stmt: TableCreateStatement = schema.create_table_from_entity(bookmark_category::Entity);
db.execute(db.get_database_backend().build(&stmt)).await?;
let stmt: TableCreateStatement = schema.create_table_from_entity(setting::Entity);
db.execute(db.get_database_backend().build(&stmt)).await?;
auth::generate_secret(&db).await?; auth::generate_secret(&db).await?;