add migration tests

This commit is contained in:
Tsiry Sandratraina
2022-12-01 21:16:13 +03:00
parent c5710452db
commit 424e9e5306
2 changed files with 38 additions and 0 deletions

View File

@@ -1,3 +1,6 @@
#[cfg(test)]
mod tests;
use std::{fs::File, path::Path};
use music_player_settings::{read_settings, Settings};

View File

@@ -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);
}