Avoid modifying test files
This commit is contained in:
parent
538368ec38
commit
6238d533b1
15
tests/lib.rs
15
tests/lib.rs
@ -6,6 +6,8 @@ mod library;
|
||||
|
||||
mod testlib;
|
||||
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use musichoard::{
|
||||
external::{
|
||||
database::sql::{backend::SqlDatabaseSqliteBackend, SqlDatabase},
|
||||
@ -13,9 +15,16 @@ use musichoard::{
|
||||
},
|
||||
IMusicHoardBase, IMusicHoardDatabase, IMusicHoardLibrary, MusicHoard,
|
||||
};
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
use crate::testlib::COLLECTION;
|
||||
|
||||
fn copy_file_into_temp<P: Into<PathBuf>>(path: P) -> NamedTempFile {
|
||||
let temp = NamedTempFile::new().unwrap();
|
||||
fs::copy(path.into(), temp.path()).unwrap();
|
||||
temp
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_library_then_database() {
|
||||
// Acquired the lock on the beets config file. We need to own the underlying object so later we
|
||||
@ -28,7 +37,8 @@ fn merge_library_then_database() {
|
||||
.config(Some(&*library::beets::BEETS_TEST_CONFIG_PATH));
|
||||
let library = BeetsLibrary::new(executor);
|
||||
|
||||
let backend = SqlDatabaseSqliteBackend::new(&*database::sql::DATABASE_TEST_FILE).unwrap();
|
||||
let file = copy_file_into_temp(&*database::sql::DATABASE_TEST_FILE);
|
||||
let backend = SqlDatabaseSqliteBackend::new(file.path()).unwrap();
|
||||
let database = SqlDatabase::new(backend).unwrap();
|
||||
|
||||
let mut music_hoard = MusicHoard::new(database, library);
|
||||
@ -51,7 +61,8 @@ fn merge_database_then_library() {
|
||||
.config(Some(&*library::beets::BEETS_TEST_CONFIG_PATH));
|
||||
let library = BeetsLibrary::new(executor);
|
||||
|
||||
let backend = SqlDatabaseSqliteBackend::new(&*database::sql::DATABASE_TEST_FILE).unwrap();
|
||||
let file = copy_file_into_temp(&*database::sql::DATABASE_TEST_FILE);
|
||||
let backend = SqlDatabaseSqliteBackend::new(file.path()).unwrap();
|
||||
let database = SqlDatabase::new(backend).unwrap();
|
||||
|
||||
let mut music_hoard = MusicHoard::new(database, library);
|
||||
|
Loading…
x
Reference in New Issue
Block a user