Wojciech Kozlowski
473825b396
Some reorganisation Remove unnecessary trait Basic example working Handle errors Handle dates Expand scope of MusicBrainz reference Type the musicbrainz refs Explicit constructors for str Handle MBIDs for albums Add search to the API Handle primary and secondary types Simplify AlbumDate Passing unit tests Tests pass Prevent compiler/clippy warnings Finish unit tests Clippy Remove old deserialize version
64 lines
2.2 KiB
Rust
64 lines
2.2 KiB
Rust
#![cfg(feature = "database-json")]
|
|
#![cfg(feature = "library-beets")]
|
|
|
|
mod database;
|
|
mod library;
|
|
|
|
mod testlib;
|
|
|
|
use musichoard::{
|
|
external::{
|
|
database::json::{backend::JsonDatabaseFileBackend, JsonDatabase},
|
|
library::beets::{executor::BeetsLibraryProcessExecutor, BeetsLibrary},
|
|
},
|
|
IMusicHoardBase, IMusicHoardDatabase, IMusicHoardLibrary, MusicHoard,
|
|
};
|
|
|
|
use crate::testlib::COLLECTION;
|
|
|
|
#[test]
|
|
fn merge_library_then_database() {
|
|
// Acquired the lock on the beets config file. We need to own the underlying object so later we
|
|
// create a new one. This is okay as the purpose of the lock is to prevent other tests to access
|
|
// the same Beets library at the same time.
|
|
let _arc = library::beets::BEETS_TEST_CONFIG.clone();
|
|
let _ = &mut _arc.lock().unwrap();
|
|
|
|
let executor = BeetsLibraryProcessExecutor::default()
|
|
.config(Some(&*library::beets::BEETS_TEST_CONFIG_PATH));
|
|
let library = BeetsLibrary::new(executor);
|
|
|
|
let backend = JsonDatabaseFileBackend::new(&*database::json::DATABASE_TEST_FILE);
|
|
let database = JsonDatabase::new(backend);
|
|
|
|
let mut music_hoard = MusicHoard::new(database, library).unwrap();
|
|
|
|
music_hoard.rescan_library().unwrap();
|
|
music_hoard.reload_database().unwrap();
|
|
|
|
assert_eq!(music_hoard.get_collection(), &*COLLECTION);
|
|
}
|
|
|
|
#[test]
|
|
fn merge_database_then_library() {
|
|
// Acquired the lock on the beets config file. We need to own the underlying object so later we
|
|
// create a new one. This is okay as the purpose of the lock is to prevent other tests to access
|
|
// the same Beets library at the same time.
|
|
let _arc = library::beets::BEETS_TEST_CONFIG.clone();
|
|
let _ = &mut _arc.lock().unwrap();
|
|
|
|
let executor = BeetsLibraryProcessExecutor::default()
|
|
.config(Some(&*library::beets::BEETS_TEST_CONFIG_PATH));
|
|
let library = BeetsLibrary::new(executor);
|
|
|
|
let backend = JsonDatabaseFileBackend::new(&*database::json::DATABASE_TEST_FILE);
|
|
let database = JsonDatabase::new(backend);
|
|
|
|
let mut music_hoard = MusicHoard::new(database, library).unwrap();
|
|
|
|
music_hoard.reload_database().unwrap();
|
|
music_hoard.rescan_library().unwrap();
|
|
|
|
assert_eq!(music_hoard.get_collection(), &*COLLECTION);
|
|
}
|