musichoard/tests/library/beets.rs

106 lines
2.7 KiB
Rust
Raw Normal View History

use std::{
fs,
path::PathBuf,
sync::{Arc, Mutex},
};
use once_cell::sync::Lazy;
use musichoard::{
library::{
2023-04-14 11:14:08 +02:00
beets::{BeetsLibrary, BeetsLibraryProcessExecutor},
Field, Library, Query,
},
Artist,
};
use crate::COLLECTION;
2023-04-14 11:14:08 +02:00
static BEETS_EMPTY_CONFIG: Lazy<Arc<Mutex<BeetsLibrary<BeetsLibraryProcessExecutor>>>> =
Lazy::new(|| {
Arc::new(Mutex::new(BeetsLibrary::new(
2023-04-14 11:14:08 +02:00
BeetsLibraryProcessExecutor::default(),
)))
});
2023-04-14 11:14:08 +02:00
static BEETS_TEST_CONFIG: Lazy<Arc<Mutex<BeetsLibrary<BeetsLibraryProcessExecutor>>>> =
Lazy::new(|| {
Arc::new(Mutex::new(BeetsLibrary::new(
2023-04-14 11:14:08 +02:00
BeetsLibraryProcessExecutor::default().config(Some(
&fs::canonicalize("./tests/files/library/config.yml").unwrap(),
)),
)))
});
#[test]
fn test_no_config_list() {
let beets_arc = BEETS_EMPTY_CONFIG.clone();
let beets = &mut beets_arc.lock().unwrap();
let output = beets.list(&Query::new()).unwrap();
let expected: Vec<Artist> = vec![];
assert_eq!(output, expected);
}
#[test]
fn test_invalid_config() {
2023-04-14 11:14:08 +02:00
let mut beets = BeetsLibrary::new(BeetsLibraryProcessExecutor::default().config(Some(
&PathBuf::from("./tests/files/library/config-does-not-exist.yml"),
)));
let result = beets.list(&Query::new());
assert!(result.is_err());
assert!(!result.unwrap_err().to_string().is_empty());
}
#[test]
fn test_full_list() {
let beets_arc = BEETS_TEST_CONFIG.clone();
let beets = &mut beets_arc.lock().unwrap();
let output = beets.list(&Query::new()).unwrap();
let expected: Vec<Artist> = COLLECTION.to_owned();
assert_eq!(output, expected);
}
#[test]
fn test_album_artist_query() {
let beets_arc = BEETS_TEST_CONFIG.clone();
let beets = &mut beets_arc.lock().unwrap();
let output = beets
.list(Query::new().include(Field::AlbumArtist(String::from("Аркона"))))
.unwrap();
let expected: Vec<Artist> = COLLECTION[0..1].to_owned();
assert_eq!(output, expected);
}
#[test]
fn test_album_title_query() {
let beets_arc = BEETS_TEST_CONFIG.clone();
let beets = &mut beets_arc.lock().unwrap();
let output = beets
.list(&Query::new().include(Field::AlbumTitle(String::from("Slovo"))))
.unwrap();
let expected: Vec<Artist> = COLLECTION[0..1].to_owned();
assert_eq!(output, expected);
}
#[test]
fn test_exclude_query() {
let beets_arc = BEETS_TEST_CONFIG.clone();
let beets = &mut beets_arc.lock().unwrap();
let output = beets
.list(&Query::new().exclude(Field::AlbumArtist(String::from("Аркона"))))
.unwrap();
let expected: Vec<Artist> = COLLECTION[1..].to_owned();
assert_eq!(output, expected);
}