use std::{ fs, sync::{Arc, Mutex}, }; use once_cell::sync::Lazy; use musichoard::{ library::{ beets::{BeetsLibrary, BeetsLibrarySystemExecutor}, Library, Query, QueryOption, }, Artist, }; use crate::COLLECTION; static BEETS_EMPTY_CONFIG: Lazy>> = Lazy::new(|| { Arc::new(Mutex::new(BeetsLibrary::new(Box::new(unsafe { BeetsLibrarySystemExecutor::default() })))) }); static BEETS_TEST_CONFIG: Lazy>> = Lazy::new(|| { Arc::new(Mutex::new(BeetsLibrary::new(Box::new(unsafe { BeetsLibrarySystemExecutor::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::default()).unwrap(); let expected: Vec = vec![]; assert_eq!(output, expected); } #[test] fn test_full_list() { let beets_arc = BEETS_TEST_CONFIG.clone(); let beets = &mut beets_arc.lock().unwrap(); let output = beets.list(&Query::default()).unwrap(); let expected: Vec = 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::default().album_artist(QueryOption::Include(String::from("Аркона")))) .unwrap(); let expected: Vec = 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::default().album_title(QueryOption::Include(String::from("Slovo")))) .unwrap(); let expected: Vec = 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::default().album_artist(QueryOption::Exclude(String::from("Аркона")))) .unwrap(); let expected: Vec = COLLECTION[1..].to_owned(); assert_eq!(output, expected); }