mirror of
https://github.com/tsirysndr/music-player.git
synced 2026-01-10 13:47:59 -05:00
add migration tests
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use std::{fs::File, path::Path};
|
||||
|
||||
use music_player_settings::{read_settings, Settings};
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
use std::{env, fs::File, path::Path};
|
||||
|
||||
use sea_orm_migration::{
|
||||
prelude::*,
|
||||
sea_orm::{ConnectionTrait, DatabaseBackend, QueryResult, Statement},
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_cli() {
|
||||
env::set_var("DATABASE_URL", "sqlite:///tmp/test.db");
|
||||
let database_path = std::env::var("DATABASE_URL")
|
||||
.unwrap()
|
||||
.replace("sqlite://", "");
|
||||
if !Path::new(&database_path).exists() {
|
||||
File::create(database_path).expect("Failed to create database file");
|
||||
}
|
||||
|
||||
cli::run_cli(super::Migrator).await;
|
||||
|
||||
let db = sea_orm::Database::connect("sqlite:///tmp/test.db")
|
||||
.await
|
||||
.expect("Could not connect to database");
|
||||
|
||||
let result: Vec<QueryResult> = db
|
||||
.query_all(Statement::from_string(
|
||||
DatabaseBackend::Sqlite,
|
||||
"SELECT name FROM sqlite_master
|
||||
WHERE type='table';"
|
||||
.to_owned(),
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result.len(), 9);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user