2023-04-10 20:48:44 +02:00
|
|
|
use std::{
|
|
|
|
fs,
|
2023-04-13 20:29:48 +02:00
|
|
|
path::PathBuf,
|
2023-04-10 20:48:44 +02:00
|
|
|
sync::{Arc, Mutex},
|
|
|
|
};
|
|
|
|
|
|
|
|
use once_cell::sync::Lazy;
|
2023-04-10 00:13:18 +02:00
|
|
|
|
|
|
|
use musichoard::{
|
|
|
|
library::{
|
2023-04-10 21:36:43 +02:00
|
|
|
beets::{BeetsLibrary, BeetsLibraryCommandExecutor},
|
2023-04-10 00:13:18 +02:00
|
|
|
Library, Query, QueryOption,
|
|
|
|
},
|
|
|
|
Artist,
|
|
|
|
};
|
|
|
|
|
|
|
|
use crate::COLLECTION;
|
|
|
|
|
2023-04-13 15:29:14 +02:00
|
|
|
static BEETS_EMPTY_CONFIG: Lazy<Arc<Mutex<BeetsLibrary<BeetsLibraryCommandExecutor>>>> =
|
|
|
|
Lazy::new(|| {
|
|
|
|
Arc::new(Mutex::new(BeetsLibrary::new(
|
|
|
|
BeetsLibraryCommandExecutor::default(),
|
|
|
|
)))
|
|
|
|
});
|
|
|
|
|
|
|
|
static BEETS_TEST_CONFIG: Lazy<Arc<Mutex<BeetsLibrary<BeetsLibraryCommandExecutor>>>> =
|
|
|
|
Lazy::new(|| {
|
|
|
|
Arc::new(Mutex::new(BeetsLibrary::new(
|
|
|
|
BeetsLibraryCommandExecutor::default().config(Some(
|
|
|
|
&fs::canonicalize("./tests/files/library/config.yml").unwrap(),
|
|
|
|
)),
|
|
|
|
)))
|
|
|
|
});
|
2023-04-10 20:48:44 +02:00
|
|
|
|
2023-04-10 00:13:18 +02:00
|
|
|
#[test]
|
|
|
|
fn test_no_config_list() {
|
2023-04-10 20:48:44 +02:00
|
|
|
let beets_arc = BEETS_EMPTY_CONFIG.clone();
|
|
|
|
let beets = &mut beets_arc.lock().unwrap();
|
2023-04-10 00:13:18 +02:00
|
|
|
|
|
|
|
let output = beets.list(&Query::default()).unwrap();
|
|
|
|
|
|
|
|
let expected: Vec<Artist> = vec![];
|
|
|
|
assert_eq!(output, expected);
|
|
|
|
}
|
|
|
|
|
2023-04-13 20:29:48 +02:00
|
|
|
#[test]
|
|
|
|
fn test_invalid_config() {
|
|
|
|
let mut beets = BeetsLibrary::new(BeetsLibraryCommandExecutor::default().config(Some(
|
|
|
|
&PathBuf::from("./tests/files/library/config-does-not-exist.yml"),
|
|
|
|
)));
|
|
|
|
|
|
|
|
let result = beets.list(&Query::default());
|
|
|
|
assert!(result.is_err());
|
|
|
|
assert!(!result.unwrap_err().to_string().is_empty());
|
|
|
|
}
|
|
|
|
|
2023-04-10 00:13:18 +02:00
|
|
|
#[test]
|
|
|
|
fn test_full_list() {
|
2023-04-10 20:48:44 +02:00
|
|
|
let beets_arc = BEETS_TEST_CONFIG.clone();
|
|
|
|
let beets = &mut beets_arc.lock().unwrap();
|
2023-04-10 00:13:18 +02:00
|
|
|
|
|
|
|
let output = beets.list(&Query::default()).unwrap();
|
|
|
|
|
|
|
|
let expected: Vec<Artist> = COLLECTION.to_owned();
|
|
|
|
assert_eq!(output, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_album_artist_query() {
|
2023-04-10 20:48:44 +02:00
|
|
|
let beets_arc = BEETS_TEST_CONFIG.clone();
|
|
|
|
let beets = &mut beets_arc.lock().unwrap();
|
2023-04-10 00:13:18 +02:00
|
|
|
|
|
|
|
let output = beets
|
|
|
|
.list(&Query::default().album_artist(QueryOption::Include(String::from("Аркона"))))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let expected: Vec<Artist> = COLLECTION[0..1].to_owned();
|
|
|
|
assert_eq!(output, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_album_title_query() {
|
2023-04-10 20:48:44 +02:00
|
|
|
let beets_arc = BEETS_TEST_CONFIG.clone();
|
|
|
|
let beets = &mut beets_arc.lock().unwrap();
|
2023-04-10 00:13:18 +02:00
|
|
|
|
|
|
|
let output = beets
|
|
|
|
.list(&Query::default().album_title(QueryOption::Include(String::from("Slovo"))))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let expected: Vec<Artist> = COLLECTION[0..1].to_owned();
|
|
|
|
assert_eq!(output, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_exclude_query() {
|
2023-04-10 20:48:44 +02:00
|
|
|
let beets_arc = BEETS_TEST_CONFIG.clone();
|
|
|
|
let beets = &mut beets_arc.lock().unwrap();
|
2023-04-10 00:13:18 +02:00
|
|
|
|
|
|
|
let output = beets
|
|
|
|
.list(&Query::default().album_artist(QueryOption::Exclude(String::from("Аркона"))))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let expected: Vec<Artist> = COLLECTION[1..].to_owned();
|
|
|
|
assert_eq!(output, expected);
|
|
|
|
}
|