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,
url TEXT NOT NULL,
description TEXT,
active Boolean NOT NULL DEFAULT 1,
active Boolean DEFAULT 1 NOT NULL,
glyph TEXT,
application_category_id INTEGER,
alive Boolean NOT NULL DEFAULT 1,
enable_healthcheck Boolean NOT NULL DEFAULT 0
enable_healthcheck Boolean DEFAULT 0 NOT NULL
);
CREATE TABLE application_category (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,

View File

@ -89,11 +89,6 @@ pub mod test_prelude {
pub use crate::error::Result;
pub use actix_web::dev::ServiceResponse;
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::{
entity::prelude::*, entity::*, tests_cfg::*, DatabaseBackend, MockDatabase, MockExecResult,
Transaction,
@ -102,22 +97,11 @@ pub mod test_prelude {
/// 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>> {
let db = Database::connect("sqlite::memory:").await?;
let schema = Schema::new(DbBackend::Sqlite);
let pool = sqlx::SqlitePool::connect(":memory:").await?;
sqlx::migrate!("./migrations").run(&pool).await?;
tracing::info!("Database migrated");
let stmt: TableCreateStatement = schema.create_table_from_entity(application::Entity);
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?;
let db = sea_orm::SqlxSqliteConnector::from_sqlx_sqlite_pool(pool);
auth::generate_secret(&db).await?;