Remove database-json #267

Merged
wojtek merged 7 commits from 248---replace-json-file-as-a-database-with-sqlite into main 2025-01-12 12:18:25 +01:00
Showing only changes of commit 6238d533b1 - Show all commits

View File

@ -6,6 +6,8 @@ mod library;
mod testlib; mod testlib;
use std::{fs, path::PathBuf};
use musichoard::{ use musichoard::{
external::{ external::{
database::sql::{backend::SqlDatabaseSqliteBackend, SqlDatabase}, database::sql::{backend::SqlDatabaseSqliteBackend, SqlDatabase},
@ -13,9 +15,16 @@ use musichoard::{
}, },
IMusicHoardBase, IMusicHoardDatabase, IMusicHoardLibrary, MusicHoard, IMusicHoardBase, IMusicHoardDatabase, IMusicHoardLibrary, MusicHoard,
}; };
use tempfile::NamedTempFile;
use crate::testlib::COLLECTION; use crate::testlib::COLLECTION;
fn copy_file_into_temp<P: Into<PathBuf>>(path: P) -> NamedTempFile {
let temp = NamedTempFile::new().unwrap();
fs::copy(path.into(), temp.path()).unwrap();
temp
}
#[test] #[test]
fn merge_library_then_database() { fn merge_library_then_database() {
// Acquired the lock on the beets config file. We need to own the underlying object so later we // Acquired the lock on the beets config file. We need to own the underlying object so later we
@ -28,7 +37,8 @@ fn merge_library_then_database() {
.config(Some(&*library::beets::BEETS_TEST_CONFIG_PATH)); .config(Some(&*library::beets::BEETS_TEST_CONFIG_PATH));
let library = BeetsLibrary::new(executor); let library = BeetsLibrary::new(executor);
let backend = SqlDatabaseSqliteBackend::new(&*database::sql::DATABASE_TEST_FILE).unwrap(); let file = copy_file_into_temp(&*database::sql::DATABASE_TEST_FILE);
let backend = SqlDatabaseSqliteBackend::new(file.path()).unwrap();
let database = SqlDatabase::new(backend).unwrap(); let database = SqlDatabase::new(backend).unwrap();
let mut music_hoard = MusicHoard::new(database, library); let mut music_hoard = MusicHoard::new(database, library);
@ -51,7 +61,8 @@ fn merge_database_then_library() {
.config(Some(&*library::beets::BEETS_TEST_CONFIG_PATH)); .config(Some(&*library::beets::BEETS_TEST_CONFIG_PATH));
let library = BeetsLibrary::new(executor); let library = BeetsLibrary::new(executor);
let backend = SqlDatabaseSqliteBackend::new(&*database::sql::DATABASE_TEST_FILE).unwrap(); let file = copy_file_into_temp(&*database::sql::DATABASE_TEST_FILE);
let backend = SqlDatabaseSqliteBackend::new(file.path()).unwrap();
let database = SqlDatabase::new(backend).unwrap(); let database = SqlDatabase::new(backend).unwrap();
let mut music_hoard = MusicHoard::new(database, library); let mut music_hoard = MusicHoard::new(database, library);