Split out builder tests
This commit is contained in:
parent
df7a15453d
commit
991f111ec5
@ -101,6 +101,13 @@ macro_rules! music_hoard_multi_url_dispatch {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for MusicHoard<NoLibrary, NoDatabase> {
|
||||||
|
/// Create a new [`MusicHoard`] without any library or database.
|
||||||
|
fn default() -> Self {
|
||||||
|
MusicHoard::new(NoLibrary, NoDatabase)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<LIB, DB> MusicHoard<LIB, DB> {
|
impl<LIB, DB> MusicHoard<LIB, DB> {
|
||||||
/// Create a new [`MusicHoard`] with the provided [`ILibrary`] and [`IDatabase`].
|
/// Create a new [`MusicHoard`] with the provided [`ILibrary`] and [`IDatabase`].
|
||||||
pub fn new(library: LIB, database: DB) -> Self {
|
pub fn new(library: LIB, database: DB) -> Self {
|
||||||
@ -335,7 +342,6 @@ mod tests {
|
|||||||
track::Format,
|
track::Format,
|
||||||
Merge,
|
Merge,
|
||||||
};
|
};
|
||||||
use crate::core::musichoard::musichoard_builder::MusicHoardBuilder;
|
|
||||||
use crate::core::musichoard::testmod::{FULL_COLLECTION, LIBRARY_COLLECTION};
|
use crate::core::musichoard::testmod::{FULL_COLLECTION, LIBRARY_COLLECTION};
|
||||||
use crate::database::{self, MockIDatabase};
|
use crate::database::{self, MockIDatabase};
|
||||||
use crate::library::{self, testmod::LIBRARY_ITEMS, MockILibrary};
|
use crate::library::{self, testmod::LIBRARY_ITEMS, MockILibrary};
|
||||||
@ -379,7 +385,7 @@ mod tests {
|
|||||||
fn artist_new_delete() {
|
fn artist_new_delete() {
|
||||||
let artist_id = ArtistId::new("an artist");
|
let artist_id = ArtistId::new("an artist");
|
||||||
let artist_id_2 = ArtistId::new("another artist");
|
let artist_id_2 = ArtistId::new("another artist");
|
||||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
let mut music_hoard = MusicHoard::default();
|
||||||
|
|
||||||
let mut expected: Vec<Artist> = vec![];
|
let mut expected: Vec<Artist> = vec![];
|
||||||
|
|
||||||
@ -400,7 +406,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn artist_sort_set_clear() {
|
fn artist_sort_set_clear() {
|
||||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
let mut music_hoard = MusicHoard::default();
|
||||||
|
|
||||||
let artist_1_id = ArtistId::new("the artist");
|
let artist_1_id = ArtistId::new("the artist");
|
||||||
let artist_1_sort = ArtistId::new("artist, the");
|
let artist_1_sort = ArtistId::new("artist, the");
|
||||||
@ -448,7 +454,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn collection_error() {
|
fn collection_error() {
|
||||||
let artist_id = ArtistId::new("an artist");
|
let artist_id = ArtistId::new("an artist");
|
||||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
let mut music_hoard = MusicHoard::default();
|
||||||
|
|
||||||
let actual_err = music_hoard
|
let actual_err = music_hoard
|
||||||
.add_musicbrainz_url(&artist_id, QOBUZ)
|
.add_musicbrainz_url(&artist_id, QOBUZ)
|
||||||
@ -463,7 +469,7 @@ mod tests {
|
|||||||
fn add_remove_musicbrainz_url() {
|
fn add_remove_musicbrainz_url() {
|
||||||
let artist_id = ArtistId::new("an artist");
|
let artist_id = ArtistId::new("an artist");
|
||||||
let artist_id_2 = ArtistId::new("another artist");
|
let artist_id_2 = ArtistId::new("another artist");
|
||||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
let mut music_hoard = MusicHoard::default();
|
||||||
|
|
||||||
music_hoard.add_artist(artist_id.clone());
|
music_hoard.add_artist(artist_id.clone());
|
||||||
|
|
||||||
@ -534,7 +540,7 @@ mod tests {
|
|||||||
fn set_clear_musicbrainz_url() {
|
fn set_clear_musicbrainz_url() {
|
||||||
let artist_id = ArtistId::new("an artist");
|
let artist_id = ArtistId::new("an artist");
|
||||||
let artist_id_2 = ArtistId::new("another artist");
|
let artist_id_2 = ArtistId::new("another artist");
|
||||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
let mut music_hoard = MusicHoard::default();
|
||||||
|
|
||||||
music_hoard.add_artist(artist_id.clone());
|
music_hoard.add_artist(artist_id.clone());
|
||||||
|
|
||||||
@ -589,7 +595,7 @@ mod tests {
|
|||||||
fn add_remove_musicbutler_urls() {
|
fn add_remove_musicbutler_urls() {
|
||||||
let artist_id = ArtistId::new("an artist");
|
let artist_id = ArtistId::new("an artist");
|
||||||
let artist_id_2 = ArtistId::new("another artist");
|
let artist_id_2 = ArtistId::new("another artist");
|
||||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
let mut music_hoard = MusicHoard::default();
|
||||||
|
|
||||||
music_hoard.add_artist(artist_id.clone());
|
music_hoard.add_artist(artist_id.clone());
|
||||||
|
|
||||||
@ -719,7 +725,7 @@ mod tests {
|
|||||||
fn set_clear_musicbutler_urls() {
|
fn set_clear_musicbutler_urls() {
|
||||||
let artist_id = ArtistId::new("an artist");
|
let artist_id = ArtistId::new("an artist");
|
||||||
let artist_id_2 = ArtistId::new("another artist");
|
let artist_id_2 = ArtistId::new("another artist");
|
||||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
let mut music_hoard = MusicHoard::default();
|
||||||
|
|
||||||
music_hoard.add_artist(artist_id.clone());
|
music_hoard.add_artist(artist_id.clone());
|
||||||
|
|
||||||
@ -782,7 +788,7 @@ mod tests {
|
|||||||
fn add_remove_bandcamp_urls() {
|
fn add_remove_bandcamp_urls() {
|
||||||
let artist_id = ArtistId::new("an artist");
|
let artist_id = ArtistId::new("an artist");
|
||||||
let artist_id_2 = ArtistId::new("another artist");
|
let artist_id_2 = ArtistId::new("another artist");
|
||||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
let mut music_hoard = MusicHoard::default();
|
||||||
|
|
||||||
music_hoard.add_artist(artist_id.clone());
|
music_hoard.add_artist(artist_id.clone());
|
||||||
|
|
||||||
@ -912,7 +918,7 @@ mod tests {
|
|||||||
fn set_clear_bandcamp_urls() {
|
fn set_clear_bandcamp_urls() {
|
||||||
let artist_id = ArtistId::new("an artist");
|
let artist_id = ArtistId::new("an artist");
|
||||||
let artist_id_2 = ArtistId::new("another artist");
|
let artist_id_2 = ArtistId::new("another artist");
|
||||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
let mut music_hoard = MusicHoard::default();
|
||||||
|
|
||||||
music_hoard.add_artist(artist_id.clone());
|
music_hoard.add_artist(artist_id.clone());
|
||||||
|
|
||||||
@ -975,7 +981,7 @@ mod tests {
|
|||||||
fn add_remove_qobuz_url() {
|
fn add_remove_qobuz_url() {
|
||||||
let artist_id = ArtistId::new("an artist");
|
let artist_id = ArtistId::new("an artist");
|
||||||
let artist_id_2 = ArtistId::new("another artist");
|
let artist_id_2 = ArtistId::new("another artist");
|
||||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
let mut music_hoard = MusicHoard::default();
|
||||||
|
|
||||||
music_hoard.add_artist(artist_id.clone());
|
music_hoard.add_artist(artist_id.clone());
|
||||||
|
|
||||||
@ -1026,7 +1032,7 @@ mod tests {
|
|||||||
fn set_clear_qobuz_url() {
|
fn set_clear_qobuz_url() {
|
||||||
let artist_id = ArtistId::new("an artist");
|
let artist_id = ArtistId::new("an artist");
|
||||||
let artist_id_2 = ArtistId::new("another artist");
|
let artist_id_2 = ArtistId::new("another artist");
|
||||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
let mut music_hoard = MusicHoard::default();
|
||||||
|
|
||||||
music_hoard.add_artist(artist_id.clone());
|
music_hoard.add_artist(artist_id.clone());
|
||||||
|
|
||||||
@ -1233,8 +1239,8 @@ mod tests {
|
|||||||
// sorted consistently. If the merge assumes they are sorted consistently this will lead to
|
// sorted consistently. If the merge assumes they are sorted consistently this will lead to
|
||||||
// the same artist appearing twice in the final list. This should not be the case.
|
// the same artist appearing twice in the final list. This should not be the case.
|
||||||
|
|
||||||
// We will mimic this situation by taking the last artist from FULL_COLLECTION and giving it a
|
// We will mimic this situation by taking the last artist from FULL_COLLECTION and giving it
|
||||||
// sorting name that would place it in the beginning.
|
// a sorting name that would place it in the beginning.
|
||||||
let left = FULL_COLLECTION.to_owned();
|
let left = FULL_COLLECTION.to_owned();
|
||||||
let mut right: Vec<Artist> = vec![left.last().unwrap().clone()];
|
let mut right: Vec<Artist> = vec![left.last().unwrap().clone()];
|
||||||
|
|
||||||
@ -1286,10 +1292,7 @@ mod tests {
|
|||||||
.times(1)
|
.times(1)
|
||||||
.return_once(|_| library_result);
|
.return_once(|_| library_result);
|
||||||
|
|
||||||
let mut music_hoard = MusicHoardBuilder::default()
|
let mut music_hoard = MusicHoard::new(library, database);
|
||||||
.set_library(library)
|
|
||||||
.set_database(database)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
music_hoard.rescan_library().unwrap();
|
music_hoard.rescan_library().unwrap();
|
||||||
assert_eq!(music_hoard.get_collection(), &*LIBRARY_COLLECTION);
|
assert_eq!(music_hoard.get_collection(), &*LIBRARY_COLLECTION);
|
||||||
@ -1313,10 +1316,7 @@ mod tests {
|
|||||||
.times(1)
|
.times(1)
|
||||||
.return_once(|_| library_result);
|
.return_once(|_| library_result);
|
||||||
|
|
||||||
let mut music_hoard = MusicHoardBuilder::default()
|
let mut music_hoard = MusicHoard::new(library, database);
|
||||||
.set_library(library)
|
|
||||||
.set_database(database)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
music_hoard.rescan_library().unwrap();
|
music_hoard.rescan_library().unwrap();
|
||||||
assert_eq!(music_hoard.get_collection(), &*LIBRARY_COLLECTION);
|
assert_eq!(music_hoard.get_collection(), &*LIBRARY_COLLECTION);
|
||||||
@ -1350,10 +1350,7 @@ mod tests {
|
|||||||
.times(1)
|
.times(1)
|
||||||
.return_once(|_| library_result);
|
.return_once(|_| library_result);
|
||||||
|
|
||||||
let mut music_hoard = MusicHoardBuilder::default()
|
let mut music_hoard = MusicHoard::new(library, database);
|
||||||
.set_library(library)
|
|
||||||
.set_database(database)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
music_hoard.rescan_library().unwrap();
|
music_hoard.rescan_library().unwrap();
|
||||||
assert_eq!(music_hoard.get_collection(), &expected);
|
assert_eq!(music_hoard.get_collection(), &expected);
|
||||||
@ -1386,10 +1383,7 @@ mod tests {
|
|||||||
.times(1)
|
.times(1)
|
||||||
.return_once(|_| library_result);
|
.return_once(|_| library_result);
|
||||||
|
|
||||||
let mut music_hoard = MusicHoardBuilder::default()
|
let mut music_hoard = MusicHoard::new(library, database);
|
||||||
.set_library(library)
|
|
||||||
.set_database(database)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
assert!(music_hoard.rescan_library().is_err());
|
assert!(music_hoard.rescan_library().is_err());
|
||||||
}
|
}
|
||||||
@ -1404,10 +1398,7 @@ mod tests {
|
|||||||
.times(1)
|
.times(1)
|
||||||
.return_once(|| Ok(FULL_COLLECTION.to_owned()));
|
.return_once(|| Ok(FULL_COLLECTION.to_owned()));
|
||||||
|
|
||||||
let mut music_hoard = MusicHoardBuilder::default()
|
let mut music_hoard = MusicHoard::new(library, database);
|
||||||
.set_library(library)
|
|
||||||
.set_database(database)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
music_hoard.load_from_database().unwrap();
|
music_hoard.load_from_database().unwrap();
|
||||||
assert_eq!(music_hoard.get_collection(), &*FULL_COLLECTION);
|
assert_eq!(music_hoard.get_collection(), &*FULL_COLLECTION);
|
||||||
@ -1436,10 +1427,7 @@ mod tests {
|
|||||||
.times(1)
|
.times(1)
|
||||||
.return_once(|_: &Collection| database_result);
|
.return_once(|_: &Collection| database_result);
|
||||||
|
|
||||||
let mut music_hoard = MusicHoardBuilder::default()
|
let mut music_hoard = MusicHoard::new(library, database);
|
||||||
.set_library(library)
|
|
||||||
.set_database(database)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
music_hoard.rescan_library().unwrap();
|
music_hoard.rescan_library().unwrap();
|
||||||
assert_eq!(music_hoard.get_collection(), &*LIBRARY_COLLECTION);
|
assert_eq!(music_hoard.get_collection(), &*LIBRARY_COLLECTION);
|
||||||
@ -1458,10 +1446,7 @@ mod tests {
|
|||||||
.times(1)
|
.times(1)
|
||||||
.return_once(|_| library_result);
|
.return_once(|_| library_result);
|
||||||
|
|
||||||
let mut music_hoard = MusicHoardBuilder::default()
|
let mut music_hoard = MusicHoard::new(library, database);
|
||||||
.set_library(library)
|
|
||||||
.set_database(database)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let actual_err = music_hoard.rescan_library().unwrap_err();
|
let actual_err = music_hoard.rescan_library().unwrap_err();
|
||||||
let expected_err =
|
let expected_err =
|
||||||
@ -1483,10 +1468,7 @@ mod tests {
|
|||||||
.times(1)
|
.times(1)
|
||||||
.return_once(|| database_result);
|
.return_once(|| database_result);
|
||||||
|
|
||||||
let mut music_hoard = MusicHoardBuilder::default()
|
let mut music_hoard = MusicHoard::new(library, database);
|
||||||
.set_library(library)
|
|
||||||
.set_database(database)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let actual_err = music_hoard.load_from_database().unwrap_err();
|
let actual_err = music_hoard.load_from_database().unwrap_err();
|
||||||
let expected_err = Error::DatabaseError(
|
let expected_err = Error::DatabaseError(
|
||||||
@ -1509,10 +1491,7 @@ mod tests {
|
|||||||
.times(1)
|
.times(1)
|
||||||
.return_once(|_: &Collection| database_result);
|
.return_once(|_: &Collection| database_result);
|
||||||
|
|
||||||
let mut music_hoard = MusicHoardBuilder::default()
|
let mut music_hoard = MusicHoard::new(library, database);
|
||||||
.set_library(library)
|
|
||||||
.set_database(database)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let actual_err = music_hoard.save_to_database().unwrap_err();
|
let actual_err = music_hoard.save_to_database().unwrap_err();
|
||||||
let expected_err = Error::DatabaseError(
|
let expected_err = Error::DatabaseError(
|
||||||
|
@ -48,3 +48,44 @@ impl<LIB, DB> MusicHoardBuilder<LIB, DB> {
|
|||||||
MusicHoard::new(self.library, self.database)
|
MusicHoard::new(self.library, self.database)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use crate::database::NullDatabase;
|
||||||
|
use crate::library::NullLibrary;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_library_no_database() {
|
||||||
|
MusicHoardBuilder::default();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn with_library_no_database() {
|
||||||
|
let mut mh = MusicHoardBuilder::default()
|
||||||
|
.set_library(NullLibrary)
|
||||||
|
.build();
|
||||||
|
assert!(mh.rescan_library().is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_library_with_database() {
|
||||||
|
let mut mh = MusicHoardBuilder::default()
|
||||||
|
.set_database(NullDatabase)
|
||||||
|
.build();
|
||||||
|
assert!(mh.load_from_database().is_ok());
|
||||||
|
assert!(mh.save_to_database().is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn with_library_with_database() {
|
||||||
|
let mut mh = MusicHoardBuilder::default()
|
||||||
|
.set_library(NullLibrary)
|
||||||
|
.set_database(NullDatabase)
|
||||||
|
.build();
|
||||||
|
assert!(mh.rescan_library().is_ok());
|
||||||
|
assert!(mh.load_from_database().is_ok());
|
||||||
|
assert!(mh.save_to_database().is_ok());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user