From 6238d533b1f8cb9460e958332d50077d81215078 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sun, 12 Jan 2025 12:01:16 +0100 Subject: [PATCH] Avoid modifying test files --- tests/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/lib.rs b/tests/lib.rs index ab9c7bb..551af37 100644 --- a/tests/lib.rs +++ b/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>(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);