-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a unit test for custom name reversing
- Loading branch information
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use super::super::database::*; | ||
use super::*; | ||
use std::path::PathBuf; | ||
use tempfile::{NamedTempFile, TempDir}; | ||
|
||
#[tokio::test] | ||
async fn test() { | ||
// given | ||
let _guard = MUTEX.lock().await; | ||
|
||
let test_directory = Path::new("tests"); | ||
let progress_bar = ProgressBar::hidden(); | ||
|
||
let db_file = NamedTempFile::new().unwrap(); | ||
let pool = establish_connection(db_file.path().to_str().unwrap()).await; | ||
let mut connection = pool.acquire().await.unwrap(); | ||
|
||
let rom_directory = TempDir::new_in(&test_directory).unwrap(); | ||
set_rom_directory(PathBuf::from(rom_directory.path())); | ||
let tmp_directory = TempDir::new_in(&test_directory).unwrap(); | ||
set_tmp_directory(PathBuf::from(tmp_directory.path())); | ||
|
||
let dat_path = test_directory.join("Test System (20200721).dat"); | ||
let (datfile_xml, detector_xml) = parse_dat(&progress_bar, &dat_path, false).await.unwrap(); | ||
|
||
import_dat( | ||
&mut connection, | ||
&progress_bar, | ||
&datfile_xml, | ||
&detector_xml, | ||
Some(&String::from("Custom Test System")), | ||
false, | ||
false, | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
// when | ||
import_dat( | ||
&mut connection, | ||
&progress_bar, | ||
&datfile_xml, | ||
&detector_xml, | ||
None, | ||
false, | ||
true, | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
// then | ||
let systems = find_systems(&mut connection).await; | ||
assert_eq!(systems.len(), 1); | ||
|
||
let system = systems.first().unwrap(); | ||
assert_eq!(system.name, "Test System"); | ||
assert!(system.custom_name.is_none()); | ||
|
||
assert_eq!(find_games(&mut connection).await.len(), 6); | ||
assert_eq!(find_roms(&mut connection).await.len(), 8); | ||
} |